Skip to content

Commit 28dba2f

Browse files
Yangqingfacebook-github-bot
authored andcommitted
Unify all *_EXPORT and *_IMPORT macros across c++ backend (pytorch#12019)
Summary: TSIA. Right now we should basically use C10_EXPORT and C10_IMPORT for explicitly marking dllexport and dllimport, as a continued effort of the C10 unification. This is a codemod by mechanically doing the following change: CAFFE2_{EXPORT,IMPORT} -> C10_{EXPORT,IMPORT} AT_CORE_{EXPORT,IMPORT} -> C10_{EXPORT,IMPORT} Pull Request resolved: pytorch#12019 Reviewed By: ezyang, teng-li Differential Revision: D10016276 Pulled By: Yangqing fbshipit-source-id: a420d62c43d1110105fc88f9e9076e28a3203164
1 parent 90bcf41 commit 28dba2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+534
-506
lines changed

Diff for: aten/src/ATen/core/ATenCoreTest.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
namespace at {
66

7-
AT_CORE_API int CoreTest();
7+
CAFFE2_API int CoreTest();
88
}

Diff for: aten/src/ATen/core/ATenGeneral.h

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
#pragma once
22

33
#include "ATen/core/Macros.h"
4-
5-
// TODO: Merge the *_API macros.
6-
#define AT_EXPORT AT_CORE_EXPORT
7-
#define AT_IMPORT AT_CORE_IMPORT

Diff for: aten/src/ATen/core/Allocator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct Allocator {
115115
}
116116
};
117117

118-
struct AT_CORE_API InefficientStdFunctionContext {
118+
struct CAFFE2_API InefficientStdFunctionContext {
119119
std::unique_ptr<void, std::function<void(void*)>> ptr_;
120120
InefficientStdFunctionContext(
121121
std::unique_ptr<void, std::function<void(void*)>>&& ptr)

Diff for: aten/src/ATen/core/Backtrace.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace at {
1010
/// Utility to demangle a C++ symbol name.
11-
AT_CORE_API std::string demangle(const char* name);
11+
CAFFE2_API std::string demangle(const char* name);
1212

1313
/// Returns the printable name of the type.
1414
template <typename T>
@@ -21,7 +21,7 @@ inline const char* demangle_type() {
2121
#endif // __GXX_RTTI
2222
}
2323

24-
AT_CORE_API std::string get_backtrace(
24+
CAFFE2_API std::string get_backtrace(
2525
size_t frames_to_skip = 0,
2626
size_t maximum_number_of_frames = 64,
2727
bool skip_python_frames = true);

Diff for: aten/src/ATen/core/Device.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace at {
2121
/// 1. A negative index represents the current device, a non-negative index
2222
/// represents a specific, concrete device,
2323
/// 2. When the device type is CPU, the device index must be zero.
24-
struct AT_CORE_API Device {
24+
struct CAFFE2_API Device {
2525
using Type = at::DeviceType;
2626

2727
/// Constructs a new `Device` from a `DeviceType` and an optional device
@@ -92,7 +92,7 @@ struct AT_CORE_API Device {
9292
int32_t index_ = -1;
9393
};
9494

95-
AT_CORE_API std::ostream& operator<<(
95+
CAFFE2_API std::ostream& operator<<(
9696
std::ostream& stream,
9797
const at::Device& device);
9898

Diff for: aten/src/ATen/core/DeviceType.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ enum class DeviceType : int32_t {
2626
ONLY_FOR_TEST = 20901701, // This device type is only for test.
2727
};
2828

29-
AT_CORE_API std::string DeviceTypeName(
29+
CAFFE2_API std::string DeviceTypeName(
3030
at::DeviceType d,
3131
bool lower_case = false);
3232

33-
AT_CORE_API std::ostream& operator<<(std::ostream& stream, at::DeviceType type);
33+
CAFFE2_API std::ostream& operator<<(std::ostream& stream, at::DeviceType type);
3434

3535
} // namespace at
3636

Diff for: aten/src/ATen/core/Error.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace at {
1919
namespace detail {
2020

2121
// Obtains the base name from a full path.
22-
AT_CORE_API std::string StripBasename(const std::string& full_path);
22+
CAFFE2_API std::string StripBasename(const std::string& full_path);
2323

2424
inline std::ostream& _str(std::ostream& ss) {
2525
return ss;
@@ -56,7 +56,7 @@ inline std::string str(const char* c_str) {
5656
}
5757

5858
/// Represents a location in source code (for debugging).
59-
struct AT_CORE_API SourceLocation {
59+
struct CAFFE2_API SourceLocation {
6060
const char* function;
6161
const char* file;
6262
uint32_t line;
@@ -71,7 +71,7 @@ std::ostream& operator<<(std::ostream& out, const SourceLocation& loc);
7171
///
7272
/// NB: at::Error is handled specially by the default torch to suppress the
7373
/// backtrace, see torch/csrc/Exceptions.h
74-
class AT_CORE_API Error : public std::exception {
74+
class CAFFE2_API Error : public std::exception {
7575
std::vector<std::string> msg_stack_;
7676
std::string backtrace_;
7777

@@ -128,7 +128,7 @@ class AT_CORE_API Error : public std::exception {
128128
}
129129
};
130130

131-
class AT_CORE_API Warning {
131+
class CAFFE2_API Warning {
132132
using handler_t =
133133
void (*)(const SourceLocation& source_location, const char* msg);
134134

@@ -152,7 +152,7 @@ class AT_CORE_API Warning {
152152

153153
// A utility function to return an exception std::string by prepending its
154154
// exception type before its what() content
155-
AT_CORE_API std::string GetExceptionString(const std::exception& e);
155+
CAFFE2_API std::string GetExceptionString(const std::exception& e);
156156

157157
} // namespace at
158158

Diff for: aten/src/ATen/core/Half.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace at {
3434

3535
namespace detail {
3636

37-
AT_CORE_API float halfbits2float(unsigned short bits);
38-
AT_CORE_API unsigned short float2halfbits(float value);
37+
CAFFE2_API float halfbits2float(unsigned short bits);
38+
CAFFE2_API unsigned short float2halfbits(float value);
3939

4040
} // namespace detail
4141

@@ -178,7 +178,7 @@ To checked_convert(From f, const char* name) {
178178
return convert<To, From>(f);
179179
}
180180

181-
AT_CORE_API std::ostream& operator<<(std::ostream& out, const Half& value);
181+
CAFFE2_API std::ostream& operator<<(std::ostream& out, const Half& value);
182182

183183
} // namespace at
184184

Diff for: aten/src/ATen/core/IdWrapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace at {
2222
* for you, given the underlying type supports it.
2323
*/
2424
template <class ConcreteType, class UnderlyingType>
25-
class AT_CORE_API IdWrapper {
25+
class CAFFE2_API IdWrapper {
2626
public:
2727
using underlying_type = UnderlyingType;
2828
using concrete_type = ConcreteType;

Diff for: aten/src/ATen/core/LegacyTypeDispatch.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
namespace at {
3232

33-
struct AT_CORE_API LegacyTypeInitInterface {
33+
struct CAFFE2_API LegacyTypeInitInterface {
3434
virtual ~LegacyTypeInitInterface() {}
3535
virtual void initCPU() const {
3636
AT_ERROR("cannot use CPU without ATen library");
@@ -42,15 +42,15 @@ struct AT_CORE_API LegacyTypeInitInterface {
4242
AT_ERROR("cannot use complex without ATen Complex library");
4343
}
4444
};
45-
struct AT_CORE_API LegacyTypeInitArgs {};
45+
struct CAFFE2_API LegacyTypeInitArgs {};
4646
AT_DECLARE_REGISTRY(LegacyTypeInitRegistry, LegacyTypeInitInterface, LegacyTypeInitArgs);
4747
#define REGISTER_LEGACY_TYPE_INIT(clsname) AT_REGISTER_CLASS(LegacyTypeInitRegistry, clsname, clsname)
4848

49-
AT_CORE_API const LegacyTypeInitInterface& getLegacyTypeInit();
49+
CAFFE2_API const LegacyTypeInitInterface& getLegacyTypeInit();
5050

5151
struct Type;
5252

53-
struct AT_CORE_API LegacyTypeDeleter {
53+
struct CAFFE2_API LegacyTypeDeleter {
5454
using TypeDeleterFun = void(Type*);
5555
TypeDeleterFun *fn_ = nullptr;
5656
LegacyTypeDeleter() {}
@@ -62,8 +62,8 @@ struct AT_CORE_API LegacyTypeDeleter {
6262
}
6363
};
6464

65-
class AT_CORE_API LegacyTypeDispatch {
66-
public:
65+
class CAFFE2_API LegacyTypeDispatch {
66+
public:
6767
using TypeUniquePtr = std::unique_ptr<Type, LegacyTypeDeleter>;
6868
// WARNING: This function has the precondition that you have
6969
// initialized the type you want to call. This initialization
@@ -150,6 +150,6 @@ class AT_CORE_API LegacyTypeDispatch {
150150
[static_cast<int>(ScalarType::NumOptions)];
151151
};
152152

153-
AT_CORE_API LegacyTypeDispatch & globalLegacyTypeDispatch();
153+
CAFFE2_API LegacyTypeDispatch& globalLegacyTypeDispatch();
154154

155155
} // namespace at

Diff for: aten/src/ATen/core/SmallVector.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static inline uint64_t NextPowerOf2(uint64_t A) {
5959
} // namespace detail
6060

6161
/// This is all the non-templated stuff common to all SmallVectors.
62-
class AT_CORE_API SmallVectorBase {
62+
class CAFFE2_API SmallVectorBase {
6363
protected:
6464
void *BeginX, *EndX, *CapacityX;
6565

Diff for: aten/src/ATen/core/TensorTypeId.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using _tensorTypeId_underlyingType = uint8_t;
1717
* Dynamic type ID of a Tensor argument. It represents something like
1818
* CPUTensor, etc.
1919
*/
20-
class AT_CORE_API TensorTypeId final
20+
class CAFFE2_API TensorTypeId final
2121
: public at::
2222
IdWrapper<TensorTypeId, details::_tensorTypeId_underlyingType> {
2323
public:
@@ -32,10 +32,10 @@ class AT_CORE_API TensorTypeId final
3232
: IdWrapper(id) {}
3333

3434
friend class TensorTypeIdCreator;
35-
friend AT_CORE_API std::ostream& operator<<(std::ostream&, TensorTypeId);
35+
friend CAFFE2_API std::ostream& operator<<(std::ostream&, TensorTypeId);
3636
};
3737

38-
AT_CORE_API std::ostream& operator<<(std::ostream&, at::TensorTypeId);
38+
CAFFE2_API std::ostream& operator<<(std::ostream&, at::TensorTypeId);
3939

4040
} // namespace at
4141

Diff for: aten/src/ATen/core/TensorTypeIdRegistration.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace at {
1818

19-
class AT_CORE_API TensorTypeIdCreator final {
19+
class CAFFE2_API TensorTypeIdCreator final {
2020
public:
2121
TensorTypeIdCreator();
2222

@@ -29,10 +29,10 @@ class AT_CORE_API TensorTypeIdCreator final {
2929
private:
3030
std::atomic<details::_tensorTypeId_underlyingType> last_id_;
3131

32-
AT_DISABLE_COPY_AND_ASSIGN(TensorTypeIdCreator);
32+
C10_DISABLE_COPY_AND_ASSIGN(TensorTypeIdCreator);
3333
};
3434

35-
class AT_CORE_API TensorTypeIdRegistry final {
35+
class CAFFE2_API TensorTypeIdRegistry final {
3636
public:
3737
TensorTypeIdRegistry();
3838

@@ -43,10 +43,10 @@ class AT_CORE_API TensorTypeIdRegistry final {
4343
std::unordered_set<at::TensorTypeId> registeredTypeIds_;
4444
std::mutex mutex_;
4545

46-
AT_DISABLE_COPY_AND_ASSIGN(TensorTypeIdRegistry);
46+
C10_DISABLE_COPY_AND_ASSIGN(TensorTypeIdRegistry);
4747
};
4848

49-
class AT_CORE_API TensorTypeIds final {
49+
class CAFFE2_API TensorTypeIds final {
5050
public:
5151
static TensorTypeIds& singleton();
5252

@@ -61,14 +61,14 @@ class AT_CORE_API TensorTypeIds final {
6161
TensorTypeIdCreator creator_;
6262
TensorTypeIdRegistry registry_;
6363

64-
AT_DISABLE_COPY_AND_ASSIGN(TensorTypeIds);
64+
C10_DISABLE_COPY_AND_ASSIGN(TensorTypeIds);
6565
};
6666

6767
inline constexpr at::TensorTypeId TensorTypeIds::undefined() noexcept {
6868
return TensorTypeIdCreator::undefined();
6969
}
7070

71-
class AT_CORE_API TensorTypeIdRegistrar final {
71+
class CAFFE2_API TensorTypeIdRegistrar final {
7272
public:
7373
TensorTypeIdRegistrar();
7474
~TensorTypeIdRegistrar();
@@ -78,14 +78,15 @@ class AT_CORE_API TensorTypeIdRegistrar final {
7878
private:
7979
at::TensorTypeId id_;
8080

81-
AT_DISABLE_COPY_AND_ASSIGN(TensorTypeIdRegistrar);
81+
C10_DISABLE_COPY_AND_ASSIGN(TensorTypeIdRegistrar);
8282
};
8383

8484
inline at::TensorTypeId TensorTypeIdRegistrar::id() const noexcept {
8585
return id_;
8686
}
8787

88-
#define AT_DECLARE_TENSOR_TYPE(TensorName) AT_CORE_API at::TensorTypeId TensorName();
88+
#define AT_DECLARE_TENSOR_TYPE(TensorName) \
89+
CAFFE2_API at::TensorTypeId TensorName();
8990

9091
#define AT_DEFINE_TENSOR_TYPE(TensorName) \
9192
at::TensorTypeId TensorName() { \

Diff for: aten/src/ATen/core/UniqueVoidPtr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using DeleterFnPtr = void (*)(void*);
1010
namespace detail {
1111

1212
// Does not delete anything
13-
AT_CORE_API void deleteNothing(void*);
13+
CAFFE2_API void deleteNothing(void*);
1414

1515
// A detail::UniqueVoidPtr is an owning smart pointer like unique_ptr, but
1616
// with three major differences:

Diff for: aten/src/ATen/core/context_base.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BaseContext;
2525
functions that are invoked statically before in Tensor class, e.g. New,
2626
We will merge this with Allocator later.
2727
*/
28-
class AT_CORE_API BaseStaticContext {
28+
class CAFFE2_API BaseStaticContext {
2929
public:
3030
virtual ~BaseStaticContext() noexcept {}
3131

@@ -55,7 +55,7 @@ class AT_CORE_API BaseStaticContext {
5555
* functions in the BaseContext class.
5656
* TODO: add docs after this is finalized.
5757
*/
58-
class AT_CORE_API BaseContext {
58+
class CAFFE2_API BaseContext {
5959
public:
6060
virtual ~BaseContext() noexcept {}
6161

Diff for: aten/src/ATen/core/intrusive_ptr.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace c10 {
3333
// tells us if the object was allocated by us. If it wasn't, no
3434
// intrusive_ptr for you!
3535

36-
class AT_CORE_API intrusive_ptr_target {
36+
class CAFFE2_API intrusive_ptr_target {
3737
// Note [Weak references for intrusive refcounting]
3838
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3939
// Here's the scheme:
@@ -114,7 +114,7 @@ class AT_CORE_API intrusive_ptr_target {
114114

115115
namespace detail {
116116
template <class TTarget>
117-
struct AT_CORE_EXPORT intrusive_target_default_null_type final {
117+
struct C10_EXPORT intrusive_target_default_null_type final {
118118
static constexpr TTarget* singleton() noexcept {
119119
return nullptr;
120120
}
@@ -136,7 +136,7 @@ class weak_intrusive_ptr;
136136
template <
137137
class TTarget,
138138
class NullType = detail::intrusive_target_default_null_type<TTarget>>
139-
class AT_CORE_EXPORT intrusive_ptr final {
139+
class C10_EXPORT intrusive_ptr final {
140140
private:
141141
static_assert(
142142
std::is_base_of<intrusive_ptr_target, TTarget>::value,
@@ -391,7 +391,7 @@ inline bool operator!=(
391391
template <
392392
typename TTarget,
393393
class NullType = detail::intrusive_target_default_null_type<TTarget>>
394-
class AT_CORE_EXPORT weak_intrusive_ptr final {
394+
class C10_EXPORT weak_intrusive_ptr final {
395395
private:
396396
static_assert(
397397
std::is_base_of<intrusive_ptr_target, TTarget>::value,
@@ -739,13 +739,13 @@ namespace std {
739739
// To allow intrusive_ptr and weak_intrusive_ptr inside std::unordered_map or
740740
// std::unordered_set, we need std::hash
741741
template <class TTarget, class NullType>
742-
struct AT_CORE_EXPORT hash<c10::intrusive_ptr<TTarget, NullType>> {
742+
struct C10_EXPORT hash<c10::intrusive_ptr<TTarget, NullType>> {
743743
size_t operator()(const c10::intrusive_ptr<TTarget, NullType>& x) const {
744744
return std::hash<TTarget*>()(x.get());
745745
}
746746
};
747747
template <class TTarget, class NullType>
748-
struct AT_CORE_EXPORT hash<c10::weak_intrusive_ptr<TTarget, NullType>> {
748+
struct C10_EXPORT hash<c10::weak_intrusive_ptr<TTarget, NullType>> {
749749
size_t operator()(const c10::weak_intrusive_ptr<TTarget, NullType>& x) const {
750750
return std::hash<TTarget*>()(x._unsafe_get_target());
751751
}

Diff for: aten/src/ATen/core/ivalue.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct CAFFE2_API ConstantString final : c10::intrusive_ptr_target {
3434

3535
// non-mutable list
3636
template <typename Elem>
37-
struct AT_CORE_EXPORT ConstantList final : c10::intrusive_ptr_target {
37+
struct C10_EXPORT ConstantList final : c10::intrusive_ptr_target {
3838
private:
3939
const std::vector<Elem> elements_;
4040
public:

0 commit comments

Comments
 (0)