forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMKLDNNCommon.h
40 lines (30 loc) · 1.17 KB
/
MKLDNNCommon.h
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
#pragma once
#include <ATen/ATen.h>
#include <ATen/Config.h>
#if AT_MKLDNN_ENABLED()
#include <ideep.hpp>
namespace at { namespace native {
// Custom allocator using c10 CPU allocator for `ideep::tensor`
struct AllocForMKLDNN {
template<class computation_t = void>
static char* malloc(size_t size) {
auto allocator = c10::GetAllocator(c10::DeviceType::CPU);
return (char*)allocator->raw_allocate(size);
}
template<class computation_t = void>
static void free(void* p) {
auto allocator = c10::GetAllocator(c10::DeviceType::CPU);
allocator->raw_deallocate(p);
}
};
// Construct aten MKL-DNN tensor given an ideep tensor
Tensor new_with_itensor_mkldnn(ideep::tensor&& it, const TensorOptions& options);
// Construct aten MKL-DNN tensor given `sizes` for allocation
Tensor new_with_sizes_mkldnn(IntArrayRef sizes, const TensorOptions& options);
// Retrieve `ideep::tensor` from MKL-DNN tensor
ideep::tensor& itensor_from_mkldnn(const Tensor& mkldnn_tensor);
// Construct an `ideep::tensor` "view" from dense tensor, note the
// ideep::tensor will share the underlying buffer
ideep::tensor itensor_view_from_dense(const Tensor& tensor);
}}
#endif // AT_MKLDNN_ENABLED