Skip to content

Commit 99dda1e

Browse files
authored
Merge pull request #82 from iotamudelta/master
Merge from upstream
2 parents 8bdaf54 + 11df981 commit 99dda1e

File tree

154 files changed

+2640
-826
lines changed

Some content is hidden

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

154 files changed

+2640
-826
lines changed

.clang-tidy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
# NOTE: there must be no spaces before the '-', so put the comma first.
33
Checks: '
44
*
5+
,clang-analyzer-*
56
,modernize-*
67
,-cert-err58-cpp
78
,-cert-err60-cpp
89
,-clang-diagnostic-*
910
,-cppcoreguidelines-owning-memory
1011
,-cppcoreguidelines-pro-bounds-array-to-pointer-decay
1112
,-cppcoreguidelines-pro-bounds-constant-array-index
13+
,-cppcoreguidelines-pro-type-member-init
1214
,-cppcoreguidelines-pro-type-static-cast-downcast
1315
,-cppcoreguidelines-pro-type-vararg
1416
,-cppcoreguidelines-special-member-functions
@@ -23,9 +25,11 @@ Checks: '
2325
,-hicpp-braces-around-statements
2426
,-hicpp-explicit-conversions
2527
,-hicpp-no-array-decay
28+
,-hicpp-signed-bitwise
2629
,-hicpp-special-member-functions
2730
,-hicpp-vararg
2831
,-llvm-header-guard
32+
,-llvm-include-order
2933
,-llvm-namespace-comment
3034
,-misc-unused-parameters
3135
,-modernize-make-unique
@@ -34,7 +38,6 @@ Checks: '
3438
,-readability-braces-around-statements
3539
,-readability-else-after-return
3640
,-readability-named-parameter
37-
,clang-analyzer-*
3841
'
3942
WarningsAsErrors: ''
4043
HeaderFilterRegex: 'torch/csrc/'

.jenkins/caffe2/test.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ for test in $(find "${INSTALL_PREFIX}/test" -executable -type f); do
6464
;;
6565
*/aten/*)
6666
# ATen uses test framework Catch2
67-
"$test" -r=xml -o "${junit_reports_dir}/$(basename $test).xml"
67+
# NB: We do NOT use the xml test reporter, because
68+
# Catch doesn't support multiple reporters
69+
# c.f. https://github.com/catchorg/Catch2/blob/master/docs/release-notes.md#223
70+
# which means that enabling XML output means you lose useful stdout
71+
# output for Jenkins. It's more important to have useful console
72+
# output than it is to have XML output for Jenkins.
73+
"$test"
6874
;;
6975
*)
7076
"$test" --gtest_output=xml:"$gtest_reports_dir/$(basename $test).xml"

.jenkins/pytorch/build.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@ if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then
4343
# https://github.com/RadeonOpenCompute/hcc#hcc-with-thinlto-linking
4444
export KMTHINLTO=1
4545

46-
sudo chown -R jenkins:jenkins /usr/local
47-
rm -rf "$(dirname "${BASH_SOURCE[0]}")/../../../pytorch_amd/" || true
48-
python "$(dirname "${BASH_SOURCE[0]}")/../../tools/amd_build/build_pytorch_amd.py"
49-
50-
USE_ROCM=1 python setup.py install
51-
exit
46+
python tools/amd_build/build_pytorch_amd.py
47+
USE_ROCM=1 python setup.py install --user
48+
exit 0
5249
fi
5350

5451
# TODO: Don't install this here

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ include_directories(BEFORE ${PROJECT_SOURCE_DIR})
284284
# in PROJECT_SOURCE_DIR.
285285
include_directories(BEFORE ${PROJECT_BINARY_DIR})
286286

287+
include_directories(BEFORE ${PROJECT_SOURCE_DIR}/aten/src/)
288+
287289
# ---[ Old caffe protobuf
288290
if(BUILD_CAFFE2)
289291
add_subdirectory(caffe/proto)

aten/src/ATen/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ CONFIGURE_FILE(cuda/CUDAConfig.h.in "${CMAKE_CURRENT_SOURCE_DIR}/cuda/CUDAConfig
4444
# NB: If you edit these globs, you'll have to update setup.py package_data as well
4545
FILE(GLOB base_h "*.h" "detail/*.h")
4646
FILE(GLOB base_cpp "*.cpp" "detail/*.cpp")
47+
add_subdirectory(core)
4748
FILE(GLOB cuda_h "cuda/*.h" "cuda/detail/*.h" "cuda/*.cuh" "cuda/detail/*.cuh")
4849
FILE(GLOB cuda_cpp "cuda/*.cpp" "cuda/detail/*.cpp")
4950
FILE(GLOB cuda_cu "cuda/*.cu" "cuda/detail/*.cu")
@@ -62,7 +63,7 @@ FILE(GLOB native_cuda_cpp "native/cuda/*.cpp")
6263
FILE(GLOB native_mkl_cpp "native/mkl/*.cpp")
6364
FILE(GLOB native_mkldnn_cpp "native/mkldnn/*.cpp")
6465

65-
set(all_cpu_cpp ${base_cpp} ${native_cpp} ${native_sparse_cpp} ${native_mkl_cpp} ${native_mkldnn_cpp} ${generated_cpp} ${ATen_CPU_SRCS} ${cpu_kernel_cpp})
66+
set(all_cpu_cpp ${base_cpp} ${ATen_CORE_SRCS} ${native_cpp} ${native_sparse_cpp} ${native_mkl_cpp} ${native_mkldnn_cpp} ${generated_cpp} ${ATen_CPU_SRCS} ${cpu_kernel_cpp})
6667
if(AT_MKL_ENABLED)
6768
set(all_cpu_cpp ${all_cpu_cpp} ${mkl_cpp})
6869
endif()
@@ -393,7 +394,7 @@ INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake-exports/ATenConfig.cmake"
393394
DESTINATION "${AT_INSTALL_SHARE_DIR}/cmake/ATen")
394395

395396
# https://stackoverflow.com/questions/11096471/how-can-i-install-a-hierarchy-of-files-using-cmake
396-
FOREACH(HEADER ${base_h} ${cuda_h} ${cudnn_h})
397+
FOREACH(HEADER ${base_h} ${ATen_CORE_HEADERS} ${cuda_h} ${cudnn_h})
397398
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" HEADER_SUB ${HEADER})
398399
GET_FILENAME_COMPONENT(DIR ${HEADER_SUB} DIRECTORY)
399400
INSTALL(FILES ${HEADER} DESTINATION ${AT_INSTALL_INCLUDE_DIR}/ATen/${DIR})

aten/src/ATen/Context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "ATen/detail/CUDAHooksInterface.h"
1010
#include "ATen/CUDAStream.h"
1111

12+
// This is temporary
13+
#include "ATen/core/ATenCoreTest.h"
14+
1215
#include <memory>
1316
#include <mutex>
1417
#include <cstdint>

aten/src/ATen/Storage.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@
44

55
namespace at {
66

7+
Storage::Storage(at::ScalarType scalar_type, size_t size, Allocator* allocator)
8+
: storage_impl_(new StorageImpl(
9+
scalar_type,
10+
size,
11+
allocator,
12+
/* resizable */ false)) {}
13+
14+
Storage::Storage(
15+
at::ScalarType scalar_type,
16+
at::DataPtr data_ptr,
17+
size_t size,
18+
const std::function<void(void*)>& deleter)
19+
: storage_impl_(new StorageImpl(
20+
scalar_type,
21+
size,
22+
std::move(data_ptr),
23+
/* allocator */ nullptr,
24+
/* resizable */ false)) {}
25+
726
Storage::~Storage() {
827
if (!storage_impl_) {
928
return;
1029
}
11-
if (--storage_impl_->refcount == 0) {
12-
if (storage_impl_->finalizer) {
13-
(*storage_impl_->finalizer)();
14-
}
15-
storage_impl_->finalizer = nullptr;
16-
storage_impl_->data_ptr.clear();
17-
if (storage_impl_ && --storage_impl_->weakcount == 0) {
18-
delete storage_impl_;
19-
}
20-
}
30+
storage_impl_->release();
2131
}
2232

2333
} // namespace at

aten/src/ATen/Storage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ struct AT_API Storage {
88
public:
99
Storage() = delete;
1010
Storage(StorageImpl* storage_impl) : storage_impl_(storage_impl) {}
11+
Storage(at::ScalarType, size_t size, Allocator* allocator);
12+
Storage(
13+
at::ScalarType,
14+
at::DataPtr,
15+
size_t size,
16+
const std::function<void(void*)>& deleter);
1117
~Storage();
1218
// There are reasonable interpretations of these constructors, but they're to
1319
// be implemented on demand.

aten/src/ATen/StorageImpl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ StorageImpl::StorageImpl(
1212
: scalar_type(scalar_type),
1313
data_ptr(std::move(data_ptr)),
1414
size(size),
15-
refcount(1),
16-
weakcount(1), // from the strong reference
1715
resizable(resizable),
1816
allocator(allocator),
1917
finalizer(nullptr) {}

aten/src/ATen/StorageImpl.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <ATen/Allocator.h>
66
#include <ATen/ScalarType.h>
77
#include <ATen/ScalarTypeUtils.h>
8+
#include <ATen/Retainable.h>
89
#include <TH/THTypeConversion.hpp>
910
#include <atomic>
1011

@@ -39,7 +40,7 @@ namespace at {
3940

4041
struct Type;
4142

42-
struct TH_CPP_API StorageImpl {
43+
struct TH_CPP_API StorageImpl : public Retainable {
4344

4445
StorageImpl() = delete;
4546
virtual ~StorageImpl() {};
@@ -48,8 +49,6 @@ struct TH_CPP_API StorageImpl {
4849
at::ScalarType scalar_type;
4950
at::DataPtr data_ptr;
5051
ptrdiff_t size;
51-
std::atomic<int> refcount;
52-
std::atomic<int> weakcount;
5352
bool resizable;
5453
at::Allocator* allocator;
5554
std::unique_ptr<THFinalizer> finalizer;
@@ -76,6 +75,14 @@ struct TH_CPP_API StorageImpl {
7675
return static_cast<T*>(this->data_ptr.get());
7776
}
7877

78+
void release_resources() {
79+
if (finalizer) {
80+
(*finalizer)();
81+
}
82+
finalizer = nullptr;
83+
data_ptr.clear();
84+
}
85+
7986
void operator=(const StorageImpl&) = delete;
8087

8188
virtual size_t elementSize() const {
@@ -94,9 +101,6 @@ struct TH_CPP_API StorageImpl {
94101
const void* data() const {
95102
return data_ptr.get();
96103
};
97-
void retain() {
98-
++refcount;
99-
}
100104

101105
int getDevice() const {
102106
return data_ptr.device().index();

aten/src/ATen/THLongStorageView.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class THLongStorageView {
6464
storage.size = ref.size();
6565
}
6666
storage.scalar_type = at::CTypeToScalarType<th::from_type<int64_t>>::to();
67-
storage.refcount = 0;
6867
storage.set_resizable(false);
6968
}
7069
private:

aten/src/ATen/core/ATenCoreTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <ATen/core/ATenCoreTest.h>
2+
3+
namespace at {
4+
5+
static int CoreTestGlobal = 0;
6+
int CoreTest() {
7+
return CoreTestGlobal++;
8+
}
9+
10+
}

aten/src/ATen/core/ATenCoreTest.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
// TODO: Move this to something like ATenCoreGeneral.h
4+
#ifdef _WIN32
5+
# if defined(ATen_cpu_EXPORTS) || defined(caffe2_EXPORTS)
6+
# define AT_CORE_API __declspec(dllexport)
7+
# else
8+
# define AT_CORE_API __declspec(dllimport)
9+
# endif
10+
#else
11+
# define AT_CORE_API
12+
#endif
13+
14+
namespace at {
15+
16+
AT_CORE_API int CoreTest();
17+
18+
}

aten/src/ATen/core/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file solely exists to let Caffe2 Android build get at the list
2+
# of core files without having to trundle through all of ATen's CMakeLists.txt
3+
4+
FILE(GLOB ATen_CORE_HEADERS "*.h")
5+
FILE(GLOB ATen_CORE_SRCS "*.cpp")
6+
7+
# Pass to parent
8+
set(ATen_CORE_HEADERS ${ATen_CORE_HEADERS} PARENT_SCOPE)
9+
set(ATen_CORE_SRCS ${ATen_CORE_SRCS} PARENT_SCOPE)
10+
# This is a little dodgy, because it means ALL ATen headers are made
11+
# visible. Fortunately, you should just get a lot of undefined symbol
12+
# errors if you go outside core
13+
set(ATen_CORE_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../.. PARENT_SCOPE)

aten/src/ATen/core/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ATen Core
2+
---------
3+
4+
ATen Core is a minimal subset of ATen which is suitable for deployment
5+
on mobile. Binary size of files in this folder is an important constraint.

aten/src/ATen/cudnn/Descriptors.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,20 @@ struct AT_CUDA_API RNNDescriptor
319319
}
320320
};
321321

322+
#if CUDNN_VERSION >= 7000
323+
324+
struct AT_CUDA_API CTCLossDescriptor
325+
: public Descriptor<cudnnCTCLossStruct,
326+
&cudnnCreateCTCLossDescriptor,
327+
&cudnnDestroyCTCLossDescriptor>
328+
{
329+
void set(cudnnDataType_t datatype) {
330+
AT_CUDNN_CHECK(cudnnSetCTCLossDescriptor(mut_desc(), datatype));
331+
}
332+
};
333+
334+
#endif
335+
322336
union Constant
323337
{
324338
float f;

aten/src/ATen/function_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def __init__(self, reason):
290290
'Backend::${DenseBackend}, ScalarType::Long)'),
291291
'THStorage*':
292292
CodeTemplate(
293-
'checked_cast_storage<${Storage}>('
293+
'checked_cast_storage<Storage>('
294294
'&${arg_name},"${arg_name}",${arg_pos}, '
295295
'Backend::${Backend}, ScalarType::${ScalarName})'),
296296
'THGenerator*':

aten/src/ATen/gen.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ def check_all_files_written(self):
103103
TEMPLATE_PATH = options.source_path + "/templates"
104104
GENERATOR_DERIVED = CodeTemplate.from_file(
105105
TEMPLATE_PATH + "/GeneratorDerived.h")
106-
STORAGE_DERIVED_CPP = CodeTemplate.from_file(
107-
TEMPLATE_PATH + "/StorageDerived.cpp")
108-
STORAGE_DERIVED_H = CodeTemplate.from_file(TEMPLATE_PATH + "/StorageDerived.h")
109-
110106
TYPE_DERIVED_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeDerived.cpp")
111107
SPARSE_TYPE_DERIVED_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/SparseTypeDerived.cpp")
112108
TYPE_DERIVED_H = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeDerived.h")
@@ -237,7 +233,6 @@ def generate_storage_type_and_tensor(backend, density, scalar_type, declarations
237233
env['isFloatingType'] = is_floating_type
238234
env['isIntegralType'] = not is_floating_type
239235
if density == 'Dense':
240-
env['Storage'] = "{}{}Storage".format(backend, scalar_name)
241236
env['Tensor'] = "{}{}{}Tensor".format(density_tag, backend, scalar_name)
242237
env['Type'] = "{}{}{}Type".format(density_tag, backend, scalar_name)
243238
env['DenseTensor'] = "{}{}Tensor".format(backend, scalar_name)
@@ -246,7 +241,6 @@ def generate_storage_type_and_tensor(backend, density, scalar_type, declarations
246241
env['storage_tensor_headers'] = []
247242
if density != 'Sparse':
248243
env['storage_tensor_headers'] = [
249-
'#include "ATen/{}.h"'.format(env['Storage']),
250244
'#include "ATen/{}.h"'.format(env['Tensor']),
251245
'#include "ATen/{}ByteTensor.h"'.format(env['Backend']),
252246
'#include "ATen/{}IntTensor.h"'.format(env['Backend']),
@@ -322,8 +316,6 @@ def generate_storage_type_and_tensor(backend, density, scalar_type, declarations
322316

323317
if density != 'Sparse':
324318
# there are no storage or tensor types for sparse; it's all uniform
325-
fm.write(env['Storage'] + ".cpp", STORAGE_DERIVED_CPP, env)
326-
fm.write(env['Storage'] + ".h", STORAGE_DERIVED_H, env)
327319
env['TensorDenseOrSparse'] = TENSOR_DENSE_CPP.substitute(env)
328320
fm.write(env['Tensor'] + ".cpp", TENSOR_DERIVED_CPP, env)
329321
fm.write(env['Tensor'] + ".h", TENSOR_DERIVED_H, env)
@@ -379,7 +371,7 @@ def declare_outputs():
379371
for backend, density, scalar_types in iterate_types():
380372
scalar_name = scalar_types[0]
381373
full_backend = "Sparse" + backend if density == "Sparse" else backend
382-
for kind in ["Storage", "Type", "Tensor"]:
374+
for kind in ["Type", "Tensor"]:
383375
if kind != 'Type' and density == "Sparse":
384376
# No Storage or Tensor for sparse
385377
continue

aten/src/ATen/native/Linear.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ATen/ATen.h"
22
#include "ATen/NativeFunctions.h"
33
#include "ATen/WrapDimUtilsMulti.h"
4+
#include <cctype>
45

56
namespace at { namespace native {
67

@@ -136,6 +137,8 @@ Tensor einsum(std::string eqn, TensorList tensors) {
136137
} else {
137138
in_eqn = eqn;
138139
}
140+
// remove spaces for einsum compatibility (#9929)
141+
in_eqn.erase(std::remove_if(in_eqn.begin(), in_eqn.end(), isspace), in_eqn.end());
139142

140143
// next we parse in_eq (the left hand side) by iterating. It is a string of comma separated terms per index
141144
int64_t operand = 0;
@@ -212,7 +215,7 @@ Tensor einsum(std::string eqn, TensorList tensors) {
212215
num_output_dims++;
213216
}
214217
}
215-
} else { // letter (hopefully)
218+
} else if (! isspace(c)) { // letter (hopefully)
216219
AT_CHECK((ell_char_count == 0) || (ell_char_count == 3), "'.' must only occur in ellipsis in the right hand side");
217220
AT_CHECK(('a' <= c) && (c <= 'z'), "only lowercase letters a-z allowed as indices");
218221
int64_t letter_num = c-'a';

0 commit comments

Comments
 (0)