-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Tensorflow lite dll build failed on Windows #33634
Comments
I confirm the issue is caused by the fact that no .def file is provided in the case of tflite build for Windows. I successfully build a tflite dll for Windows by calling link.exe by myself and providing a custom .def file I created. A block similar to the following one (found in tensorflow/BUILD) should be added to tensorflow/lite:libtensorflowlite.so target:
|
Good catch! Feel free to propose a PR, I'd be happy to approve. |
@ValYouW This is normal that you have this error. In order to make it fully work you must copy all the tensorflow BUILD parts that generate the .def file, and customize it for tensorflow lite dll. I'm not an expert in Bazel, so I could not make it myself, this is why I didn't push a proper PR. What I did is to generate manually the .def file based on the missing symbols I had in my own project, and used link.exe to build the dll from command line. By the way, @jdduke the dll I obtained is not SSE optimized, so it is very slow. I have started to check why NEON2SSE.h is not used in windows build (as in MacOS build) but not yet found. I move on other tasks right now, but I have planned to make it work some day. |
OK, thanks for checking, there may be some tweaks we need to make in our build config to get this working (sadly we don't have exhaustive internal tests for Windows internally). |
@twkx Thanks. Too complicated, I'll skip windows for now... :) |
I think this might be resolved with bazelbuild/bazel#9976. I'm curious if adding |
@jdduke I confirm adding this fixes the issue and creates a working dll (just rename the .so as .dll)! Thanks a lot. I'll check for neon asap. |
Btw, I'm landing a change shortly that should automatically generate the appropriate lib name based on the target platform (e.g., tensorflowlite.dll, libtensorflowlite.so, libtensorflowlite.dylib). I'll also go ahead and land the |
Am I understanding correctly that if I build bazel from master to get that latest fix, then add def tflite_cc_shared_object( I should then be able to compile tflite on windows using the bazel version built from source with: bazel build //tensorflow/lite:libtensorflowlite.so Is this correct? Or will I need to do other steps to get it working? |
For anyone who is interested I got it built on windows using the 2.1.0 release of bazel, adding in the features = ["windows_export_all_symbols"], to tensorflow/lite/build_def.bzl as before and compiling with bazel-2.1.0.exe build //tensorflow/lite:libtensorflowlite.so |
From a master checkout, could you try doing:
That should produce a proper .dll, though I want to make sure it's properly symbolized. Thanks! |
I pulled from master on tensorflow. Then tried: This built the .lib and .dll, however the files were tiny ~2KB and when I tried to use them I got error with unresolved symbols. I then added the following after line 168 in build_def.bzl and rebuilt in the same way: This produced the .lib that I could link against. However my code failed at runtime. (I'm not sure why yet). |
The same code worked fine when using an older commit on tensorflow:master ~15 Jan, and adding the extra line to build_def.bzl then compiling with bazel build //tensorflow/lite:libtensorflowlite.so (2.1.0 release of bazel). However I did have to keep the generated library named as .so. |
Is it possible to build TFLite for Windows and ARM(32/64)? I am asking because it would be useful to run it on the HoloLens 2 which is based on Universal Windows Platform (UWP) and has an ARM chip set. |
I built tensorflowlite.dll.if.lib and tensorflowlite.dll from master branch with modified build_def.bzl. I just arranged the way to generate tensorflowlite.dll which actually works at the moment. |
I'm fairly sure I copied the .dll across into the runtime folder correctly. However I could have made some other mistake. I'll give it another go later when I get a chance. |
I think I might be experiencing the same problem as @ChrisAGBlake
The same code works perfectly on Ubuntu 18.04 using |
In general, if you're using the C++ API, you need to be extremely careful that your client library (referencing TFLite code) is built with identical build/link options as the TFLite library itself. In general, prefer using the tensorflow/lite/c shared library to avoid ABI and stdlib incompatibilities. |
@Lotte1990 double check you use the exact same .h files in your project that the ones used to compile the library itself (extract those .h from the cloned tflite repository to be sure). Also, as @jdduke said, be carefull to use the same stdlib implementation in your project than the one used in the tensorflowlite library. |
Thanks for the quick reply. I'm using the same git checkout for (1) compiling tensorflowlite.dll (2) the header files (3) exporting the .tflite file. I'm no expert regarding the library stuff. I tried adding different lines in different combinations to CMakeLists.txt, such as |
@Lotte1990 |
I use CMake to generate a .sln file that I open in MSVC. Then I press |
You can select that configuration using UI in Visual Studio (I'm not sure CMAKE_BUILD_TYPE makes an effect to configuration for Visual Studio). Please find a drop box just under a menu bar in Visual Studio, and select Release. Also make sure you use x64 architecture (not x86). You can also find a drop box to select architecture next to the drop box to select configuration. It's also located under the menu bar in Visual Studio. |
Debug config was indeed the problem. When I compile everything with release config, it works great. As you suspected, Visual Studio completely ignores CMAKE_BUILD_TYPE. |
Is there any way to build tensorflowlite.dll for windows X86 support? |
I don't think 32-bit (x86) Windows build are supported directly. There is some additional information here. |
@Lotte1990 How exactly did you use CMAKE to create an .sln file? |
I used CMake to create an .sln file for my own project that uses TensorFlow Lite, not for TensorFlow Lite itself. For TensorFlow Lite, unfortunately, you still need to use Bazel. |
I see. Thank you. |
@jdduke I see that |
Thanks for flagging, I'll go ahead and land this for the C++ .dll target. I'm curious if you're able to use the C API/dll in lite/c:tensorflowlite_c? That should have finer grained symbol export, has a simpler header export story and also avoids many of the C++ ABI issues with compatibility. |
@jdduke Thanks, I see this fix hasn't made it to v2.2.0 :( |
Yeah, unfortunately the 2.2 branch was only accepting P0/P1 issues at that point. Should be in the next release. |
Hello, I got the latest version of TF and tensorflow/lite/build_def.bzl seems to be slightly different than listed above. I try to build and it says there are multiple values for argument features. ERROR: C:/temp/tensorflow/tensorflow/lite/build_def.bzl:157:24: Traceback (most recent call last): Anything obviously wrong? Thanks. def tflite_cc_shared_object(
|
Thanks ValYouW, I watched your video and I was doing something really dumb. I wasn't running python configure.py. |
System information
Describe the problem
I have a code base successfully running on Linux/MacOS/Android & iOS.
Now I need to run tflite model inference under Windows system.
For this, I need to compile a tensorflowlite dll for Windows (I've not found any precompiled version)
Unfortunately, the build fails at the link step... (see logs below).
Apparently, even if the build fails, a libtensorflowlite.so file is stil generated (and is indeed a dll), but it contains no exported symbols, so I cannot use it.
After checking at the tensorflow/lite/BUILD file it appears that no .def file is generated for the tflite Windows link step, as it is done for tensorflow.dll (seen in tensorflow/BUILD), which explains why no symbols are exported.
Provide the exact sequence of commands / steps that you executed before running into the problem
In Windows command prompt (Run as Administrator):
python configure.py
bazel build -s tensorflow/lite:libtensorflowlite.so
Any other info / logs
C:\Users\soule\Downloads\tensorflow> bazel build -s tensorflow/lite:libtensorflowlite.so
[...]
C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.23.28105/bin/HostX64/x64/link.exe /nologo /DLL /SUBSYSTEM:CONSOLE -s -ignore:4221 -ignore:4221 -ignore:4221 -ignore:4221 /MACHINE:X64 @bazel-out/x64_windows-opt/bin/tensorflow/lite/libtensorflowlite.so-2.params /OPT:ICF /OPT:REF
INFO: From Linking tensorflow/lite/libtensorflowlite.so:
LINK : warning LNK4044: unrecognized option '/s'; ignored
ERROR: C:/users/soule/downloads/tensorflow/tensorflow/lite/BUILD:442:1: output 'tensorflow/lite/libtensorflowlite.so.if.lib' was not created
ERROR: C:/users/soule/downloads/tensorflow/tensorflow/lite/BUILD:442:1: not all outputs were created or valid
Target //tensorflow/lite:libtensorflowlite.so failed to build
INFO: Elapsed time: 920.482s, Critical Path: 84.10s
INFO: 235 processes: 235 local.
FAILED: Build did NOT complete successfully
C:\Users\soule\Downloads\tensorflow> dumpbin /exports bazel-out\x64_windows-opt\bin\tensorflow\lite\libtensorflowlite.so
Microsoft (R) COFF/PE Dumper Version 14.23.28106.4
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file bazel-out\x64_windows-opt\bin\tensorflow\lite\libtensorflowlite.so
File Type: DLL
Summary
The text was updated successfully, but these errors were encountered: