forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnaryOps.cpp
78 lines (61 loc) · 2.25 KB
/
UnaryOps.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
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
#include <ATen/core/Tensor.h>
#include <ATen/Config.h>
#ifndef AT_PER_OPERATOR_HEADERS
#include <ATen/NativeFunctions.h>
#else
#include <ATen/ops/sigmoid_native.h> // for mkldnn_sigmoid, mkldnn_...
#include <ATen/ops/tanh_native.h> // for mkldnn_tanh, mkldnn_tanh_
#endif
#if !AT_MKLDNN_ENABLED()
namespace at {
namespace native {
Tensor mkldnn_sigmoid(const Tensor& self) {
TORCH_CHECK(false, "mkldnn_sigmoid: ATen not compiled with MKLDNN support");
}
Tensor& mkldnn_sigmoid_(Tensor& self) {
TORCH_CHECK(false, "mkldnn_sigmoid_: ATen not compiled with MKLDNN support");
}
Tensor mkldnn_tanh(const Tensor& self) {
TORCH_CHECK(false, "mkldnn_tanh: ATen not compiled with MKLDNN support");
}
Tensor& mkldnn_tanh_(Tensor& self) {
TORCH_CHECK(false, "mkldnn_tanh_: ATen not compiled with MKLDNN support");
}
} // namespace native
} // namespace at
#else // AT_MKLDNN_ENABLED
#include <ATen/native/mkldnn/MKLDNNCommon.h>
namespace at {
namespace native {
Tensor mkldnn_sigmoid(const Tensor& self) {
ideep::tensor& x = itensor_from_mkldnn(self);
ideep::tensor y;
ideep::eltwise_forward::compute(
x, y, ideep::algorithm::eltwise_logistic, ideep::prop_kind::forward);
return new_with_itensor_mkldnn(std::move(y), optTypeMetaToScalarType(self.options().dtype_opt()),
self.options().device_opt());
}
Tensor& mkldnn_sigmoid_(Tensor& self) {
ideep::tensor& x = itensor_from_mkldnn(self);
ideep::eltwise_forward::compute(
x, x, ideep::algorithm::eltwise_logistic, ideep::prop_kind::forward);
return self;
}
Tensor mkldnn_tanh(const Tensor& self) {
ideep::tensor& x = itensor_from_mkldnn(self);
ideep::tensor y;
ideep::eltwise_forward::compute(
x, y, ideep::algorithm::eltwise_tanh, ideep::prop_kind::forward);
return new_with_itensor_mkldnn(std::move(y), optTypeMetaToScalarType(self.options().dtype_opt()),
self.options().device_opt());
}
Tensor& mkldnn_tanh_(Tensor& self) {
ideep::tensor& x = itensor_from_mkldnn(self);
ideep::eltwise_forward::compute(
x, x, ideep::algorithm::eltwise_tanh, ideep::prop_kind::forward);
return self;
}
} // namespace native
} // namespace at
#endif // AT_MKLDNN_ENABLED