Skip to content

Commit 6eef9c2

Browse files
authored
Merge pull request #118 from iotamudelta/master
Merge from upstream
2 parents 5e2bc5a + 77f497c commit 6eef9c2

File tree

97 files changed

+3042
-4220
lines changed

Some content is hidden

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

97 files changed

+3042
-4220
lines changed

.jenkins/caffe2/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ if [[ -z "$INTEGRATED" ]]; then
217217
218218
else
219219
220-
sudo FULL_CAFFE2=1 python setup.py install
220+
FULL_CAFFE2=1 python setup.py install --user
221221
# TODO: I'm not sure why this is necessary
222222
cp -r torch/lib/tmp_install $INSTALL_PREFIX
223223

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,6 @@ include_directories(BEFORE ${PROJECT_BINARY_DIR})
288288

289289
include_directories(BEFORE ${PROJECT_SOURCE_DIR}/aten/src/)
290290

291-
# ---[ Old caffe protobuf
292-
if(BUILD_CAFFE2)
293-
add_subdirectory(caffe/proto)
294-
endif()
295-
296291
# ---[ Main build
297292
add_subdirectory(caffe2)
298293

aten/src/ATen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ IF(USE_CUDA AND NOT USE_ROCM)
251251
ENDIF(USE_MAGMA)
252252
IF ($ENV{ATEN_STATIC_CUDA})
253253
list(APPEND ATen_CUDA_DEPENDENCY_LIBS "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libculibos.a")
254+
list(APPEND ATen_CUDA_DEPENDENCY_LIBS "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcudart_static.a")
254255
ENDIF($ENV{ATEN_STATIC_CUDA})
255256
ENDIF()
256257

aten/src/ATen/CPUApplyUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ inline void _setup_arrays(Tensor& tensor, Arg* iter) {
5757
for (int64_t i = 0; i < max_dim; i++) {
5858
int64_t size = tensor.size(i);
5959
int64_t stride = tensor.stride(i);
60-
while (i + 1 < max_dim &&
60+
while (tensor.stride(i) > 0 && i + 1 < max_dim &&
6161
(tensor.size(i + 1) == 1 ||
6262
tensor.stride(i) == tensor.size(i + 1) * tensor.stride(i + 1))) {
6363
size = size * tensor.size(i + 1);

aten/src/ATen/Declarations.cwrap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
- THStorage* source
5959
- long storage_offset
6060
- IntListSize size
61-
- arg: IntListStride stride
61+
- arg: IntList stride
6262
default: {}
6363
]]
6464
[[
@@ -3408,13 +3408,13 @@
34083408
- cname: newWithSize
34093409
arguments:
34103410
- IntListSize size
3411-
- arg: IntListStride stride
3411+
- IntList stride
34123412
- cname: newWithStorage
34133413
arguments:
34143414
- THStorage* storage
34153415
- int64_t storageOffset
34163416
- IntListSize size
3417-
- arg: IntListStride stride
3417+
- arg: IntList stride
34183418
default: {}
34193419
]]
34203420

aten/src/ATen/Device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ Device::Device(const std::string& device_string) : Device(Type::CPU) {
7575
}
7676
}
7777

78-
} // namespace at
79-
8078
std::ostream& operator<<(std::ostream& stream, const at::Device& device) {
8179
stream << device.type();
8280
if (device.has_index()) {
8381
stream << ":" << device.index();
8482
}
8583
return stream;
8684
}
85+
86+
} // namespace at

aten/src/ATen/Device.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ struct Device {
111111
DeviceType type_;
112112
int32_t index_ = -1;
113113
};
114-
} // namespace at
115114

116115
AT_API std::ostream& operator<<(std::ostream& stream, const at::Device& device);
117116

117+
} // namespace at
118+
119+
118120
namespace std {
119121
template<> struct hash<at::Device>
120122
{

aten/src/ATen/Layout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ inline Layout layout_from_backend(Backend backend) {
2020
return Layout::Strided;
2121
}
2222
}
23-
} // namespace at
2423

2524
inline std::ostream& operator<<(std::ostream& stream, at::Layout layout) {
2625
switch (layout) {
@@ -32,3 +31,5 @@ inline std::ostream& operator<<(std::ostream& stream, at::Layout layout) {
3231
AT_ERROR("Unknown layout");
3332
}
3433
}
34+
35+
} // namespace at

aten/src/ATen/THSizeStrideCompat.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

aten/src/ATen/TensorGeometry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace at {
66

77
bool TensorGeometry::is_contiguous() const {
8+
if (numel_ == 0) {
9+
return true;
10+
}
811
int64_t dim = sizes_.size();
912
int64_t expected_stride = 1;
1013
for (int64_t i = dim - 1; i >= 0; i--) {

aten/src/ATen/TensorGeometry.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ struct AT_API TensorGeometry {
1818
strides_[i] = expected_stride;
1919
expected_stride *= sizes_[i];
2020
}
21+
numel_ = expected_stride;
2122
}
2223

2324
explicit TensorGeometry(const Tensor& t)
2425
: sizes_(t.sizes().vec())
2526
, strides_(t.strides().vec())
26-
, storage_offset_(t.storage_offset()) {}
27+
, storage_offset_(t.storage_offset())
28+
, numel_(t.numel()) {}
2729

2830
// true if the tensor is contiguous
2931
bool is_contiguous() const;
@@ -43,13 +45,7 @@ struct AT_API TensorGeometry {
4345
}
4446
IntList strides() const { return IntList{ strides_ }; }
4547
int64_t storage_offset() const { return storage_offset_; }
46-
int64_t numel() const {
47-
int64_t r = 1;
48-
for (auto s : sizes()) {
49-
r *= s;
50-
}
51-
return r;
52-
}
48+
int64_t numel() const { return numel_; }
5349

5450
TensorGeometry transpose(int64_t dim0, int64_t dim1) {
5551
TensorGeometry r = *this; // copy
@@ -63,6 +59,7 @@ struct AT_API TensorGeometry {
6359
std::vector<int64_t> sizes_;
6460
std::vector<int64_t> strides_;
6561
int64_t storage_offset_;
62+
int64_t numel_;
6663
};
6764

6865
} // namespace at

aten/src/ATen/TensorUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void checkSameGPU(CheckedFrom c, const TensorArg& t1, const TensorArg& t2) {
118118
oss << "Tensor for " << t2 << " is on CPU, ";
119119
}
120120
oss << "but expected " << ((!(t1->is_cuda() || t2->is_cuda())) ? "them" : "it")
121-
<< " to be on GPU (while checking arguments for " << c << ")";
121+
<< " to be on GPU (while checking arguments for " << c << ")";
122122
AT_ERROR(oss.str());
123123
}
124124
AT_CHECK(

aten/src/ATen/core/DeviceType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ std::string DeviceTypeName(at::DeviceType d, bool lower_case) {
3434
}
3535
}
3636

37-
} // namespace at
38-
3937
std::ostream& operator<<(std::ostream& stream, at::DeviceType type) {
4038
stream << at::DeviceTypeName(type, /* lower case */ true);
4139
return stream;
4240
}
41+
42+
} // namespace at

aten/src/ATen/core/DeviceType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ AT_CORE_API std::string DeviceTypeName(
2727
at::DeviceType d,
2828
bool lower_case = false);
2929

30-
} // namespace at
31-
3230
AT_CORE_API std::ostream& operator<<(std::ostream& stream, at::DeviceType type);
31+
32+
} // namespace at

aten/src/ATen/cuda/detail/KernelUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#pragma once
2+
3+
#include "ATen/ATen.h"
4+
25
// Contents of this file are copied from THCUNN/common.h for the ease of porting
36
// THCUNN functions into ATen.
47

@@ -14,6 +17,7 @@ constexpr int CUDA_NUM_THREADS = 1024;
1417
// CUDA: number of blocks for threads.
1518
inline int GET_BLOCKS(const int N)
1619
{
20+
AT_ASSERTM(N > 0, "CUDA kernel launch blocks must be positive, but got N=", N);
1721
return (N + CUDA_NUM_THREADS - 1) / CUDA_NUM_THREADS;
1822
}
1923

aten/src/ATen/cuda/detail/TensorInfo.cuh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace detail {
1111
// CUDA kernel argument that defines tensor layout
1212
template <typename T, typename IndexType>
1313
struct TensorInfo {
14+
TensorInfo();
1415
TensorInfo(T* p,
1516
int dim,
1617
IndexType sz[MAX_TENSORINFO_DIMS],
@@ -47,6 +48,12 @@ struct TensorInfo {
4748
int dims;
4849
};
4950

51+
template <typename T, typename IndexType>
52+
TensorInfo<T, IndexType>::TensorInfo() {
53+
data = nullptr;
54+
dims = 0;
55+
}
56+
5057
template <typename T, typename IndexType>
5158
TensorInfo<T, IndexType>::TensorInfo(T* p,
5259
int dim,
@@ -73,7 +80,7 @@ template <typename T, typename IndexType>
7380
int
7481
TensorInfo<T, IndexType>::collapseDims(const int excludeDim) {
7582

76-
AT_CHECK(excludeDim >= -1 && excludeDim < dims,
83+
AT_CHECK(excludeDim >= -1 && excludeDim < dims,
7784
"expected excluded dim between -1 and dims - 1");
7885

7986
int stopDim = (excludeDim == -1) ? dims : excludeDim;
@@ -87,20 +94,20 @@ TensorInfo<T, IndexType>::collapseDims(const int excludeDim) {
8794
if (sizes[oldIndex] == 1) {
8895
continue;
8996
}
90-
97+
9198
++newIndex;
9299
sizes[newIndex] = sizes[oldIndex];
93100
strides[newIndex] = strides[oldIndex];
94101
++oldIndex;
95-
break;
102+
break;
96103
}
97104

98105
// Collapses dims
99106
for (; oldIndex < stopDim; ++oldIndex) {
100107
if (sizes[oldIndex] == 1) {
101108
continue;
102109
}
103-
110+
104111
if (strides[newIndex] == sizes[oldIndex] * strides[oldIndex]) {
105112
sizes[newIndex] *= sizes[oldIndex];
106113
strides[newIndex] = strides[oldIndex];
@@ -113,7 +120,7 @@ TensorInfo<T, IndexType>::collapseDims(const int excludeDim) {
113120

114121
// Handles excludeDim being set (oldIndex == excludeDim)
115122
if (oldIndex != dims) {
116-
123+
117124
// Preserves excluded dimension
118125
++newIndex;
119126
sizes[newIndex] = sizes[oldIndex];
@@ -146,7 +153,7 @@ struct IndexToOffset {
146153
static __host__ __device__ IndexType get(
147154
IndexType linearId,
148155
const TensorInfo<T, IndexType>& info) {
149-
156+
150157
IndexType offset = 0;
151158

152159
// Uses static dims

aten/src/ATen/function_wrapper.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ def __init__(self, reason):
211211
'THStorage*': 'Storage &',
212212
'THGenerator*': 'Generator *',
213213
'IntListSize': 'IntList',
214-
'IntListStride': 'IntList',
215214
'accreal': 'Scalar',
216215
'real': 'Scalar',
217216
'long': 'int64_t',
@@ -228,7 +227,6 @@ def __init__(self, reason):
228227
'THStorage*': 'Storage',
229228
'THGenerator*': 'Generator*',
230229
'IntListSize': 'IntList',
231-
'IntListStride': 'IntList',
232230
'accreal': 'accreal',
233231
'real': 'real',
234232
'long': 'int64_t',
@@ -297,8 +295,6 @@ def __init__(self, reason):
297295
CodeTemplate(
298296
'check_generator<${Backend}Generator>(${arg_name}, &globalContext().defaultGenerator(backend()))'),
299297
# This is a cast done via direct-construction
300-
'IntListSize': CodeTemplate('at::IntList ${result_name} = get_intlist_size_th(${arg_name});'),
301-
'IntListStride': CodeTemplate('at::IntList ${result_name} = get_intlist_stride_th(${arg_name});'),
302298
'real': CodeTemplate('${arg_name}.to${ScalarName}()'),
303299
'accreal': CodeTemplate('${arg_name}.to${AccScalarName}()'),
304300
'TensorList': CodeTemplate(
@@ -308,8 +304,6 @@ def __init__(self, reason):
308304
'IntList': CodeTemplate('check_intlist<${size}>(${arg_name}, "${arg_name}", ${arg_pos}${,default_init})')
309305
}
310306

311-
DIRECT_CONSTRUCTION_CHECKED_CAST = {'IntListSize', 'IntListStride'}
312-
313307
CHECKED_USE = {
314308
'THTensor*': '{}_->tensor',
315309
'THSTensor*': '{}_->tensor',
@@ -1374,19 +1368,12 @@ def emit_body(env, option):
13741368
if 'default_init' in arg:
13751369
default_init.append(arg['default_init'])
13761370

1377-
if arg['type'] in DIRECT_CONSTRUCTION_CHECKED_CAST:
1378-
body.append(CHECKED_CAST[arg['type']].substitute(
1379-
env, arg_name=arg['name'], arg_pos=count,
1380-
null_okay=null_okay, default_init=default_init,
1381-
size=arg.get('size'),
1382-
result_name=arg['name'] + '_'))
1383-
else:
1384-
check_cast = CHECKED_CAST[arg['type']].substitute(
1385-
env, arg_name=arg['name'], arg_pos=count,
1386-
null_okay=null_okay, default_init=default_init,
1387-
size=arg.get('size'))
1388-
body.append("auto {}_ = {};".format(
1389-
arg['name'], check_cast))
1371+
check_cast = CHECKED_CAST[arg['type']].substitute(
1372+
env, arg_name=arg['name'], arg_pos=count,
1373+
null_okay=null_okay, default_init=default_init,
1374+
size=arg.get('size'))
1375+
body.append("auto {}_ = {};".format(
1376+
arg['name'], check_cast))
13901377
if drop_argument(arg, option) or replace_with_null(arg):
13911378
body.append(
13921379
"(void) {}_; //silence unused warning".format(arg['name']))

0 commit comments

Comments
 (0)