Skip to content

Commit a6f1ae7

Browse files
Yangqingfacebook-github-bot
authored andcommitted
set up c10 scaffolding. Move macros proper first.
Summary: Pull Request resolved: pytorch#11939 Reviewed By: orionr, dzhulgakov Differential Revision: D10004629 Pulled By: Yangqing fbshipit-source-id: ba50a96820d35c7922d81c78c4cbe849c85c251c
1 parent 1a1d79e commit a6f1ae7

Some content is hidden

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

59 files changed

+412
-242
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
55
# ---[ Project and semantic versioning.
66
project(Caffe2 CXX C)
77

8+
set(CMAKE_CXX_STANDARD 11)
9+
if (NOT MSVC)
10+
set(CMAKE_C_STANDARD 11)
11+
endif()
12+
813
set(CAFFE2_VERSION_MAJOR 0)
914
set(CAFFE2_VERSION_MINOR 8)
1015
set(CAFFE2_VERSION_PATCH 2)
@@ -294,6 +299,7 @@ include_directories(BEFORE ${PROJECT_BINARY_DIR})
294299
include_directories(BEFORE ${PROJECT_SOURCE_DIR}/aten/src/)
295300

296301
# ---[ Main build
302+
add_subdirectory(c10)
297303
add_subdirectory(caffe2)
298304

299305
# --[ Documentation

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ than Linux, which are worth keeping in mind when fixing these problems.
262262
1. Symbols are NOT exported by default on Windows; instead, you have to explicitly
263263
mark a symbol as exported/imported in a header file with `__declspec(dllexport)` /
264264
`__declspec(dllimport)`. We have codified this pattern into a set of macros
265-
which follow the convention `*_API`, e.g., `AT_API` inside ATen. (Every separate
266-
shared library needs a unique macro name, because symbol visibility is on a per
267-
shared library basis.)
265+
which follow the convention `*_API`, e.g., `CAFFE2_API` inside Caffe2 and ATen.
266+
(Every separate shared library needs a unique macro name, because symbol visibility
267+
is on a per shared library basis. See c10/macros/Macros.h for more details.)
268268

269269
The upshot is if you see an "unresolved external" error in your Windows build, this
270270
is probably because you forgot to mark a function with `*_API`. However, there is

aten/src/ATen/CPUGeneral.h

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

3-
// Using AT_API is crucial as otherwise you'll see
3+
// Using CAFFE2_API is crucial as otherwise you'll see
44
// linking errors using MSVC
55
// See https://msdn.microsoft.com/en-us/library/a90k134d.aspx
6-
// This header adds this if using AT_API
6+
// This header adds this if using CAFFE2_API
77
#include "ATen/core/ATenGeneral.h"
88

99
namespace at {
10-
AT_API void set_num_threads(int);
11-
AT_API int get_num_threads();
10+
CAFFE2_API void set_num_threads(int);
11+
CAFFE2_API int get_num_threads();
1212
}

aten/src/ATen/CPUTypeDefault.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace at {
55

6-
struct AT_API CPUTypeDefault : public TypeDefault {
6+
struct CAFFE2_API CPUTypeDefault : public TypeDefault {
77
CPUTypeDefault(TensorTypeId type_id, bool is_variable, bool is_undefined)
88
: TypeDefault(type_id, is_variable, is_undefined) {}
99
Allocator* allocator() const override;

aten/src/ATen/Context.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace at {
2424

2525
struct Tensor;
2626

27-
class AT_API Context {
28-
public:
27+
class CAFFE2_API Context {
28+
public:
2929
Context();
3030
TypeExtendedInterface* getNonVariableTypeRaw(Backend p, ScalarType s) {
3131
return static_cast<TypeExtendedInterface*>(globalLegacyTypeDispatch().getNonVariableTypeRaw(p, s));
@@ -133,7 +133,7 @@ class AT_API Context {
133133
friend struct Type;
134134
};
135135

136-
AT_API Context & globalContext();
136+
CAFFE2_API Context& globalContext();
137137

138138
static inline void init() {
139139
globalContext();
@@ -153,11 +153,11 @@ static inline TypeExtendedInterface& getNonVariableType(DeviceType p, ScalarType
153153
return globalContext().getNonVariableType(deviceTypeToBackend(p), s);
154154
}
155155

156-
AT_API TypeExtendedInterface& getType(TensorOptions options);
157-
AT_API TypeExtendedInterface& getType(const TensorImpl*);
158-
AT_API TypeExtendedInterface& getType(const Tensor&);
156+
CAFFE2_API TypeExtendedInterface& getType(TensorOptions options);
157+
CAFFE2_API TypeExtendedInterface& getType(const TensorImpl*);
158+
CAFFE2_API TypeExtendedInterface& getType(const Tensor&);
159159

160-
AT_API Allocator* getCPUAllocator();
160+
CAFFE2_API Allocator* getCPUAllocator();
161161

162162
static inline TypeExtendedInterface& CPU(ScalarType s) {
163163
return getNonVariableType(Backend::CPU, s);

aten/src/ATen/DLConvertor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace at {
1212

13-
AT_API ScalarType toScalarType(const DLDataType& dtype);
14-
AT_API DLManagedTensor * toDLPack(const Tensor& src);
15-
AT_API Tensor fromDLPack(const DLManagedTensor* src);
13+
CAFFE2_API ScalarType toScalarType(const DLDataType& dtype);
14+
CAFFE2_API DLManagedTensor* toDLPack(const Tensor& src);
15+
CAFFE2_API Tensor fromDLPack(const DLManagedTensor* src);
1616

1717
} //namespace at

aten/src/ATen/ExpandUtils.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
namespace at {
1111

12-
AT_API std::vector<int64_t> infer_size(IntList a, IntList b);
13-
AT_API std::tuple<std::vector<int64_t>, std::vector<int64_t> > inferExpandGeometry(
14-
IntList tensor_sizes, IntList tensor_strides, IntList sizes);
12+
CAFFE2_API std::vector<int64_t> infer_size(IntList a, IntList b);
13+
CAFFE2_API std::tuple<std::vector<int64_t>, std::vector<int64_t>>
14+
inferExpandGeometry(
15+
IntList tensor_sizes,
16+
IntList tensor_strides,
17+
IntList sizes);
1518

1619
// avoid copy-construction of Tensor by using a reference_wrapper.
1720
inline void check_defined(std::initializer_list<std::reference_wrapper<const Tensor>> tensors, const char *api_name) {

aten/src/ATen/SparseTensorImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "ATen/core/Error.h"
66

77
namespace at {
8-
struct AT_API SparseTensorImpl : public TensorImpl {
8+
struct CAFFE2_API SparseTensorImpl : public TensorImpl {
99
// Stored in COO format, indices + values.
1010

1111
// INVARIANTS:

aten/src/ATen/TensorGeometry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace at {
77

8-
struct AT_API TensorGeometry {
8+
struct CAFFE2_API TensorGeometry {
99
TensorGeometry() : storage_offset_(0) {}
1010

1111
explicit TensorGeometry(IntList sizes)

aten/src/ATen/TensorUtils.h

+67-27
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace at {
1212
// make sense. These are particularly useful for native functions,
1313
// which do NO argument checking by default.
1414

15-
struct AT_API TensorArg {
15+
struct CAFFE2_API TensorArg {
1616
Tensor tensor;
1717
const char* name;
1818
int pos; // 1-indexed
@@ -22,7 +22,7 @@ struct AT_API TensorArg {
2222
const Tensor& operator*() const { return tensor; }
2323
};
2424

25-
struct AT_API TensorGeometryArg {
25+
struct CAFFE2_API TensorGeometryArg {
2626
TensorGeometry tensor;
2727
const char* name;
2828
int pos; // 1-indexed
@@ -49,40 +49,80 @@ using CheckedFrom = const char*;
4949
// not TensorGeometryArg, because the Tensor to TensorGeometry
5050
// conversion will blow up if you have undefined tensors.
5151

52-
AT_API std::ostream& operator<<(std::ostream & out, TensorGeometryArg t);
53-
AT_API void checkDim(CheckedFrom c, const TensorGeometryArg& t, int64_t dim);
52+
CAFFE2_API std::ostream& operator<<(std::ostream& out, TensorGeometryArg t);
53+
CAFFE2_API void checkDim(
54+
CheckedFrom c,
55+
const TensorGeometryArg& t,
56+
int64_t dim);
5457
// NB: this is an inclusive-exclusive range
55-
AT_API void checkDimRange(CheckedFrom c, const TensorGeometryArg& t, int64_t dim_start, int64_t dim_end);
56-
AT_API void checkSameDim(CheckedFrom c, const TensorGeometryArg& t1, const TensorGeometryArg& t2);
57-
AT_API void checkContiguous(CheckedFrom c, const TensorGeometryArg& t);
58-
AT_API void checkAllContiguous(CheckedFrom c, at::ArrayRef<TensorArg> ts);
59-
AT_API void checkSize(CheckedFrom c, const TensorGeometryArg& t, IntList sizes);
60-
AT_API void checkSize(CheckedFrom c, const TensorGeometryArg& t, int64_t dim, int64_t size);
61-
AT_API void checkNumel(CheckedFrom c, const TensorGeometryArg& t, int64_t numel);
62-
AT_API void checkSameNumel(CheckedFrom c, const TensorGeometryArg& t1, const TensorGeometryArg& t2);
63-
AT_API void checkAllSameNumel(CheckedFrom c, ArrayRef<TensorArg> tensors);
64-
AT_API void checkScalarType(CheckedFrom c, const TensorArg& t, ScalarType s);
65-
AT_API void checkScalarTypes(CheckedFrom c, const TensorArg& t, at::ArrayRef<ScalarType> l);
66-
AT_API void checkSameGPU(CheckedFrom c, const TensorArg& t1, const TensorArg& t2);
67-
AT_API void checkAllSameGPU(CheckedFrom c, ArrayRef<TensorArg> tensors);
68-
AT_API void checkSameType(CheckedFrom c, const TensorArg& t1, const TensorArg& t2);
69-
AT_API void checkAllSameType(CheckedFrom c, ArrayRef<TensorArg> tensors);
70-
AT_API void checkSameSize(CheckedFrom c, const TensorArg& t1, const TensorArg& t2);
71-
AT_API void checkDefined(CheckedFrom c, const TensorArg& t);
72-
AT_API void checkAllDefined(CheckedFrom c, at::ArrayRef<TensorArg> t);
58+
CAFFE2_API void checkDimRange(
59+
CheckedFrom c,
60+
const TensorGeometryArg& t,
61+
int64_t dim_start,
62+
int64_t dim_end);
63+
CAFFE2_API void checkSameDim(
64+
CheckedFrom c,
65+
const TensorGeometryArg& t1,
66+
const TensorGeometryArg& t2);
67+
CAFFE2_API void checkContiguous(CheckedFrom c, const TensorGeometryArg& t);
68+
CAFFE2_API void checkAllContiguous(CheckedFrom c, at::ArrayRef<TensorArg> ts);
69+
CAFFE2_API void checkSize(
70+
CheckedFrom c,
71+
const TensorGeometryArg& t,
72+
IntList sizes);
73+
CAFFE2_API void checkSize(
74+
CheckedFrom c,
75+
const TensorGeometryArg& t,
76+
int64_t dim,
77+
int64_t size);
78+
CAFFE2_API void checkNumel(
79+
CheckedFrom c,
80+
const TensorGeometryArg& t,
81+
int64_t numel);
82+
CAFFE2_API void checkSameNumel(
83+
CheckedFrom c,
84+
const TensorGeometryArg& t1,
85+
const TensorGeometryArg& t2);
86+
CAFFE2_API void checkAllSameNumel(CheckedFrom c, ArrayRef<TensorArg> tensors);
87+
CAFFE2_API void checkScalarType(
88+
CheckedFrom c,
89+
const TensorArg& t,
90+
ScalarType s);
91+
CAFFE2_API void checkScalarTypes(
92+
CheckedFrom c,
93+
const TensorArg& t,
94+
at::ArrayRef<ScalarType> l);
95+
CAFFE2_API void checkSameGPU(
96+
CheckedFrom c,
97+
const TensorArg& t1,
98+
const TensorArg& t2);
99+
CAFFE2_API void checkAllSameGPU(CheckedFrom c, ArrayRef<TensorArg> tensors);
100+
CAFFE2_API void checkSameType(
101+
CheckedFrom c,
102+
const TensorArg& t1,
103+
const TensorArg& t2);
104+
CAFFE2_API void checkAllSameType(CheckedFrom c, ArrayRef<TensorArg> tensors);
105+
CAFFE2_API void checkSameSize(
106+
CheckedFrom c,
107+
const TensorArg& t1,
108+
const TensorArg& t2);
109+
CAFFE2_API void checkDefined(CheckedFrom c, const TensorArg& t);
110+
CAFFE2_API void checkAllDefined(CheckedFrom c, at::ArrayRef<TensorArg> t);
73111

74112
// FixMe: does TensorArg slow things down?
75-
AT_API void checkBackend(CheckedFrom c, at::ArrayRef<Tensor> t, at::Backend backend);
113+
CAFFE2_API void checkBackend(
114+
CheckedFrom c,
115+
at::ArrayRef<Tensor> t,
116+
at::Backend backend);
76117

77118
// Methods for getting data_ptr if tensor is defined
78-
AT_API void * maybe_data_ptr(const Tensor& tensor);
79-
AT_API void * maybe_data_ptr(const TensorArg& tensor);
119+
CAFFE2_API void* maybe_data_ptr(const Tensor& tensor);
120+
CAFFE2_API void* maybe_data_ptr(const TensorArg& tensor);
80121

81122
// Return if the tensor geometry represented by `sizes` and `strides` is contiguous
82123
// Although we cache is_contiguous in tensor now, this is till useful because it
83124
// allows checking if a particular geometry is contiguous without explicitly
84125
// constructing a tensor, e.g., when you want to choose a kernel strategy based
85126
// on whether a subgeometry is contiguous.
86-
AT_API bool geometry_is_contiguous(IntList sizes, IntList strides);
87-
127+
CAFFE2_API bool geometry_is_contiguous(IntList sizes, IntList strides);
88128
}

aten/src/ATen/Utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace at {
2626

27-
AT_API int _crash_if_asan(int);
27+
CAFFE2_API int _crash_if_asan(int);
2828

2929
static inline const Storage& checked_storage(
3030
const Storage& expr,

aten/src/ATen/core/ATenGeneral.h

-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
#include "ATen/core/Macros.h"
44

55
// TODO: Merge the *_API macros.
6-
#define AT_API AT_CORE_API
76
#define AT_EXPORT AT_CORE_EXPORT
87
#define AT_IMPORT AT_CORE_IMPORT

aten/src/ATen/core/Formatting.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
namespace at {
1010

11-
AT_API std::ostream& operator<<(std::ostream & out, IntList list);
12-
AT_API std::ostream& operator<<(std::ostream & out, Backend b);
13-
AT_API std::ostream& operator<<(std::ostream & out, const Type & t);
14-
AT_API std::ostream& print(std::ostream& stream, const Tensor & tensor, int64_t linesize);
11+
CAFFE2_API std::ostream& operator<<(std::ostream& out, IntList list);
12+
CAFFE2_API std::ostream& operator<<(std::ostream& out, Backend b);
13+
CAFFE2_API std::ostream& operator<<(std::ostream& out, const Type& t);
14+
CAFFE2_API std::ostream& print(
15+
std::ostream& stream,
16+
const Tensor& tensor,
17+
int64_t linesize);
1518
static inline std::ostream& operator<<(std::ostream & out, const Tensor & t) {
1619
return print(out,t,80);
1720
}

aten/src/ATen/core/Generator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace at {
77

8-
struct AT_API Generator {
8+
struct CAFFE2_API Generator {
99
Generator() {};
1010
Generator(const Generator& other) = delete;
1111
Generator(Generator&& other) = delete;

aten/src/ATen/core/Macros.h

+1-42
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,7 @@
33
#include <sstream>
44
#include <string>
55

6-
// You can use the definition AT_CORE_STATIC_WINDOWS to control whether
7-
// or not we apply __declspec. You will want to set this as
8-
// -DAT_CORE_STATIC_WINDOWS=1 when compiling code which links
9-
// against ATen/core on Windows, when ATen/core is built as a
10-
// static library (in which case, saying the symbol is coming
11-
// from a DLL would be incorrect).
12-
13-
#ifdef _WIN32
14-
#if !defined(AT_CORE_STATIC_WINDOWS)
15-
#define AT_CORE_EXPORT __declspec(dllexport)
16-
#define AT_CORE_IMPORT __declspec(dllimport)
17-
#else // !defined(AT_CORE_STATIC_WINDOWS)
18-
#define AT_CORE_EXPORT
19-
#define AT_CORE_IMPORT
20-
#endif // !defined(AT_CORE_STATIC_WINDOWS)
21-
#else // _WIN32
22-
#if defined(__GNUC__)
23-
#define AT_CORE_EXPORT __attribute__((__visibility__("default")))
24-
#else // defined(__GNUC__)
25-
#define AT_CORE_EXPORT
26-
#endif // defined(__GNUC__)
27-
#define AT_CORE_IMPORT AT_CORE_EXPORT
28-
#endif // _WIN32
29-
30-
// AT_CORE_API is a macro that, depends on whether you are building the
31-
// main library or not, resolves to either AT_CORE_EXPORT or
32-
// AT_CORE_IMPORT.
33-
//
34-
35-
// TODO: unify the controlling macros.
36-
#if defined(CAFFE2_BUILD_MAIN_LIBS) || defined(ATen_cpu_EXPORTS) || defined(caffe2_EXPORTS)
37-
#define AT_CORE_API AT_CORE_EXPORT
38-
#else // defined(CAFFE2_BUILD_MAIN_LIBS) || defined(ATen_cpu_EXPORTS) || defined(caffe2_EXPORTS)
39-
#define AT_CORE_API AT_CORE_IMPORT
40-
#endif // defined(CAFFE2_BUILD_MAIN_LIBS) || defined(ATen_cpu_EXPORTS) || defined(caffe2_EXPORTS)
6+
#include "c10/macros/Macros.h"
417

428
#ifdef __CUDACC__
439
// Designates functions callable from the host (CPU) and the device (GPU)
@@ -50,13 +16,6 @@
5016
#define AT_DEVICE
5117
#endif
5218

53-
// Disable the copy and assignment operator for a class. Note that this will
54-
// disable the usage of the class in std containers.
55-
#define AT_DISABLE_COPY_AND_ASSIGN(classname) \
56-
classname(const classname&) = delete; \
57-
classname& operator=(const classname&) = delete
58-
59-
6019
#if defined(__ANDROID__)
6120
#define AT_ANDROID 1
6221
#define AT_MOBILE 1

aten/src/ATen/core/OptionsGuard.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct DefaultTensorOptions {
2020
/// Defined in OptionsGuard.cpp because we can't use optional in headers, due
2121
/// to Windows and other compilers.
2222
/// TODO: The inability to use optional in headers is no longer true
23-
AT_API static TensorOptions& get();
23+
CAFFE2_API static TensorOptions& get();
2424

2525
private:
2626
/// This is an optional because of compiler bugs that mis-initialize static
@@ -64,8 +64,9 @@ struct OptionsGuard {
6464
#else // AT_MOBILE
6565

6666
struct DefaultTensorOptions {
67-
AT_API static const TensorOptions& get();
68-
private:
67+
CAFFE2_API static const TensorOptions& get();
68+
69+
private:
6970
static TensorOptions options_;
7071
};
7172

0 commit comments

Comments
 (0)