forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRelu.cpp
43 lines (30 loc) · 1.04 KB
/
Relu.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
#include <ATen/ATen.h>
#include <ATen/NativeFunctions.h>
#include <ATen/Config.h>
#if !AT_MKLDNN_ENABLED()
namespace at { namespace native {
Tensor mkldnn_relu(const Tensor& input) {
AT_ERROR("mkldnn_relu: ATen not compiled with MKLDNN support");
}
Tensor& mkldnn_relu_(Tensor& input) {
AT_ERROR("mkldnn_relu_: ATen not compiled with MKLDNN support");
}
}}
#else // AT_MKLDNN_EBABLED
#include <ATen/native/mkldnn/MKLDNNCommon.h>
namespace at { namespace native {
Tensor mkldnn_relu(const Tensor& input) {
const ideep::tensor& x = itensor_from_mkldnn(input);
ideep::tensor y;
ideep::eltwise_forward::compute(
x, y, ideep::algorithm::eltwise_relu, ideep::prop_kind::forward_training, /*alpha*/ 0.0);
return new_with_itensor_mkldnn(std::move(y), input.options());
}
Tensor& mkldnn_relu_(Tensor& input) {
ideep::tensor& x = itensor_from_mkldnn(input);
ideep::eltwise_forward::compute(
x, x, ideep::algorithm::eltwise_relu, ideep::prop_kind::forward_training, /*alpha*/ 0.0);
return input;
}
}}
#endif // AT_MKLDNN_EBABLED