From 2c3b9d08b1d06eed79e3380d780ae91eb888fd76 Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 13 Oct 2020 14:49:41 +0200 Subject: [PATCH] Factor out common macros in single file --- CMakeLists.txt | 1 - setup.py | 2 +- torchvision/csrc/cpu/vision_cpu.h | 11 +---------- torchvision/csrc/cuda/vision_cuda.h | 11 +---------- torchvision/csrc/macros.h | 24 ++++++++++++++++++++++++ torchvision/csrc/vision.h | 18 +----------------- 6 files changed, 28 insertions(+), 39 deletions(-) create mode 100644 torchvision/csrc/macros.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e2974657519..cd2a4d49c29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,6 @@ endif() add_library(${PROJECT_NAME} SHARED ${MODELS_SOURCES} ${OPERATOR_SOURCES} ${IMAGE_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} ${PNG_LIBRARY} ${JPEG_LIBRARIES} Python3::Python) -target_compile_definitions(${PROJECT_NAME} PRIVATE VISION_BUILD_LIB) set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchVision) include_directories(torchvision/csrc ${JPEG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}) diff --git a/setup.py b/setup.py index d1ec2399d88..d6674465405 100644 --- a/setup.py +++ b/setup.py @@ -178,7 +178,7 @@ def get_extensions(): tests = test_file + source_models tests_include_dirs = [test_dir, models_dir] - define_macros = [('VISION_BUILD_LIB', None)] + define_macros = [] extra_compile_args = {} if (torch.cuda.is_available() and ((CUDA_HOME is not None) or is_rocm_pytorch)) \ diff --git a/torchvision/csrc/cpu/vision_cpu.h b/torchvision/csrc/cpu/vision_cpu.h index 331043c5d39..c2a2c36ce99 100644 --- a/torchvision/csrc/cpu/vision_cpu.h +++ b/torchvision/csrc/cpu/vision_cpu.h @@ -1,15 +1,6 @@ #pragma once #include - -#ifdef _WIN32 -#if defined(torchvision_EXPORTS) -#define VISION_API __declspec(dllexport) -#else -#define VISION_API __declspec(dllimport) -#endif -#else -#define VISION_API -#endif +#include "../macros.h" VISION_API std::tuple ROIPool_forward_cpu( const at::Tensor& input, diff --git a/torchvision/csrc/cuda/vision_cuda.h b/torchvision/csrc/cuda/vision_cuda.h index e3175ad39e2..2c13d0aeed3 100644 --- a/torchvision/csrc/cuda/vision_cuda.h +++ b/torchvision/csrc/cuda/vision_cuda.h @@ -1,15 +1,6 @@ #pragma once #include - -#ifdef _WIN32 -#if defined(torchvision_EXPORTS) -#define VISION_API __declspec(dllexport) -#else -#define VISION_API __declspec(dllimport) -#endif -#else -#define VISION_API -#endif +#include "../macros.h" VISION_API at::Tensor ROIAlign_forward_cuda( const at::Tensor& input, diff --git a/torchvision/csrc/macros.h b/torchvision/csrc/macros.h new file mode 100644 index 00000000000..cb01005a022 --- /dev/null +++ b/torchvision/csrc/macros.h @@ -0,0 +1,24 @@ +#ifndef TORCHVISION_MACROS_H +#define TORCHVISION_MACROS_H + +#ifdef _WIN32 +#if defined(torchvision_EXPORTS) +#define VISION_API __declspec(dllexport) +#else +#define VISION_API __declspec(dllimport) +#endif +#else +#define VISION_API +#endif + +#if (defined __cpp_inline_variables) || __cplusplus >= 201703L +#define VISION_INLINE_VARIABLE inline +#else +#ifdef _MSC_VER +#define VISION_INLINE_VARIABLE __declspec(selectany) +#else +#define VISION_INLINE_VARIABLE __attribute__((weak)) +#endif +#endif + +#endif // TORCHVISION_MACROS_H diff --git a/torchvision/csrc/vision.h b/torchvision/csrc/vision.h index 5060d489edc..9362cd069e4 100644 --- a/torchvision/csrc/vision.h +++ b/torchvision/csrc/vision.h @@ -1,24 +1,8 @@ #ifndef VISION_H #define VISION_H -#include #include - -#if (defined __cpp_inline_variables) || __cplusplus >= 201703L -#define VISION_INLINE_VARIABLE inline -#else -#ifdef _MSC_VER -#define VISION_INLINE_VARIABLE __declspec(selectany) -#else -#define VISION_INLINE_VARIABLE __attribute__((weak)) -#endif -#endif - -#ifdef VISION_BUILD_LIB -#define VISION_API C10_EXPORT -#else -#define VISION_API C10_IMPORT -#endif +#include "macros.h" namespace vision { VISION_API int RegisterOps() noexcept;