Skip to content

Commit ac85abc

Browse files
authored
Merge pull request #251 from iotamudelta/ifu
Integrate from upstream
2 parents 337bb29 + 3d39130 commit ac85abc

File tree

186 files changed

+3692
-2211
lines changed

Some content is hidden

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

186 files changed

+3692
-2211
lines changed

.jenkins/pytorch/win-build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ if "%REBUILD%"=="" ( call conda install -y -q numpy cffi pyyaml boto3 )
9191
:: Install ninja
9292
if "%REBUILD%"=="" ( pip install ninja )
9393
94+
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x64
9495
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x86_amd64
9596
9697
git submodule update --init --recursive

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
55
# ---[ Project and semantic versioning.
66
project(Caffe2 CXX C)
77

8+
set(CMAKE_INSTALL_MESSAGE NEVER)
9+
810
set(CMAKE_CXX_STANDARD 11)
911
if (NOT MSVC)
1012
set(CMAKE_C_STANDARD 11)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ python setup.py install
210210

211211
### Docker image
212212

213-
Dockerfile is supplied to build images with cuda support and cudnn v7. You can pass -e PYTHON_VERSION=x.y flag to specificy which python to be used by Miniconda, or leave it unset to use the default. Build as usual
213+
Dockerfile is supplied to build images with cuda support and cudnn v7. You can pass `-e PYTHON_VERSION=x.y` flag to specificy which python to be used by Miniconda, or leave it unset to use the default. Build as usual
214214
```
215215
docker build -t pytorch -f docker/pytorch/Dockerfile .
216216
```

aten/src/ATen/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ CONFIGURE_FILE(Config.h.in "${CMAKE_CURRENT_SOURCE_DIR}/Config.h")
2020
CONFIGURE_FILE(cuda/CUDAConfig.h.in "${CMAKE_CURRENT_SOURCE_DIR}/cuda/CUDAConfig.h")
2121

2222
# NB: If you edit these globs, you'll have to update setup.py package_data as well
23-
FILE(GLOB base_h "*.h" "detail/*.h")
24-
FILE(GLOB base_cpp "*.cpp" "detail/*.cpp")
23+
FILE(GLOB base_h "*.h" "detail/*.h" "cpu/*.h")
24+
FILE(GLOB base_cpp "*.cpp" "detail/*.cpp" "cpu/*.cpp")
2525
add_subdirectory(core)
2626
FILE(GLOB cuda_h "cuda/*.h" "cuda/detail/*.h" "cuda/*.cuh" "cuda/detail/*.cuh")
2727
FILE(GLOB cuda_cpp "cuda/*.cpp" "cuda/detail/*.cpp")

aten/src/ATen/Context.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
#include "ATen/CPUGenerator.h"
1414
#include "ATen/RegisterCPU.h"
1515
#include "ATen/Tensor.h"
16+
#include <ATen/cpu/FlushDenormal.h>
1617

1718
#include "TH/TH.h" // for USE_LAPACK
1819

19-
#ifdef USE_SSE3
20-
#include <pmmintrin.h>
21-
#endif
22-
2320
namespace at {
2421

2522
static inline void errorHandler(const char * msg, void * data) {
@@ -94,18 +91,7 @@ bool Context::hasLAPACK() const {
9491
}
9592

9693
bool Context::setFlushDenormal(bool on) {
97-
#ifdef USE_SSE3
98-
// Setting flush-to-zero (FTZ) flag
99-
_MM_SET_FLUSH_ZERO_MODE(on ? _MM_FLUSH_ZERO_ON
100-
: _MM_FLUSH_ZERO_OFF);
101-
102-
// Setting denormals-are-zero (DAZ) flag
103-
_MM_SET_DENORMALS_ZERO_MODE(on ? _MM_DENORMALS_ZERO_ON
104-
: _MM_DENORMALS_ZERO_OFF);
105-
return true;
106-
#else
107-
return false;
108-
#endif
94+
return at::cpu::set_flush_denormal(on);
10995
}
11096

11197
TypeExtendedInterface& getType(TensorOptions options) {

aten/src/ATen/InitialTensorOptions.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <ATen/core/TensorOptions.h>
4+
5+
namespace at {
6+
7+
// Represents the initial TensorOptions, before the "defaults" are ever changed.
8+
// This is designed to be used in library code, where the explicit devices, dtypes, etc. are known.
9+
// NOTE: this is not a stable API.
10+
inline TensorOptions initialTensorOptions() {
11+
return TensorOptions(kCPU).dtype(kFloat).layout(kStrided)
12+
.requires_grad(false).is_variable(false);
13+
}
14+
15+
}

aten/src/ATen/SparseTensorImpl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#include <ATen/ATen.h>
22
#include <ATen/SparseTensorImpl.h>
3+
#include <ATen/InitialTensorOptions.h>
34

45
namespace at {
56

67
namespace {
7-
Backend sparseTensorIdToDenseBackend(TensorTypeId type_id) {
8+
DeviceType sparseTensorIdToDeviceType(TensorTypeId type_id) {
89
if (type_id == SparseCPUTensorId()) {
9-
return Backend::CPU;
10+
return kCPU;
1011
} else if (type_id == SparseCUDATensorId()) {
11-
return Backend::CUDA;
12+
return kCUDA;
1213
} else {
1314
AT_ERROR("Cannot construct SparseTensor with non-sparse tensor type ID ", type_id);
1415
}
@@ -33,8 +34,8 @@ SparseTensorImpl::SparseTensorImpl(at::TensorTypeId type_id, const caffe2::TypeM
3334
, size_{0}
3435
, sparseDims_(1)
3536
, denseDims_(0)
36-
, indices_(globalContext().getNonVariableTypeOpt(sparseTensorIdToDenseBackend(type_id), ScalarType::Long)->tensor({1, 0}))
37-
, values_(globalContext().getNonVariableTypeOpt(sparseTensorIdToDenseBackend(type_id), dataTypeToScalarType(data_type.id()))->tensor()) {}
37+
, indices_(at::empty({1, 0}, at::initialTensorOptions().device(sparseTensorIdToDeviceType(type_id)).dtype(ScalarType::Long)))
38+
, values_(at::empty({0}, at::initialTensorOptions().device(sparseTensorIdToDeviceType(type_id)).dtype(dataTypeToScalarType(data_type.id())))) {}
3839

3940
IntList SparseTensorImpl::sizes() const {
4041
return size_;

aten/src/ATen/core/ArrayRef.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ class ArrayRef final {
108108
return Data + Length;
109109
}
110110

111+
// These are actually the same as iterator, since ArrayRef only
112+
// gives you const iterators.
113+
constexpr const_iterator cbegin() const {
114+
return Data;
115+
}
116+
constexpr const_iterator cend() const {
117+
return Data + Length;
118+
}
119+
111120
constexpr reverse_iterator rbegin() const {
112121
return reverse_iterator(end());
113122
}
@@ -209,4 +218,53 @@ class ArrayRef final {
209218
/// @}
210219
};
211220

221+
template <typename T>
222+
std::ostream& operator<<(std::ostream & out, ArrayRef<T> list) {
223+
int i = 0;
224+
out << "[";
225+
for(auto e : list) {
226+
if (i++ > 0)
227+
out << ", ";
228+
out << e;
229+
}
230+
out << "]";
231+
return out;
232+
}
233+
234+
// WARNING: Template instantiation will NOT be willing to do an implicit
235+
// conversions to get you to an at::ArrayRef, which is why we need so
236+
// many overloads.
237+
238+
template <typename T>
239+
bool operator==(at::ArrayRef<T> a1, at::ArrayRef<T> a2) {
240+
return a1.equals(a2);
241+
}
242+
243+
template <typename T>
244+
bool operator!=(at::ArrayRef<T> a1, at::ArrayRef<T> a2) {
245+
return !a1.equals(a2);
246+
}
247+
248+
template <typename T>
249+
bool operator==(std::vector<T> a1, at::ArrayRef<T> a2) {
250+
return at::ArrayRef<T>(a1).equals(a2);
251+
}
252+
253+
template <typename T>
254+
bool operator!=(std::vector<T> a1, at::ArrayRef<T> a2) {
255+
return !at::ArrayRef<T>(a1).equals(a2);
256+
}
257+
258+
template <typename T>
259+
bool operator==(at::ArrayRef<T> a1, std::vector<T> a2) {
260+
return a1.equals(at::ArrayRef<T>(a2));
261+
}
262+
263+
template <typename T>
264+
bool operator!=(at::ArrayRef<T> a1, std::vector<T> a2) {
265+
return !a1.equals(at::ArrayRef<T>(a2));
266+
}
267+
268+
using IntList = ArrayRef<int64_t>;
269+
212270
} // namespace at

aten/src/ATen/core/Device.cpp

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22
#include <ATen/core/Error.h>
33
#include <ATen/core/Macros.h>
44

5+
#include <algorithm>
6+
#include <array>
57
#include <exception>
68
#include <ostream>
79
#include <string>
810
#include <tuple>
11+
#include <vector>
912

1013
namespace at {
1114
namespace {
12-
std::pair<Device::Type, size_t> parse_type(const std::string& device_string) {
13-
auto position = device_string.find("cpu");
14-
if (position != std::string::npos) {
15-
return {Device::Type::CPU, 3};
15+
DeviceType parse_type(const std::string& device_string) {
16+
static const std::array<std::pair<std::string, DeviceType>, 7> types = {{
17+
{"cpu", DeviceType::CPU},
18+
{"cuda", DeviceType::CUDA},
19+
{"mkldnn", DeviceType::MKLDNN},
20+
{"opengl", DeviceType::OPENGL},
21+
{"opencl", DeviceType::OPENCL},
22+
{"ideep", DeviceType::IDEEP},
23+
{"hip", DeviceType::HIP},
24+
}};
25+
auto device = std::find_if(
26+
types.begin(),
27+
types.end(),
28+
[device_string](const std::pair<std::string, DeviceType>& p) {
29+
return p.first == device_string;
30+
});
31+
if (device != types.end()) {
32+
return device->second;
1633
}
17-
position = device_string.find("cuda");
18-
if (position != std::string::npos) {
19-
return {Device::Type::CUDA, 4};
20-
}
21-
AT_ERROR("Expected 'cpu' or 'cuda' device type at start of device string");
34+
AT_ERROR(
35+
"Expected one of cpu, cuda, mkldnn, opengl, opencl, ideep, or hip device type at start of device string");
2236
}
2337
} // namespace
2438

@@ -47,28 +61,23 @@ std::pair<Device::Type, size_t> parse_type(const std::string& device_string) {
4761
// }
4862
Device::Device(const std::string& device_string) : Device(Type::CPU) {
4963
AT_CHECK(!device_string.empty(), "Device string must not be empty");
50-
51-
size_t position;
52-
std::tie(type_, position) = parse_type(device_string);
53-
54-
// e.g. 'cuda', 'cpu'.
55-
if (position == device_string.size()) {
64+
int index = device_string.find(":");
65+
if (index == std::string::npos) {
66+
type_ = parse_type(device_string);
5667
return;
68+
} else {
69+
std::string s;
70+
s = device_string.substr(0, index);
71+
AT_CHECK(!s.empty(), "Device string must not be empty");
72+
type_ = parse_type(s);
5773
}
58-
59-
AT_CHECK(
60-
device_string[position] == ':',
61-
"Expected ':' to separate device type from index in device string");
62-
// Skip the colon.
63-
position += 1;
64-
65-
const auto index_string = device_string.substr(position);
74+
std::string device_index = device_string.substr(index + 1);
6675
try {
67-
index_ = at::stoi(index_string);
76+
index_ = at::stoi(device_index);
6877
} catch (const std::exception&) {
6978
AT_ERROR(
7079
"Could not parse device index '",
71-
index_string,
80+
device_index,
7281
"' in device string '",
7382
device_string,
7483
"'");

aten/src/ATen/core/Formatting.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ struct FormatGuard {
2828
std::ios saved;
2929
};
3030

31-
std::ostream& operator<<(std::ostream & out, IntList list) {
32-
int i = 0;
33-
out << "[";
34-
for(auto e : list) {
35-
if (i++ > 0)
36-
out << ", ";
37-
out << e;
38-
}
39-
out << "]";
40-
return out;
41-
}
42-
4331
std::ostream& operator<<(std::ostream & out, Backend b) {
4432
return out << toString(b);
4533
}

aten/src/ATen/core/Formatting.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace at {
1010

11-
CAFFE2_API std::ostream& operator<<(std::ostream& out, IntList list);
1211
CAFFE2_API std::ostream& operator<<(std::ostream& out, Backend b);
1312
CAFFE2_API std::ostream& operator<<(std::ostream& out, const Type& t);
1413
CAFFE2_API std::ostream& print(

aten/src/ATen/core/ScalarType.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ enum class ScalarType : int8_t {
6969
};
7070

7171
static inline DataType scalarTypeToDataType(ScalarType scalar_type) {
72-
#define DEFINE_CASE(ctype,name,_) \
73-
case ScalarType:: name : return caffe2::TypeMeta::Id<ctype>();
72+
#define DEFINE_CASE(ctype, name, _) \
73+
case ScalarType::name: \
74+
return caffe2::TypeIdentifier::Get<ctype>();
7475

7576
switch(scalar_type) {
7677
AT_FORALL_SCALAR_TYPES_WITH_COMPLEX(DEFINE_CASE)
@@ -93,9 +94,9 @@ static inline caffe2::TypeMeta scalarTypeToTypeMeta(ScalarType scalar_type) {
9394
}
9495

9596
static inline ScalarType dataTypeToScalarType(DataType dtype) {
96-
#define DEFINE_IF(ctype,name,_) \
97-
if (dtype == caffe2::TypeMeta::Id<ctype>()) { \
98-
return ScalarType:: name; \
97+
#define DEFINE_IF(ctype, name, _) \
98+
if (dtype == caffe2::TypeIdentifier::Get<ctype>()) { \
99+
return ScalarType::name; \
99100
}
100101
AT_FORALL_SCALAR_TYPES_WITH_COMPLEX(DEFINE_IF)
101102
#undef DEFINE_IF
@@ -189,7 +190,6 @@ static inline ScalarType promoteTypes(ScalarType a, ScalarType b) {
189190
}
190191

191192
class Tensor;
192-
typedef ArrayRef<int64_t> IntList;
193193
typedef ArrayRef<Tensor> TensorList;
194194

195195
inline std::ostream& operator<<(

aten/src/ATen/core/SmallVector.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,19 @@ inline size_t capacity_in_bytes(const SmallVector<T, N>& X) {
10151015
return X.capacity_in_bytes();
10161016
}
10171017

1018+
template <typename T, unsigned N>
1019+
std::ostream& operator<<(std::ostream & out, const SmallVector<T, N>& list) {
1020+
int i = 0;
1021+
out << "[";
1022+
for(auto e : list) {
1023+
if (i++ > 0)
1024+
out << ", ";
1025+
out << e;
1026+
}
1027+
out << "]";
1028+
return out;
1029+
}
1030+
10181031
} // end namespace at
10191032

10201033
namespace std {

aten/src/ATen/core/Tensor.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,17 @@ struct CAFFE2_API WeakTensor {
677677
private:
678678
c10::weak_intrusive_ptr<TensorImpl, UndefinedTensorImpl> weak_impl_;
679679
};
680+
681+
namespace detail {
682+
// Helper creator for Tensor clas which doesn't requires the users to pass
683+
// in an intrusive_ptr instead it just converts the argument passed to
684+
// requested intrusive_ptr type.
685+
template <typename T, typename... Args>
686+
Tensor make_tensor(Args&&... args) {
687+
return Tensor(c10::make_intrusive<T>(std::forward<Args>(args)...));
688+
}
689+
} // namespace detail
690+
680691
} // namespace at
681692

682693
#include "ATen/core/TensorMethods.h"

0 commit comments

Comments
 (0)