Skip to content

Commit c7df2c5

Browse files
committed
Update on "bump pt core pin to 0718"
Differential Revision: [D78579692](https://our.internmc.facebook.com/intern/diff/D78579692/) [ghstack-poisoned]
1 parent 4524604 commit c7df2c5

File tree

1 file changed

+66
-0
lines changed
  • runtime/core/portable_type/c10/torch/headeronly/macros

1 file changed

+66
-0
lines changed

runtime/core/portable_type/c10/torch/headeronly/macros/Export.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#pragma once
22

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+
310
/* Header file to define the common scaffolding for exported symbols.
411
*
512
* Export is by itself a quite tricky situation to deal with, and if you are
@@ -85,3 +92,62 @@
8592
#else
8693
#define C10_API C10_IMPORT
8794
#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

Comments
 (0)