forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinear.cpp
48 lines (36 loc) · 1012 Bytes
/
Linear.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
#include <ATen/ATen.h>
#include <ATen/Config.h>
#include <ATen/NativeFunctions.h>
#if !AT_MKLDNN_ENABLED()
namespace at {
namespace native {
Tensor mkldnn_linear(
const Tensor& self,
const Tensor& weight,
const Tensor& bias) {
AT_ERROR("mkldnn_linear: 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_linear(
const Tensor& self,
const Tensor& weight,
const Tensor& bias) {
ideep::tensor& x = itensor_from_mkldnn(self);
ideep::tensor& w = itensor_from_mkldnn(weight);
ideep::tensor y;
if (bias.defined()) {
ideep::tensor& b = itensor_from_mkldnn(bias);
ideep::inner_product_forward::compute(x, w, b, y);
} else {
ideep::inner_product_forward::compute(x, w, y);
}
return new_with_itensor_mkldnn(std::move(y), self.options());
}
} // namespace native
} // namespace at
#endif // AT_MKLDNN_EBABLED