Unverified Commit dcfd26e8 authored by bmanga's avatar bmanga Committed by GitHub
Browse files

Fix ops registration on windows (#3380)



* On MSVC, instruct the linker not to drop the _register_ops symbol

* Remove workaround for ops registration on windows
Co-authored-by: default avatarFrancisco Massa <fvsmassa@gmail.com>
parent 51500c7e
...@@ -3,11 +3,6 @@ ...@@ -3,11 +3,6 @@
#include <torchvision/vision.h> #include <torchvision/vision.h>
#include <torchvision/ops/nms.h> #include <torchvision/ops/nms.h>
#ifdef _WIN32
// Windows only
// This is necessary until operators are automatically registered on include
static auto _nms = &vision::ops::nms;
#endif
int main() { int main() {
torch::DeviceType device_type; torch::DeviceType device_type;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#else #else
#ifdef _MSC_VER #ifdef _MSC_VER
#define VISION_INLINE_VARIABLE __declspec(selectany) #define VISION_INLINE_VARIABLE __declspec(selectany)
#define HINT_MSVC_LINKER_INCLUDE_SYMBOL
#else #else
#define VISION_INLINE_VARIABLE __attribute__((weak)) #define VISION_INLINE_VARIABLE __attribute__((weak))
#endif #endif
......
...@@ -7,9 +7,10 @@ namespace vision { ...@@ -7,9 +7,10 @@ namespace vision {
VISION_API int64_t cuda_version(); VISION_API int64_t cuda_version();
namespace detail { namespace detail {
// Dummy variable to reference a symbol from vision.cpp. extern "C" VISION_INLINE_VARIABLE auto _register_ops = &cuda_version;
// This ensures that the torchvision library and the ops registration #ifdef HINT_MSVC_LINKER_INCLUDE_SYMBOL
// initializers are not pruned. #pragma comment(linker, "/include:_register_ops")
VISION_INLINE_VARIABLE int64_t _cuda_version = cuda_version(); #endif
} // namespace detail } // namespace detail
} // namespace vision } // namespace vision
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment