Skip to content

Commit dee2f5b

Browse files
authored
Merge pull request #104 from iotamudelta/master
Merge from upstream
2 parents 1e6bf28 + 8558486 commit dee2f5b

37 files changed

+869
-458
lines changed

.jenkins/pytorch/build.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fi
7474
WERROR=1 python setup.py install
7575

7676
# Add the test binaries so that they won't be git clean'ed away
77-
git add -f build/bin build/lib
77+
git add -f build/bin
7878

7979
# Testing ATen install
8080
if [[ "$BUILD_ENVIRONMENT" != *cuda* ]]; then
@@ -101,3 +101,11 @@ if [[ "$BUILD_ENVIRONMENT" == *xenial-cuda8-cudnn6-py3* ]]; then
101101
make html
102102
popd
103103
fi
104+
105+
# Test no-Python build
106+
if [[ "$BUILD_TEST_LIBTORCH" == "1" ]]; then
107+
echo "Building libtorch"
108+
# NB: Install outside of source directory (at the same level as the root
109+
# pytorch folder) so that it doesn't get cleaned away prior to docker push.
110+
WERROR=1 VERBOSE=1 tools/cpp_build/build_caffe2.sh "$PWD/../cpp-build"
111+
fi

.jenkins/pytorch/macos-build.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ export IMAGE_COMMIT_TAG=${BUILD_ENVIRONMENT}-${IMAGE_COMMIT_ID}
6161

6262
python setup.py install
6363

64-
# this is a bit hacky, but not too bad. Bundle the test binaries into
65-
# the installation directory, so they can catch a free ride on the 7z
66-
# train.
67-
mkdir -p ${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch/test_binaries/build
68-
mv build/{bin,lib} ${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch/test_binaries/build/
69-
7064
# Upload torch binaries when the build job is finished
7165
7z a ${IMAGE_COMMIT_TAG}.7z ${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch*
7266
aws s3 cp ${IMAGE_COMMIT_TAG}.7z s3://ossci-macos-build/pytorch/${IMAGE_COMMIT_TAG}.7z --acl public-read

.jenkins/pytorch/macos-test.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,22 @@ test_python_all() {
5050
test_cpp_api() {
5151
# C++ API
5252

53+
# NB: Install outside of source directory (at the same level as the root
54+
# pytorch folder) so that it doesn't get cleaned away prior to docker push.
55+
# But still clean it before we perform our own build.
56+
#
57+
CPP_BUILD="$PWD/../cpp-build"
58+
rm -rf $CPP_BUILD
59+
mkdir -p $CPP_BUILD
60+
WERROR=1 VERBOSE=1 tools/cpp_build/build_caffe2.sh "$CPP_BUILD"
61+
5362
python tools/download_mnist.py --quiet -d test/cpp/api/mnist
5463

5564
# Unfortunately it seems like the test can't load from miniconda3
5665
# without these paths being set
5766
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$PWD/miniconda3/lib"
5867
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/miniconda3/lib"
59-
${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch/test_binaries/build/bin/test_api
68+
"$CPP_BUILD"/caffe2/bin/test_api
6069
}
6170

6271
if [ -z "${JOB_BASE_NAME}" ] || [[ "${JOB_BASE_NAME}" == *-test ]]; then

.jenkins/pytorch/test.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ test_torchvision() {
108108
test_libtorch() {
109109
if [[ "$BUILD_TEST_LIBTORCH" == "1" ]]; then
110110
echo "Testing libtorch"
111+
CPP_BUILD="$PWD/../cpp-build"
111112
if [[ "$BUILD_ENVIRONMENT" == *cuda* ]]; then
112-
./build/bin/test_jit
113+
"$CPP_BUILD"/caffe2/bin/test_jit
113114
else
114-
./build/bin/test_jit "[cpu]"
115+
"$CPP_BUILD"/caffe2/bin/test_jit "[cpu]"
115116
fi
116117
python tools/download_mnist.py --quiet -d test/cpp/api/mnist
117-
OMP_NUM_THREADS=2 ./build/bin/test_api
118+
OMP_NUM_THREADS=2 "$CPP_BUILD"/caffe2/bin/test_api
118119
fi
119120
}
120121

aten/src/ATen/Backend.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#pragma once
2+
#include <stdexcept>
3+
4+
namespace at {
5+
6+
enum class Backend { CPU, CUDA, SparseCPU, SparseCUDA, Undefined, NumOptions };
7+
8+
constexpr Backend kCPU = Backend::CPU;
9+
constexpr Backend kCUDA = Backend::CUDA;
10+
constexpr Backend kSparseCPU = Backend::SparseCPU;
11+
constexpr Backend kSparseCUDA = Backend::SparseCUDA;
12+
13+
static inline Backend toSparse(Backend b) {
14+
switch (b) {
15+
case Backend::CPU:
16+
return Backend::SparseCPU;
17+
case Backend::CUDA:
18+
return Backend::SparseCUDA;
19+
case Backend::SparseCPU:
20+
return Backend::SparseCPU;
21+
case Backend::SparseCUDA:
22+
return Backend::SparseCUDA;
23+
default:
24+
throw std::runtime_error("Unknown backend");
25+
}
26+
}
27+
28+
static inline Backend toDense(Backend b) {
29+
switch (b) {
30+
case Backend::CPU:
31+
return Backend::CPU;
32+
case Backend::CUDA:
33+
return Backend::CUDA;
34+
case Backend::SparseCPU:
35+
return Backend::CPU;
36+
case Backend::SparseCUDA:
37+
return Backend::CUDA;
38+
default:
39+
throw std::runtime_error("Unknown backend");
40+
}
41+
}
42+
43+
static inline const char* toString(Backend b) {
44+
switch (b) {
45+
case Backend::CPU:
46+
return "CPU";
47+
case Backend::CUDA:
48+
return "CUDA";
49+
case Backend::SparseCPU:
50+
return "SparseCPU";
51+
case Backend::SparseCUDA:
52+
return "SparseCUDA";
53+
default:
54+
return "UNKNOWN_BACKEND";
55+
}
56+
}
57+
58+
} // namespace at

aten/src/ATen/Device.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <ATen/ScalarType.h>
44
#include <ATen/core/Error.h>
55
#include <ATen/core/DeviceType.h>
6+
#include <ATen/core/Error.h>
67

78
#include <cstddef>
89
#include <iosfwd>
@@ -38,7 +39,8 @@ struct Device {
3839
}
3940
}
4041

41-
/// Constructs a new `Device` from a `DeviceType` and an optional device index.
42+
/// Constructs a new `Device` from a `DeviceType` and an optional device
43+
/// index.
4244
/* implicit */ Device(DeviceType type, int32_t index = -1)
4345
: type_(type), index_(index) {
4446
AT_CHECK(

aten/src/ATen/ScalarType.h

Lines changed: 3 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,4 @@
11
#pragma once
2-
3-
#include "ATen/ATenGeneral.h"
4-
#include "ATen/core/ArrayRef.h"
5-
#include "ATen/core/Half.h"
6-
7-
#include <cstdint>
8-
#include <iostream>
9-
10-
namespace at {
11-
12-
// NB: Order matters for this macro; it is relied upon in
13-
// _promoteTypesLookup and the serialization format.
14-
#define AT_FORALL_SCALAR_TYPES(_) \
15-
_(uint8_t,Byte,i) /* 0 */ \
16-
_(int8_t,Char,i) /* 1 */ \
17-
_(int16_t,Short,i) /* 2 */ \
18-
_(int,Int,i) /* 3 */ \
19-
_(int64_t,Long,i) /* 4 */ \
20-
_(at::Half,Half,d) /* 5 */ \
21-
_(float,Float,d) /* 6 */ \
22-
_(double,Double,d) /* 7 */
23-
24-
#define AT_FORALL_SCALAR_TYPES_EXCEPT_HALF(_) \
25-
_(uint8_t,Byte,i) \
26-
_(int8_t,Char,i) \
27-
_(int16_t,Short,i) \
28-
_(int,Int,i) \
29-
_(int64_t,Long,i) \
30-
_(float,Float,d) \
31-
_(double,Double,d)
32-
33-
enum class ScalarType {
34-
#define DEFINE_ENUM(_1,n,_2) \
35-
n,
36-
AT_FORALL_SCALAR_TYPES(DEFINE_ENUM)
37-
#undef DEFINE_ENUM
38-
Undefined, // 8
39-
NumOptions
40-
};
41-
42-
enum class Backend {
43-
CPU,
44-
CUDA,
45-
SparseCPU,
46-
SparseCUDA,
47-
Undefined,
48-
NumOptions
49-
};
50-
51-
constexpr Backend kCPU = Backend::CPU;
52-
constexpr Backend kCUDA = Backend::CUDA;
53-
constexpr Backend kSparseCPU = Backend::SparseCPU;
54-
constexpr Backend kSparseCUDA = Backend::SparseCUDA;
55-
56-
static inline Backend toSparse(Backend b) {
57-
switch (b) {
58-
case Backend::CPU: return Backend::SparseCPU;
59-
case Backend::CUDA: return Backend::SparseCUDA;
60-
case Backend::SparseCPU: return Backend::SparseCPU;
61-
case Backend::SparseCUDA: return Backend::SparseCUDA;
62-
default: throw std::runtime_error("Unknown backend");
63-
}
64-
}
65-
66-
static inline Backend toDense(Backend b) {
67-
switch (b) {
68-
case Backend::CPU: return Backend::CPU;
69-
case Backend::CUDA: return Backend::CUDA;
70-
case Backend::SparseCPU: return Backend::CPU;
71-
case Backend::SparseCUDA: return Backend::CUDA;
72-
default: throw std::runtime_error("Unknown backend");
73-
}
74-
}
75-
76-
static inline const char * toString(Backend b) {
77-
switch(b) {
78-
case Backend::CPU: return "CPU";
79-
case Backend::CUDA: return "CUDA";
80-
case Backend::SparseCPU: return "SparseCPU";
81-
case Backend::SparseCUDA: return "SparseCUDA";
82-
default: return "UNKNOWN_BACKEND";
83-
}
84-
}
85-
86-
#define DEFINE_CONSTANT(_,name,_2) \
87-
constexpr ScalarType k##name = ScalarType::name;
88-
89-
AT_FORALL_SCALAR_TYPES(DEFINE_CONSTANT)
90-
#undef DEFINE_CONSTANT
91-
92-
static inline const char * toString(ScalarType t) {
93-
#define DEFINE_CASE(_,name,_2) \
94-
case ScalarType:: name : return #name;
95-
96-
switch(t) {
97-
AT_FORALL_SCALAR_TYPES(DEFINE_CASE)
98-
default:
99-
return "UNKNOWN_SCALAR";
100-
}
101-
#undef DEFINE_CASE
102-
}
103-
104-
static inline size_t elementSize(ScalarType t) {
105-
#define CASE_ELEMENTSIZE_CASE(ctype,name,_2) \
106-
case ScalarType:: name : return sizeof(ctype);
107-
108-
switch(t) {
109-
AT_FORALL_SCALAR_TYPES(CASE_ELEMENTSIZE_CASE)
110-
default:
111-
AT_ERROR("Unknown ScalarType");
112-
}
113-
#undef CASE_ELEMENTSIZE_CASE
114-
}
115-
116-
static inline bool isIntegralType(ScalarType t) {
117-
return (t == ScalarType::Byte ||
118-
t == ScalarType::Char ||
119-
t == ScalarType::Int ||
120-
t == ScalarType::Long ||
121-
t == ScalarType::Short);
122-
}
123-
124-
static inline bool isFloatingType(ScalarType t) {
125-
return (t == ScalarType::Double ||
126-
t == ScalarType::Float ||
127-
t == ScalarType::Half);
128-
}
129-
130-
static inline ScalarType promoteTypes(ScalarType a, ScalarType b) {
131-
// This is generated according to NumPy's promote_types
132-
constexpr auto u1 = ScalarType::Byte;
133-
constexpr auto i1 = ScalarType::Char;
134-
constexpr auto i2 = ScalarType::Short;
135-
constexpr auto i4 = ScalarType::Int;
136-
constexpr auto i8 = ScalarType::Long;
137-
constexpr auto f2 = ScalarType::Half;
138-
constexpr auto f4 = ScalarType::Float;
139-
constexpr auto f8 = ScalarType::Double;
140-
constexpr auto ud = ScalarType::Undefined;
141-
static constexpr ScalarType _promoteTypesLookup
142-
[static_cast<int>(ScalarType::NumOptions)]
143-
[static_cast<int>(ScalarType::NumOptions)] = {
144-
/* u1 i1 i2 i4 i8 f2 f4 f8, ud */
145-
/* u1 */ { u1, i2, i2, i4, i8, f2, f4, f8, ud },
146-
/* i1 */ { i2, i1, i2, i4, i8, f2, f4, f8, ud },
147-
/* i2 */ { i2, i2, i2, i4, i8, f4, f4, f8, ud },
148-
/* i4 */ { i4, i4, i4, i4, i8, f8, f4, f8, ud },
149-
/* i8 */ { i8, i8, i8, i8, i8, f8, f4, f8, ud },
150-
/* f2 */ { f2, f2, f4, f8, f8, f2, f4, f8, ud },
151-
/* f4 */ { f4, f4, f4, f4, f4, f4, f4, f8, ud },
152-
/* f8 */ { f8, f8, f8, f8, f8, f8, f8, f8, ud },
153-
/* ud */ { ud, ud, ud, ud, ud, ud, ud, ud, ud },
154-
};
155-
return _promoteTypesLookup[static_cast<int>(a)][static_cast<int>(b)];
156-
}
157-
158-
struct Tensor;
159-
typedef ArrayRef<int64_t> IntList;
160-
typedef ArrayRef<Tensor> TensorList;
161-
162-
} // namespace at
163-
164-
inline std::ostream& operator<<(
165-
std::ostream& stream,
166-
at::ScalarType scalar_type) {
167-
return stream << at::toString(scalar_type);
168-
}
2+
#include <ATen/ATenGeneral.h> // for BC reasons
3+
#include <ATen/Backend.h>
4+
#include <ATen/core/ScalarType.h>

aten/src/ATen/core/ATenCoreTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <ATen/core/CoreAPI.h>
3+
#include <ATen/core/Macros.h>
44

55
namespace at {
66

aten/src/ATen/core/Backtrace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <string>
55
#include <typeinfo>
66

7-
#include <ATen/core/CoreAPI.h>
7+
#include <ATen/core/Macros.h>
88

99
namespace at {
1010
/// Utility to demangle a C++ symbol name.

aten/src/ATen/core/DeviceType.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ATen/core (which would require a lot more build system hacking.)
44
// If you modify me, keep me synchronized with that file.
55

6-
#include <ATen/core/CoreAPI.h>
6+
#include <ATen/core/Macros.h>
77

88
#include <ostream>
99

@@ -12,19 +12,21 @@ namespace at {
1212
// Underlying type declared to be int32_t for consistency with protobufs.
1313
enum class DeviceType : int32_t {
1414
CPU = 0,
15-
CUDA = 1, // CUDA.
16-
MKLDNN = 2, // Reserved for explicit MKLDNN
17-
OPENGL = 3, // OpenGL
18-
OPENCL = 4, // OpenCL
19-
IDEEP = 5, // IDEEP.
20-
HIP = 6, // AMD HIP
15+
CUDA = 1, // CUDA.
16+
MKLDNN = 2, // Reserved for explicit MKLDNN
17+
OPENGL = 3, // OpenGL
18+
OPENCL = 4, // OpenCL
19+
IDEEP = 5, // IDEEP.
20+
HIP = 6, // AMD HIP
2121
// Change the following number if you add more devices in the code.
2222
COMPILE_TIME_MAX_DEVICE_TYPES = 7,
23-
ONLY_FOR_TEST = 20901701, // This device type is only for test.
23+
ONLY_FOR_TEST = 20901701, // This device type is only for test.
2424
};
2525

26-
AT_CORE_API std::string DeviceTypeName(at::DeviceType d, bool lower_case = false);
26+
AT_CORE_API std::string DeviceTypeName(
27+
at::DeviceType d,
28+
bool lower_case = false);
2729

28-
}
30+
} // namespace at
2931

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

aten/src/ATen/core/Error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <ATen/core/CoreAPI.h>
3+
#include <ATen/core/Macros.h>
44
#include <ATen/core/optional.h>
55

66
#include <cstddef>

aten/src/ATen/core/Half-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <cstring>
44
#include <limits>
5-
#include <ATen/core/CoreAPI.h>
5+
#include <ATen/core/Macros.h>
66

77
#ifdef __CUDACC__
88
#include <cuda_fp16.h>

0 commit comments

Comments
 (0)