Skip to content

Commit

Permalink
Unify all *_EXPORT and *_IMPORT macros across c++ backend (pytorch#12019
Browse files Browse the repository at this point in the history
)

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
  • Loading branch information
Yangqing authored and facebook-github-bot committed Sep 26, 2018
1 parent 90bcf41 commit 28dba2f
Show file tree
Hide file tree
Showing 71 changed files with 534 additions and 506 deletions.
2 changes: 1 addition & 1 deletion aten/src/ATen/core/ATenCoreTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

namespace at {

AT_CORE_API int CoreTest();
CAFFE2_API int CoreTest();
}
4 changes: 0 additions & 4 deletions aten/src/ATen/core/ATenGeneral.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#pragma once

#include "ATen/core/Macros.h"

// TODO: Merge the *_API macros.
#define AT_EXPORT AT_CORE_EXPORT
#define AT_IMPORT AT_CORE_IMPORT
2 changes: 1 addition & 1 deletion aten/src/ATen/core/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct Allocator {
}
};

struct AT_CORE_API InefficientStdFunctionContext {
struct CAFFE2_API InefficientStdFunctionContext {
std::unique_ptr<void, std::function<void(void*)>> ptr_;
InefficientStdFunctionContext(
std::unique_ptr<void, std::function<void(void*)>>&& ptr)
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/core/Backtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

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

AT_CORE_API std::string get_backtrace(
CAFFE2_API std::string get_backtrace(
size_t frames_to_skip = 0,
size_t maximum_number_of_frames = 64,
bool skip_python_frames = true);
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/core/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace at {
/// 1. A negative index represents the current device, a non-negative index
/// represents a specific, concrete device,
/// 2. When the device type is CPU, the device index must be zero.
struct AT_CORE_API Device {
struct CAFFE2_API Device {
using Type = at::DeviceType;

/// Constructs a new `Device` from a `DeviceType` and an optional device
Expand Down Expand Up @@ -92,7 +92,7 @@ struct AT_CORE_API Device {
int32_t index_ = -1;
};

AT_CORE_API std::ostream& operator<<(
CAFFE2_API std::ostream& operator<<(
std::ostream& stream,
const at::Device& device);

Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/core/DeviceType.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ enum class DeviceType : int32_t {
ONLY_FOR_TEST = 20901701, // This device type is only for test.
};

AT_CORE_API std::string DeviceTypeName(
CAFFE2_API std::string DeviceTypeName(
at::DeviceType d,
bool lower_case = false);

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

} // namespace at

Expand Down
10 changes: 5 additions & 5 deletions aten/src/ATen/core/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace at {
namespace detail {

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

inline std::ostream& _str(std::ostream& ss) {
return ss;
Expand Down Expand Up @@ -56,7 +56,7 @@ inline std::string str(const char* c_str) {
}

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

Expand Down Expand Up @@ -128,7 +128,7 @@ class AT_CORE_API Error : public std::exception {
}
};

class AT_CORE_API Warning {
class CAFFE2_API Warning {
using handler_t =
void (*)(const SourceLocation& source_location, const char* msg);

Expand All @@ -152,7 +152,7 @@ class AT_CORE_API Warning {

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

} // namespace at

Expand Down
6 changes: 3 additions & 3 deletions aten/src/ATen/core/Half.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace at {

namespace detail {

AT_CORE_API float halfbits2float(unsigned short bits);
AT_CORE_API unsigned short float2halfbits(float value);
CAFFE2_API float halfbits2float(unsigned short bits);
CAFFE2_API unsigned short float2halfbits(float value);

} // namespace detail

Expand Down Expand Up @@ -178,7 +178,7 @@ To checked_convert(From f, const char* name) {
return convert<To, From>(f);
}

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

} // namespace at

Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/core/IdWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace at {
* for you, given the underlying type supports it.
*/
template <class ConcreteType, class UnderlyingType>
class AT_CORE_API IdWrapper {
class CAFFE2_API IdWrapper {
public:
using underlying_type = UnderlyingType;
using concrete_type = ConcreteType;
Expand Down
14 changes: 7 additions & 7 deletions aten/src/ATen/core/LegacyTypeDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace at {

struct AT_CORE_API LegacyTypeInitInterface {
struct CAFFE2_API LegacyTypeInitInterface {
virtual ~LegacyTypeInitInterface() {}
virtual void initCPU() const {
AT_ERROR("cannot use CPU without ATen library");
Expand All @@ -42,15 +42,15 @@ struct AT_CORE_API LegacyTypeInitInterface {
AT_ERROR("cannot use complex without ATen Complex library");
}
};
struct AT_CORE_API LegacyTypeInitArgs {};
struct CAFFE2_API LegacyTypeInitArgs {};
AT_DECLARE_REGISTRY(LegacyTypeInitRegistry, LegacyTypeInitInterface, LegacyTypeInitArgs);
#define REGISTER_LEGACY_TYPE_INIT(clsname) AT_REGISTER_CLASS(LegacyTypeInitRegistry, clsname, clsname)

AT_CORE_API const LegacyTypeInitInterface& getLegacyTypeInit();
CAFFE2_API const LegacyTypeInitInterface& getLegacyTypeInit();

struct Type;

struct AT_CORE_API LegacyTypeDeleter {
struct CAFFE2_API LegacyTypeDeleter {
using TypeDeleterFun = void(Type*);
TypeDeleterFun *fn_ = nullptr;
LegacyTypeDeleter() {}
Expand All @@ -62,8 +62,8 @@ struct AT_CORE_API LegacyTypeDeleter {
}
};

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

AT_CORE_API LegacyTypeDispatch & globalLegacyTypeDispatch();
CAFFE2_API LegacyTypeDispatch& globalLegacyTypeDispatch();

} // namespace at
2 changes: 1 addition & 1 deletion aten/src/ATen/core/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static inline uint64_t NextPowerOf2(uint64_t A) {
} // namespace detail

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

Expand Down
6 changes: 3 additions & 3 deletions aten/src/ATen/core/TensorTypeId.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using _tensorTypeId_underlyingType = uint8_t;
* Dynamic type ID of a Tensor argument. It represents something like
* CPUTensor, etc.
*/
class AT_CORE_API TensorTypeId final
class CAFFE2_API TensorTypeId final
: public at::
IdWrapper<TensorTypeId, details::_tensorTypeId_underlyingType> {
public:
Expand All @@ -32,10 +32,10 @@ class AT_CORE_API TensorTypeId final
: IdWrapper(id) {}

friend class TensorTypeIdCreator;
friend AT_CORE_API std::ostream& operator<<(std::ostream&, TensorTypeId);
friend CAFFE2_API std::ostream& operator<<(std::ostream&, TensorTypeId);
};

AT_CORE_API std::ostream& operator<<(std::ostream&, at::TensorTypeId);
CAFFE2_API std::ostream& operator<<(std::ostream&, at::TensorTypeId);

} // namespace at

Expand Down
19 changes: 10 additions & 9 deletions aten/src/ATen/core/TensorTypeIdRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace at {

class AT_CORE_API TensorTypeIdCreator final {
class CAFFE2_API TensorTypeIdCreator final {
public:
TensorTypeIdCreator();

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

AT_DISABLE_COPY_AND_ASSIGN(TensorTypeIdCreator);
C10_DISABLE_COPY_AND_ASSIGN(TensorTypeIdCreator);
};

class AT_CORE_API TensorTypeIdRegistry final {
class CAFFE2_API TensorTypeIdRegistry final {
public:
TensorTypeIdRegistry();

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

AT_DISABLE_COPY_AND_ASSIGN(TensorTypeIdRegistry);
C10_DISABLE_COPY_AND_ASSIGN(TensorTypeIdRegistry);
};

class AT_CORE_API TensorTypeIds final {
class CAFFE2_API TensorTypeIds final {
public:
static TensorTypeIds& singleton();

Expand All @@ -61,14 +61,14 @@ class AT_CORE_API TensorTypeIds final {
TensorTypeIdCreator creator_;
TensorTypeIdRegistry registry_;

AT_DISABLE_COPY_AND_ASSIGN(TensorTypeIds);
C10_DISABLE_COPY_AND_ASSIGN(TensorTypeIds);
};

inline constexpr at::TensorTypeId TensorTypeIds::undefined() noexcept {
return TensorTypeIdCreator::undefined();
}

class AT_CORE_API TensorTypeIdRegistrar final {
class CAFFE2_API TensorTypeIdRegistrar final {
public:
TensorTypeIdRegistrar();
~TensorTypeIdRegistrar();
Expand All @@ -78,14 +78,15 @@ class AT_CORE_API TensorTypeIdRegistrar final {
private:
at::TensorTypeId id_;

AT_DISABLE_COPY_AND_ASSIGN(TensorTypeIdRegistrar);
C10_DISABLE_COPY_AND_ASSIGN(TensorTypeIdRegistrar);
};

inline at::TensorTypeId TensorTypeIdRegistrar::id() const noexcept {
return id_;
}

#define AT_DECLARE_TENSOR_TYPE(TensorName) AT_CORE_API at::TensorTypeId TensorName();
#define AT_DECLARE_TENSOR_TYPE(TensorName) \
CAFFE2_API at::TensorTypeId TensorName();

#define AT_DEFINE_TENSOR_TYPE(TensorName) \
at::TensorTypeId TensorName() { \
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/core/UniqueVoidPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using DeleterFnPtr = void (*)(void*);
namespace detail {

// Does not delete anything
AT_CORE_API void deleteNothing(void*);
CAFFE2_API void deleteNothing(void*);

// A detail::UniqueVoidPtr is an owning smart pointer like unique_ptr, but
// with three major differences:
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/core/context_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BaseContext;
functions that are invoked statically before in Tensor class, e.g. New,
We will merge this with Allocator later.
*/
class AT_CORE_API BaseStaticContext {
class CAFFE2_API BaseStaticContext {
public:
virtual ~BaseStaticContext() noexcept {}

Expand Down Expand Up @@ -55,7 +55,7 @@ class AT_CORE_API BaseStaticContext {
* functions in the BaseContext class.
* TODO: add docs after this is finalized.
*/
class AT_CORE_API BaseContext {
class CAFFE2_API BaseContext {
public:
virtual ~BaseContext() noexcept {}

Expand Down
12 changes: 6 additions & 6 deletions aten/src/ATen/core/intrusive_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace c10 {
// tells us if the object was allocated by us. If it wasn't, no
// intrusive_ptr for you!

class AT_CORE_API intrusive_ptr_target {
class CAFFE2_API intrusive_ptr_target {
// Note [Weak references for intrusive refcounting]
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Here's the scheme:
Expand Down Expand Up @@ -114,7 +114,7 @@ class AT_CORE_API intrusive_ptr_target {

namespace detail {
template <class TTarget>
struct AT_CORE_EXPORT intrusive_target_default_null_type final {
struct C10_EXPORT intrusive_target_default_null_type final {
static constexpr TTarget* singleton() noexcept {
return nullptr;
}
Expand All @@ -136,7 +136,7 @@ class weak_intrusive_ptr;
template <
class TTarget,
class NullType = detail::intrusive_target_default_null_type<TTarget>>
class AT_CORE_EXPORT intrusive_ptr final {
class C10_EXPORT intrusive_ptr final {
private:
static_assert(
std::is_base_of<intrusive_ptr_target, TTarget>::value,
Expand Down Expand Up @@ -391,7 +391,7 @@ inline bool operator!=(
template <
typename TTarget,
class NullType = detail::intrusive_target_default_null_type<TTarget>>
class AT_CORE_EXPORT weak_intrusive_ptr final {
class C10_EXPORT weak_intrusive_ptr final {
private:
static_assert(
std::is_base_of<intrusive_ptr_target, TTarget>::value,
Expand Down Expand Up @@ -739,13 +739,13 @@ namespace std {
// To allow intrusive_ptr and weak_intrusive_ptr inside std::unordered_map or
// std::unordered_set, we need std::hash
template <class TTarget, class NullType>
struct AT_CORE_EXPORT hash<c10::intrusive_ptr<TTarget, NullType>> {
struct C10_EXPORT hash<c10::intrusive_ptr<TTarget, NullType>> {
size_t operator()(const c10::intrusive_ptr<TTarget, NullType>& x) const {
return std::hash<TTarget*>()(x.get());
}
};
template <class TTarget, class NullType>
struct AT_CORE_EXPORT hash<c10::weak_intrusive_ptr<TTarget, NullType>> {
struct C10_EXPORT hash<c10::weak_intrusive_ptr<TTarget, NullType>> {
size_t operator()(const c10::weak_intrusive_ptr<TTarget, NullType>& x) const {
return std::hash<TTarget*>()(x._unsafe_get_target());
}
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/core/ivalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct CAFFE2_API ConstantString final : c10::intrusive_ptr_target {

// non-mutable list
template <typename Elem>
struct AT_CORE_EXPORT ConstantList final : c10::intrusive_ptr_target {
struct C10_EXPORT ConstantList final : c10::intrusive_ptr_target {
private:
const std::vector<Elem> elements_;
public:
Expand Down
Loading

0 comments on commit 28dba2f

Please sign in to comment.