-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Fix windows build issues #3087
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
Fix windows build issues #3087
Conversation
* Fix debug build by ignoring the python debug library. An option IGNORE_PYTHON_DEBUG_LIBRARY is introduced for that. * Fix symbol registration issues with redefinition of cuda_version and linker optimizations in Release build.
Looks like the Python build is not happening like it is supposed to on Windows. I found the culprit, the models/*.cpp files are not included in the .pyd extension. I did not make any change to this file. I suspect that the change to the vision header broke this. How can we reconcile this? Shouldn't the models.cpp be included in the .pyd extension? This can be fixed with the following change, but I am not sure what was intended in the first place. So I will wait for comments before making further changes. diff --git a/setup.py b/setup.py
index 82c93be..05eb199 100644
--- a/setup.py
+++ b/setup.py
@@ -136,6 +136,8 @@ def get_extensions():
main_file = glob.glob(os.path.join(extensions_dir, '*.cpp'))
source_cpu = glob.glob(os.path.join(extensions_dir, 'cpu', '*.cpp'))
+ models_dir = os.path.join(this_dir, 'torchvision', 'csrc', 'models')
+ source_models = glob.glob(os.path.join(models_dir, '*.cpp'))
is_rocm_pytorch = False
if torch.__version__ >= '1.5':
@@ -158,7 +160,7 @@ def get_extensions():
else:
source_cuda = glob.glob(os.path.join(extensions_dir, 'cuda', '*.cu'))
- sources = main_file + source_cpu
+ sources = main_file + source_cpu + source_models
extension = CppExtension
compile_cpp_tests = os.getenv('WITH_CPP_MODELS_TEST', '0') == '1' |
@willyd Thanks for your investigation. I believe that this is intentional because the model C++ files are only compiled if Lines 164 to 174 in 74de51d
Adding @fmassa, who could perhaps shed some light on the intended behaviour. |
Hi, We don't want to ship Ideally, we wouldn't need to include The current situation with the |
Understood.
Thus we should not rely on the extension vision.cpp to register the operators but have a separate cpp file for operator registration, which I think happen in the |
Sure. I will try and get back to you. |
I just merged and updated my branch with the latest master. The header issues are indeed fixed. The only remaining issues with master are:
This PR addresses both the above issues. |
@peterjc123 Could you please have a look? |
if(MSVC) | ||
# This is required for consuming projects otherwise, the linker | ||
# will strip the operators registration symbols. | ||
target_link_options(${PROJECT_NAME} INTERFACE /OPT:NOREF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope torchvision will remain small like now forever. When it grows larger, this will definitely stop working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to this, we thought that #2798 had fixed the linker issues once and for all, but we still need it for Windows as can be seen in
vision/test/tracing/frcnn/test_frcnn_tracing.cpp
Lines 7 to 11 in ce34258
#ifdef _WIN32 | |
// Windows only | |
// This is necessary until operators are automatically registered on include | |
static auto _nms = &vision::ops::nms; | |
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have time to look into it carefully. So at least for now, I will approve this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @bmanga
# A typical build on Windows needs to have Release and Debug libraries but most | ||
# people don't have the python debug library. Hence, we ignore it here and link | ||
# against the Release python library even in debug mode. | ||
set(PYTHON3_DEBUG_LIBRARY_NAME python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}_d.lib) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the quesion may be that why do we need Python for Libtorchvision? It is better to introduce a new variable BUILD_PYTHON
and stop using those tricks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need Python for torchvision and we would love to remove it.
It is currently required only on Windows builds as we need
vision/torchvision/csrc/vision.cpp
Lines 13 to 20 in ce34258
// If we are in a Windows environment, we need to define | |
// initialization functions for the _custom_ops extension | |
#ifdef _WIN32 | |
PyMODINIT_FUNC PyInit__C(void) { | |
// No need to do anything. | |
return NULL; | |
} | |
#endif |
@datumbox has tried removing this recently to see if it was still needed, but Windows builds stopped working.
Do you have any ideas on how we could remove this Python dependency on Windows once and for all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmassa We can pass in a variable USE_PYTHON
. Apparently, this function is unneeded for non-python builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterjc123 Just to make sure I understand what you suggest:
- Add a CMake option USE_PYTHON which defines a preprocessor macro USE_PYTHON or WITH_PYTHON that would not be defined for C++-only builds done via CMake.
- That preprocessor macro would be defined when building with setuptools
If this is what you suggest I can try to add it to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@willyd Yeah, that's exactly what I mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@datumbox Thanks for letting me know. Yes I still intend to give it a shot. I am very busy at work lately, but I should have time to put on this PR before the end of the year.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the integration of WITH_PYTHON
variable to the CMake project and it works in C++. I still need to rebase on master to get the latest changes and test again. It adds quite a few #ifdef so it is probably best to add a new header to avoid those. I will update this PR when I have something that works with the latest master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@willyd that would be great, thanks. Please ping me once you complete the PR to make sure we see it. Since this is quite old, it's in risk of missing any updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@willyd Hi there! Wondering if we can close this PR or if you are still interested in sending the patch. Let me know, thanks! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@datumbox Unfortunately, I don't have time to work on the patch. Let's close the PR and if I still have problems when I get back to it, I will submit a new PR.
Codecov Report
@@ Coverage Diff @@
## master #3087 +/- ##
=======================================
Coverage 73.48% 73.48%
=======================================
Files 99 99
Lines 9230 9230
Branches 1476 1476
=======================================
Hits 6783 6783
Misses 1991 1991
Partials 456 456 Continue to review full report at Codecov.
|
An alternative solution for the windows registration failure is in #3380 |
I haven't looked into the debug python part, but ideally I think we should get rid of the python dep. |
As discussed with @willyd on the comments above (see #3087 (comment)) we will close the PR and tackle the problem on the future on a new PR. |
Fixes #3086