Skip to content

Commit

Permalink
Factor out common macros in single file
Browse files Browse the repository at this point in the history
  • Loading branch information
bmanga committed Oct 15, 2020
1 parent 535504d commit 2c3b9d0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 39 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)) \
Expand Down
11 changes: 1 addition & 10 deletions torchvision/csrc/cpu/vision_cpu.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#pragma once
#include <torch/extension.h>

#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<at::Tensor, at::Tensor> ROIPool_forward_cpu(
const at::Tensor& input,
Expand Down
11 changes: 1 addition & 10 deletions torchvision/csrc/cuda/vision_cuda.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#pragma once
#include <torch/extension.h>

#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,
Expand Down
24 changes: 24 additions & 0 deletions torchvision/csrc/macros.h
Original file line number Diff line number Diff line change
@@ -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
18 changes: 1 addition & 17 deletions torchvision/csrc/vision.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
#ifndef VISION_H
#define VISION_H

#include <c10/macros/Macros.h>
#include <torchvision/models/models.h>

#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;
Expand Down

0 comments on commit 2c3b9d0

Please sign in to comment.