-
Notifications
You must be signed in to change notification settings - Fork 352
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
❓ [Question] Building torch_tensorrt.lib on Windows #1014
Comments
I managed to create the .lib file from the .dll following these instructions: https://web.archive.org/web/20140219172454/https://adrianhenke.wordpress.com/2008/12/05/create-lib-file-from-dll/ (adding /MACHINE:X64 to the lib command), but the .dll didn't contain the torchscript namespace and its functions/classes. I found that the torchscript namespace was in cpp_objs\torch_tensorrt\compile_spec.obj, but when I tried turning the .objs in that folder into a .lib (with VS tools' "lib": https://stackoverflow.com/questions/31763558/how-to-build-static-and-dynamic-libraries-from-obj-files-for-visual-c) and linking it in my probject, it just created a bunch of new 'unresolved external symbol' linker errors. Any suggestions on how to build .lib and .dll files for all of torch_tensorrt, including compile_spec, ptq, etc.? @narendasan perhaps you would have some insight into this? Thanks! |
Are the symbols from the top level namespace available? Like torch_tensorrt::Input? Unfortunately I don't have a ton of experience with windows development. Perhaps bazel can directly generate the .lib for you. The final library targets in the repo are located at
Not sure if this would help here. |
@narendasan Even torch_tensorrt::Input throws an 'unresolved external symbol' linker error. I tried adding a .lib target to cpp/lib/BUILD just under the .dll target, but it doesn't do anything. There is a 4KB torch_tensorrt.def file in cpp/lib, but when I added it as shown below (I tried with both the .dll and .lib targets):
I got the following error: And it wouldn't let me put the full directory as it threw an error if the filename included a ':', '/', or ''. Thanks for your help so far. |
So the lib target will not get included in the package builder target I was reading a bit more on def files and it seems like it's not really necessary, but we might need to change the TORCHTRT_API macro (https://github.com/NVIDIA/Torch-TensorRT/blob/master/cpp/include/torch_tensorrt/macros.h) to add |
Re the missing file error, that is because bazel expects a def file in //cpp/lib |
@narendasan there is a def file in //cpp/lib |
Hmm and this is the source //cpp/lib and not like //bazel-torch-tensorrt/cpp/lib? Maybe try clearing the cache?
bazel clean --expunge
…________________________________
From: Jonah ***@***.***>
Sent: Sunday, May 1, 2022 3:30:48 PM
To: NVIDIA/Torch-TensorRT ***@***.***>
Cc: Naren Dasan ***@***.***>; Mention ***@***.***>
Subject: Re: [NVIDIA/Torch-TensorRT] ❓ [Question] Building torch_tensorrt.lib on Windows (Issue #1014)
@narendasan<https://github.com/narendasan> there is a def file in //cpp/lib
—
Reply to this email directly, view it on GitHub<#1014 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AANVFFM2GGMHJEKSDMCKS5DVH4AZRANCNFSM5UWGEY3A>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I tried running
I realized it was creating a .lib.dll file, so I changed
|
Yes this is //cpp/lib. Just tried clearing the cache, ran mostly til the end then gave the same error but of course ending this time in:
|
I also modified line 11 of macros.h to |
Should it be all one line or should it be it’s own MVSC case for TORCHTRT_API?
…________________________________
From: Jonah ***@***.***>
Sent: Sunday, May 1, 2022 3:53:52 PM
To: NVIDIA/Torch-TensorRT ***@***.***>
Cc: Naren Dasan ***@***.***>; Mention ***@***.***>
Subject: Re: [NVIDIA/Torch-TensorRT] ❓ [Question] Building torch_tensorrt.lib on Windows (Issue #1014)
I also modified line 11 of macros.h to #define TORCHTRT_API __attribute__((__visibility__("default"))) __declspec(dllexport) and was able to successfully build the .dll with that as before, the .dll is the same size though so I'm not sure if it made any difference.
—
Reply to this email directly, view it on GitHub<#1014 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AANVFFIZOODOEXKWTRFV7ZLVH4DQBANCNFSM5UWGEY3A>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I'm not sure what you mean, if I define TORCHTRT_API again then won't it just replace the existing attribute definition? |
I tried it on a new line as so:
And was again able to build the .dll successfully (it was the same size as before), but still not the .lib file. |
I think something more along the lines of this https://ms-iot.github.io/ROSOnWindows/Porting/SymbolVisibility.html Since I believe the |
Okay, that was a helpful lead. I added I am going to keep going down this pattern but I am starting to think this will just be a game of catch-up where I have to go add Perhaps I'm misunderstanding it, but it seems the reason Update - after adding it to those two functions, we get 21 unresolved externals. CMake's WINDOWS_EXPORT_ALL_SYMBOLS from the article you linked seems like it would be useful if we were using CMake. |
I found a similar command in bazel, and tried executing
This seems like it might be related to this discussion: bazelbuild/bazel#11622 |
I managed to fix the TorchTRTLogger errors too by again adding DllExport. It seems that However, I then got 21 unresolved externals, which was all the functions in core/lowering/passes except UnpackBatchNorm. Added DllExport to those. After that, I got this error related to linking nvinfer, which I noticed came up in #226 as well:
Resolved that issue by adding Then I went through a series of linker errors resolved by adding DllExport on all overloads for each declaration and definition:
Then:
And again:
However, when I added DllExport to the LogLevel overload so it was on both overloads, I got this ambiguous call error:
I tried removing DllExport from the Severity overload and having it just on the LogLevel one, but unfortunately I still get the ambiguous call error whether it's on the LogLevel one or both (and still get the 'unresolved external symbol error' when I apply DllExport to only the Severity overload). I honestly don't remember what happened after this, but it went away in lieu of another unresolved external error, this time for core::util::toDimsPad, which I applied the same DllExport solution to. This brought back the TorchTRTLogger unresolved external error as well as one for core::plugins::impl::TorchTRTPluginRegistry::TorchTRTPluginRegistry, which I again resolved with DllExport (on line 18 of core/plugins/register_plugins.cpp). I then got another unresolved linker error for core::conversion::converters::tensor_to_const (in core/conversion/converters/converter_util.cpp/h), and resolved it in the same way. Then "unresolved external symbol initLibNvInferPlugins referenced in function "public: __cdecl torch_tensorrt::core::plugins::impl::TorchTRTPluginRegistry::TorchTRTPluginRegistry(void)" and again the same error as before for the LogLevel overload of TorchTRTLogger. The PluginRegistry error seems to be a problem with linking nvinferplugins. I tried to resolve this by adding This didn't seem to fix the problem, as I was left again with unresolved external symbol errors for initLibNvInferPlugins referenced in core::plugins::impl::TorchTRTPluginRegistry::TorchTRTPluginRegistry and for core::util::logging::TorchTRTLogger::TorchTRTLogger (LogLevel overload). I decided to deal with the overloads of the TorchTRTLogger constructor creating the ambiguous call error. This is occurring because a compiler generated function calls the constructor with default parameters, and since both constructors can be defaulted, it's unsure which one to use. I managed to find a solution that I actually think is ideal since LogLevel is basically just a wrapper for Severity, involving one constructor and overflows for other functions in the class: https://gist.github.com/jonahclarsen/c3cc6b08271d28042963c2d2bca65931 (it still needs cleaning up). Now I am left again with the Any help on this would be greatly appreciated. |
Which target is missing |
Also do you have a branch you can share even if its dirty that we can look at? |
I am not sure how to create a branch. However, I am abandoning building with Bazel (at least for now) because I was able to finally get the binaries created with CMake thanks to @gcuendet at #1007 (although I still haven't been able to use them in my Libtorch project without getting errors). However, if you or anyone else wants to pursue building with Bazel further, here are the files/folders I modified on top of TRT-1.0.0: Torch-TensorRT-1.0.0-attempt2.zip |
❓ Question
I am wondering how to build the torch_tensorrt.lib on Windows.
What you have already tried
I have followed #960 and #856 (with the same WORKSPACE as the latter) and managed to successfully build torch_tensorrt.dll. However, I need the .lib file in order to compile my Libtorch program. I tried linking to some of the .lib files that were created already (like bazel-out\x64_windows-opt\bin\cpp\torch_tensorrt.lo.lib), but that didn't work. I expect it's a fairly simple bazel command, but I have no idea where to put it.
Environment
conda
,pip
,libtorch
, source): libtorch from pytorch.orgAdditional context
My libtorch program runs fine even if I include the torch-tensorrt headers, but throws the following errors as soon as I try to use torch_tensorrt::torchscript::CompileSpec and call torch_tensorrt::torchscript::compile:
Error LNK1120 2 unresolved externals Omkar 1.10.0+cu113 B:\Programming_Current Projects\HelloLibTorch\x64\Release\HelloTorch.exe 1
Error LNK2019 unresolved external symbol "public: __cdecl torch_tensorrt::torchscript::CompileSpec::CompileSpec(class std::vector<class std::vector<__int64,class std::allocator<__int64> >,class std::allocator<class std::vector<__int64,class std::allocator<__int64> > > >)" (??0CompileSpec@torchscript@torch_tensorrt@@qeaa@V?$vector@V?$vector@_JV?$allocator@_J@std@@@std@@v?$allocator@V?$vector@_JV?$allocator@_J@std@@@std@@@2@@std@@@z) referenced in function main Omkar 1.10.0+cu113 B:\Programming_Current Projects\HelloLibTorch\main.obj 1
Error LNK2019 unresolved external symbol "struct torch::jit::Module __cdecl torch_tensorrt::torchscript::compile(struct torch::jit::Module const &,struct torch_tensorrt::torchscript::CompileSpec)" (?compile@torchscript@torch_tensorrt@@ya?AUModule@jit@torch@@AEBU345@UCompileSpec@12@@z) referenced in function main Omkar 1.10.0+cu113 B:\Programming_Current Projects\HelloLibTorch\main.obj 1
The text was updated successfully, but these errors were encountered: