forked from mstfbl/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TensorShape.cpp
88 lines (70 loc) · 2.86 KB
/
TensorShape.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <ATen/ATen.h>
#include <ATen/Config.h>
#include <ATen/InferSize.h>
#include <ATen/NativeFunctions.h>
#if !AT_MKLDNN_ENABLED()
namespace at {
namespace native {
Tensor mkldnn_view(const Tensor& self, IntArrayRef size) {
TORCH_CHECK(false, "mkldnn_reshape: ATen not compiled with MKLDNN support");
}
Tensor mkldnn_reshape(const Tensor& self, IntArrayRef size) {
TORCH_CHECK(false, "mkldnn_reshape: ATen not compiled with MKLDNN support");
}
Tensor mkldnn_clone(const Tensor& self, c10::optional<c10::MemoryFormat> optional_memory_format) {
TORCH_CHECK(false, "mkldnn_clone: ATen not compiled with MKLDNN support");
}
Tensor mkldnn_transpose(const Tensor& self, int64_t dim0, int64_t dim1) {
TORCH_CHECK(false, "mkldnn_transpose: ATen not compiled with MKLDNN support");
}
Tensor& mkldnn_transpose_(Tensor& self, int64_t dim0, int64_t dim1) {
TORCH_CHECK(false, "mkldnn_transpose_: ATen not compiled with MKLDNN support");
}
} // namespace native
} // namespace at
#else // AT_MKLDNN_EBABLED
#include <ATen/native/mkldnn/MKLDNNCommon.h>
namespace at {
namespace native {
Tensor mkldnn_view(const Tensor& self, IntArrayRef size) {
TORCH_CHECK(false,
"Currently Mkldnn tensor does not support view. Change to use reshape instead");
}
Tensor mkldnn_reshape(const Tensor& self, IntArrayRef size) {
auto inferred_size = at::infer_size(size, self.numel());
if (self.sizes() == inferred_size) {
return self;
}
const ideep::tensor& x = itensor_from_mkldnn(self);
ideep::tensor y{x};
y.reshape(inferred_size);
return new_with_itensor_mkldnn(std::move(y), optTypeMetaToScalarType(self.options().dtype_opt()),
self.options().device_opt());
}
Tensor mkldnn_clone(const Tensor& self, c10::optional<c10::MemoryFormat> optional_memory_format) {
TORCH_CHECK(
!optional_memory_format.has_value(),
"unsupported memory format option ",
optional_memory_format.value());
ideep::tensor& src = itensor_from_mkldnn(self);
ideep::tensor dst;
ideep::direct_copy::compute(src, dst);
return new_with_itensor_mkldnn(std::move(dst), optTypeMetaToScalarType(self.options().dtype_opt()),
self.options().device_opt());
}
Tensor mkldnn_transpose(const Tensor& self, int64_t dim0, int64_t dim1) {
const ideep::tensor& x = itensor_from_mkldnn(self);
ideep::tensor y;
std::vector<int> axes(x.ndims());
std::iota(axes.begin(), axes.end(), 0);
std::swap(axes[dim0], axes[dim1]);
y.transpose_from(x, axes);
return new_with_itensor_mkldnn(std::move(y), optTypeMetaToScalarType(self.options().dtype_opt()),
self.options().device_opt());
}
Tensor& mkldnn_transpose_(Tensor& self, int64_t dim0, int64_t dim1) {
TORCH_CHECK(false, "mkldnn_transpose_: in-place mkldnn operations are not supported yet");
}
} // namespace native
} // namespace at
#endif // AT_MKLDNN_EBABLED