1 | /******************************************************************************* |
2 | * Copyright 2018 Intel Corporation |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | *******************************************************************************/ |
16 | |
17 | #ifndef MEMORY_HPP |
18 | #define MEMORY_HPP |
19 | |
20 | #include <assert.h> |
21 | |
22 | #include "mkldnn.h" |
23 | |
24 | #include "c_types_map.hpp" |
25 | #include "nstl.hpp" |
26 | |
27 | struct mkldnn_memory: public mkldnn::impl::c_compatible { |
28 | mkldnn_memory(mkldnn::impl::engine_t *engine, |
29 | const mkldnn::impl::memory_desc_t *md) |
30 | : engine_(engine), md_(*md) {} |
31 | virtual ~mkldnn_memory() {} |
32 | |
33 | /** allocates/initializes memory */ |
34 | virtual mkldnn::impl::status_t init() = 0; |
35 | |
36 | /** returns memory's engine */ |
37 | mkldnn::impl::engine_t *engine() const { return engine_; } |
38 | /** returns memory's description */ |
39 | const mkldnn::impl::memory_desc_t *md() const { return &md_; } |
40 | |
41 | /** returns data handle */ |
42 | virtual mkldnn::impl::status_t get_data_handle(void **handle) const = 0; |
43 | |
44 | /** sets data handle */ |
45 | virtual mkldnn::impl::status_t set_data_handle(void *handle) = 0; |
46 | |
47 | /** zeros padding */ |
48 | virtual mkldnn::impl::status_t zero_pad() const |
49 | { return mkldnn::impl::status::success; } |
50 | |
51 | protected: |
52 | mkldnn::impl::engine_t *engine_; |
53 | const mkldnn::impl::memory_desc_t md_; |
54 | |
55 | private: |
56 | mkldnn_memory() = delete; |
57 | mkldnn_memory(const mkldnn_memory &) = delete; |
58 | mkldnn_memory(mkldnn_memory &&) = delete; |
59 | mkldnn_memory &operator=(const mkldnn_memory &) = delete; |
60 | mkldnn_memory &operator=(mkldnn_memory &&) = delete; |
61 | }; |
62 | |
63 | #endif |
64 | |