-
Notifications
You must be signed in to change notification settings - Fork 74.7k
Windows import library is missing sufficient symbols to use C++ API #41904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm new to Bazel but from what I can tell, the root cause is that, unfiltered, the Windows dll would contain more than 64K symbols, which is the maximum number of symbols that can be exported by a Windows Dll (because each symbol is indexed by a 16bit integer). To cirvcumvent this, Bazel builds a 'dummy' dll called From https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/BUILD : # add win_def_file for tensorflow_cc
win_def_file = select({
# We need this DEF file to properly export symbols on Windows
"//tensorflow:windows": ":tensorflow_filtered_def_file",
"//conditions:default": None,
}), However, this filtered def file contains only the symbols required to build custom ops. It does not contain the symbols required to actually use the C++ API as defined in the reference. From https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/tensorflow.bzl : # A list of targets that contains the implemenation of
# tf_custom_op_library_additional_deps. It's used to generate a DEF file for
# exporting symbols from _pywrap_tensorflow.dll on Windows.
def tf_custom_op_library_additional_deps_impl():
return [
"@com_google_protobuf//:protobuf",
"@nsync//:nsync_cpp",
# for //third_party/eigen3
clean_dep("//third_party/eigen3"),
# for //tensorflow/core:framework_headers_lib
clean_dep("//tensorflow/core:framework"),
clean_dep("//tensorflow/core:reader_base"),
] Note that the |
A related issue is #30246 I have an attempt to fix here: meteorcloudy@4b8e7be, could you please test if that helps? |
The basic idea of meteorcloudy/tensorflow@4b8e7be is to let Bazel parse all symbols from object files of a cc_library (unlike cc_binary, it will not include its transitive dependencies) and generate a DEF file that could be filtered (overcome the 64K symbol limit) and used for export symbols in tensorflow.dll. |
I'm afraid not. It fails with the following unresolved externals:
In addition the |
I see, meteorcloudy@4b8e7be basically offers an example to get the DEF file from cc_library instead of cc_binary. The DEF file will not contains symbols from the transitive cc_libraries, so it makes it easier to not exceed the symbol limits (64K). I think if you add the corresponding cc_libraries for the missing symbols in
It will probably work. |
I had the same problem as @planetmarshall. Applying the patch of meteorcloudy@4b8e7be, i have a linking problem for ClientSession .
Then i rebuild the .lib. Now I have no more linking problems, but the Add operation returns an error during runtime: |
I've just resolved the bad_alloc problem. I switch from Debug to Release in Microsoft Visual Studio. Thanks for your help! |
Hi @andrea-garritano, I have same problem and do like meteorcloudy/tensorflow@4b8e7be, but it's raise some of error: |
I'm sorry, but I never met this error. |
I did like @andrea-garritano suggested and tensorflow_cc builds successfully but I had 2 linking errors when I build the test code:
Any suggestions? |
I solved putting |
I have now another linking error when I try to include the freeze_saved_model module in the BUILD file as below:
Adding the last src causes a lot of linker errors when compiling tensorflow_cc, some of them reported below. Does anyone have some suggestions?
|
Hi @Shadowman82. Did you ever get anywhere with this? If I build dll just with the ops "//tensorflow/cc:cc_ops", it works and I get a dll and lib. When I link with my application, however it complains about ClientSession missing symbols. I note that the file client_session.cc is NOT even built unless it is added to the list above. I tried adding some garbage text to the file and the dll still compiled. If I add "//tensorflow/cc:client_session", to the list above and build, it tries to build client_session.cc |
Continuing from above. If I add all of: filegroup( I can't even build the dll. Loads of missing symbols similar to those reported by @Shadowman82 |
@philipeccles try and check this out I ended up getting it to work https://dkjoi.medium.com/tf2-4-dll-with-gpu-support-for-3090-in-windows-305126bc0d17?source=your_stories_page------------------------------------- I also have one simple with linking it to a standard model and doing inference. |
I finally got it to build and link with my application. One of the problems is I was using tensorflow.dll instead of tensorflow_cc.dll. The latter automatically builds client_session, the former doesn't. The only way I could get client_session to build was adding it in the filegroup in BUILD file as above. But building tensorflow.dll failed. If I build tensorflow_cc.dll I don't have to add client_session to build file and it all works. I will show my entire patch file at end of this message. What exactly is the major difference between tensorflow.dll instead of tensorflow_cc.dll? I see no documentation. Just to make the point. Tensorflow is open source so much gratitude to everyone who has contributed. However building it is on a different level entirely in terms of difficulty, compared to other open source projects I have built. I have spent a week at least getting to this point. Don't assume it's going to be easy! So here is my patch to tensorflow-2.3.0 |
@Shadowman82 , do you know the difference between tensorflow.dll and tensorflow_cc.dll? In the BUILD file they seem to be built in a very similar way. |
@philipeccles , I managed to solve it in the same way like you. I also had the same issue because I was using tensorflow.dll instead of tensorflow_cc.dll. Looking at the BUILD file the tensorflow_cc.dll I didn't find a reason for that |
I recently succeeded in building 2.6 (both tensorflow.dll and tensorflow_cc.dll) with GPU on Windows but linking it is a different challenge altogether to make a simple Matmul operation work and honestly, I am struggling. I arrived at this discussion after searching a lot for answers. Just as @philipeccles has stated above, I would like to express my gratitude to the tf team for making it accessible. However unless the accessibility of C++ API is improved particularly on Windows, it is a huge problem. Mere making something work should not feel like an achievement but currently this is how it feels with tensorflow C++ API. I am requesting all the good people in tf team to make it easy and intuitive to add symbols such as a file that list all the symbols perhaps that could be read by tf executable during compile time to determine what should be included and excluded (60k symbols limit will force us to make that choice). TF_EXPORT is tedious. C++ API is not usable in its current form on Windows for building graps. |
Hi @planetmarshall ! |
This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you. |
Closing as stale. Please reopen if you'd like to work on this further. |
@Shadowman82 Hi, Did you manage to use FreezeSavedModel ?I have, like you, the problem with a lot of link error during bazel buidl after adding to the BUILD file of tensorflow through filegroup. I use bazel build --config=opt --config=cuda tensorflow:tensorflow_cc.dll then All of them works nicely and I can use them in my project until i add "//tensorflow/cc/tools:freeze_saved_model" to the filegroup. Thank you a lot. |
System information
Expected Result
The generated Windows Binaries should export sufficient symbols to compile and link a basic program using the C++ API
Actual Result
Compiling and linking a basic Tensorflow C++ program with the Windows Binaries results in undefined symbols.
Provide the exact sequence of commands / steps that you executed before running into the problem
Example from Tensorflow 2.3.0 API Reference
main.cpp
CMakeLists.txt
The compilation succeeds but linking fails with the following missing externals:
The text was updated successfully, but these errors were encountered: