|
1 | 1 | #pragma once |
2 | 2 |
|
| 3 | +#ifndef C10_MACROS_EXPORT_H_ |
| 4 | +#define C10_MACROS_EXPORT_H_ |
| 5 | + |
| 6 | +#ifndef C10_USING_CUSTOM_GENERATED_MACROS |
| 7 | +#include <torch/headeronly/macros/cmake_macros.h> |
| 8 | +#endif // C10_USING_CUSTOM_GENERATED_MACROS |
| 9 | + |
3 | 10 | /* Header file to define the common scaffolding for exported symbols. |
4 | 11 | * |
5 | 12 | * Export is by itself a quite tricky situation to deal with, and if you are |
|
85 | 92 | #else |
86 | 93 | #define C10_API C10_IMPORT |
87 | 94 | #endif |
| 95 | + |
| 96 | +// This one is being used by libtorch.so |
| 97 | +#ifdef CAFFE2_BUILD_MAIN_LIB |
| 98 | +#define TORCH_API C10_EXPORT |
| 99 | +#else |
| 100 | +#define TORCH_API C10_IMPORT |
| 101 | +#endif |
| 102 | + |
| 103 | +// You may be wondering why we have TORCH_CUDA_CPP_API and TORCH_CUDA_CU_API |
| 104 | +// belonging to the same library instead of just one TORCH_CUDA_API. Well, it |
| 105 | +// can indeed just be one TORCH_CUDA_API (and used to be)! TORCH_CUDA_CPP_API |
| 106 | +// and TORCH_CUDA_CU_API are artifacts of when we needed a split build to |
| 107 | +// avoid relocation marker linking errors. The context is as follows: |
| 108 | +// |
| 109 | +// Once upon a time, there _was_ only TORCH_CUDA_API. All was happy until we |
| 110 | +// tried to compile PyTorch for CUDA 11.1, which ran into relocation marker |
| 111 | +// issues when linking big binaries. |
| 112 | +// (https://github.com/pytorch/pytorch/issues/39968) We had two choices: |
| 113 | +// (1) Stop supporting so many GPU architectures |
| 114 | +// (2) Do something else |
| 115 | +// We chose #2 and decided to split the behemoth that was torch_cuda into two |
| 116 | +// smaller libraries, one with most of the core kernel functions (torch_cuda_cu) |
| 117 | +// and the other that had..well..everything else (torch_cuda_cpp). The idea was |
| 118 | +// this: instead of linking our static libraries (like the hefty |
| 119 | +// libcudnn_static.a) with another huge library, torch_cuda, and run into pesky |
| 120 | +// relocation marker issues, we could link our static libraries to a smaller |
| 121 | +// part of torch_cuda (torch_cuda_cpp) and avoid the issues. |
| 122 | + |
| 123 | +// libtorch_cuda.so (where torch_cuda_cu and torch_cuda_cpp are a part of the |
| 124 | +// same api) |
| 125 | +#ifdef TORCH_CUDA_BUILD_MAIN_LIB |
| 126 | +#define TORCH_CUDA_CPP_API C10_EXPORT |
| 127 | +#define TORCH_CUDA_CU_API C10_EXPORT |
| 128 | +#else |
| 129 | +#define TORCH_CUDA_CPP_API C10_IMPORT |
| 130 | +#define TORCH_CUDA_CU_API C10_IMPORT |
| 131 | +#endif |
| 132 | + |
| 133 | +#if defined(TORCH_HIP_BUILD_MAIN_LIB) |
| 134 | +#define TORCH_HIP_CPP_API C10_EXPORT |
| 135 | +#define TORCH_HIP_API C10_EXPORT |
| 136 | +#else |
| 137 | +#define TORCH_HIP_CPP_API C10_IMPORT |
| 138 | +#define TORCH_HIP_API C10_IMPORT |
| 139 | +#endif |
| 140 | + |
| 141 | +#if defined(TORCH_XPU_BUILD_MAIN_LIB) |
| 142 | +#define TORCH_XPU_API C10_EXPORT |
| 143 | +#else |
| 144 | +#define TORCH_XPU_API C10_IMPORT |
| 145 | +#endif |
| 146 | + |
| 147 | +// Enums only need to be exported on windows for non-CUDA files |
| 148 | +#if defined(_WIN32) && defined(__CUDACC__) |
| 149 | +#define C10_API_ENUM C10_API |
| 150 | +#else |
| 151 | +#define C10_API_ENUM |
| 152 | +#endif |
| 153 | +#endif // C10_MACROS_EXPORT_H_ |
0 commit comments