From 9d5b0c134f33ae29c61722e5be471c3e209c8f5c Mon Sep 17 00:00:00 2001 From: Bruno Manganelli Date: Thu, 11 Feb 2021 14:48:12 +0000 Subject: [PATCH 1/2] On MSVC, instruct the linker not to drop the _register_ops symbol --- torchvision/csrc/macros.h | 1 + torchvision/csrc/vision.h | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/torchvision/csrc/macros.h b/torchvision/csrc/macros.h index 559140a933a..8a7136fad86 100644 --- a/torchvision/csrc/macros.h +++ b/torchvision/csrc/macros.h @@ -15,6 +15,7 @@ #else #ifdef _MSC_VER #define VISION_INLINE_VARIABLE __declspec(selectany) +#define HINT_MSVC_LINKER_INCLUDE_SYMBOL #else #define VISION_INLINE_VARIABLE __attribute__((weak)) #endif diff --git a/torchvision/csrc/vision.h b/torchvision/csrc/vision.h index 806ebef7589..22f8c6cdd38 100644 --- a/torchvision/csrc/vision.h +++ b/torchvision/csrc/vision.h @@ -7,9 +7,10 @@ namespace vision { VISION_API int64_t cuda_version(); namespace detail { -// Dummy variable to reference a symbol from vision.cpp. -// This ensures that the torchvision library and the ops registration -// initializers are not pruned. -VISION_INLINE_VARIABLE int64_t _cuda_version = cuda_version(); +extern "C" VISION_INLINE_VARIABLE auto _register_ops = &cuda_version; +#ifdef HINT_MSVC_LINKER_INCLUDE_SYMBOL +#pragma comment(linker, "/include:_register_ops") +#endif + } // namespace detail } // namespace vision From 1788138a4bb702bc8e304ee710e1ef51aeaba1ab Mon Sep 17 00:00:00 2001 From: Bruno Manganelli Date: Thu, 11 Feb 2021 14:57:22 +0000 Subject: [PATCH 2/2] Remove workaround for ops registration on windows --- test/tracing/frcnn/test_frcnn_tracing.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/tracing/frcnn/test_frcnn_tracing.cpp b/test/tracing/frcnn/test_frcnn_tracing.cpp index 8fef0519089..f5f350b6b02 100644 --- a/test/tracing/frcnn/test_frcnn_tracing.cpp +++ b/test/tracing/frcnn/test_frcnn_tracing.cpp @@ -3,11 +3,6 @@ #include #include -#ifdef _WIN32 -// Windows only -// This is necessary until operators are automatically registered on include -static auto _nms = &vision::ops::nms; -#endif int main() { torch::DeviceType device_type;