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; 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