1 | /******************************************************************************* |
2 | * Copyright 2016-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 ENGINE_HPP |
18 | #define ENGINE_HPP |
19 | |
20 | #include "mkldnn.h" |
21 | |
22 | #include "c_types_map.hpp" |
23 | #include "primitive.hpp" |
24 | #include "utils.hpp" |
25 | |
26 | /** \brief An abstraction of an execution unit with shared resources |
27 | * |
28 | * Responsibilities: |
29 | * - Provide engine specific memory allocation |
30 | * - Provide engine specific primitive_desc_t creators |
31 | */ |
32 | struct mkldnn_engine: public mkldnn::impl::c_compatible { |
33 | mkldnn_engine(mkldnn::impl::engine_kind_t kind) |
34 | : kind_(kind) |
35 | {} |
36 | virtual ~mkldnn_engine() {} |
37 | |
38 | /** get kind of the current engine */ |
39 | virtual mkldnn::impl::engine_kind_t kind() const { return kind_; } |
40 | |
41 | /** allocate memory */ |
42 | virtual mkldnn::impl::status_t memory_create( |
43 | mkldnn::impl::memory_t **memory, |
44 | const mkldnn::impl::memory_desc_t *md, |
45 | void *handle) = 0; |
46 | |
47 | /** implementation section (typedefs) */ |
48 | |
49 | // TODO: remove engine? |
50 | typedef mkldnn::impl::status_t (*reorder_primitive_desc_create_f)( |
51 | mkldnn::impl::reorder_pd_t **reorder_pd, |
52 | mkldnn::impl::engine_t *engine, |
53 | const mkldnn::impl::primitive_attr_t *attr, |
54 | mkldnn::impl::engine_t *src_engine, |
55 | const mkldnn::impl::memory_desc_t *src_md, |
56 | mkldnn::impl::engine_t *dst_engine, |
57 | const mkldnn::impl::memory_desc_t *dst_md); |
58 | |
59 | typedef mkldnn::impl::status_t (*concat_primitive_desc_create_f)( |
60 | mkldnn::impl::concat_pd_t **concat_pd, |
61 | mkldnn::impl::engine_t *engine, |
62 | const mkldnn::impl::primitive_attr_t *attr, |
63 | const mkldnn::impl::memory_desc_t *dst_md, |
64 | int n, int concat_dim, |
65 | const mkldnn::impl::memory_desc_t *src_mds); |
66 | |
67 | typedef mkldnn::impl::status_t (*sum_primitive_desc_create_f)( |
68 | mkldnn::impl::sum_pd_t **sum_pd, |
69 | mkldnn::impl::engine_t *engine, |
70 | const mkldnn::impl::primitive_attr_t *attr, |
71 | const mkldnn::impl::memory_desc_t *dst_md, |
72 | int n, const float *scales, |
73 | const mkldnn::impl::memory_desc_t *src_mds); |
74 | |
75 | typedef mkldnn::impl::status_t (*primitive_desc_create_f)( |
76 | mkldnn::impl::primitive_desc_t **, const mkldnn::impl::op_desc_t *, |
77 | const mkldnn::impl::primitive_attr_t *attr, |
78 | mkldnn::impl::engine_t *, const mkldnn::impl::primitive_desc_t *); |
79 | |
80 | /* implementation section */ |
81 | |
82 | /** return the list of reorder implementations. engine guarantees to return |
83 | * a NULL-terminated list */ |
84 | virtual const reorder_primitive_desc_create_f* |
85 | get_reorder_implementation_list() const = 0; |
86 | |
87 | /** return the list of concat implementations. engine guarantees to return |
88 | * a NULL-terminated list */ |
89 | virtual const concat_primitive_desc_create_f* |
90 | get_concat_implementation_list() const = 0; |
91 | |
92 | /** return the list of sum implementations. engine guarantees to return |
93 | * a NULL-terminated list */ |
94 | virtual const sum_primitive_desc_create_f* |
95 | get_sum_implementation_list() const = 0; |
96 | |
97 | /** return the list of implementations. engine guarantees to return a |
98 | * NULL-terminated list */ |
99 | virtual const primitive_desc_create_f* get_implementation_list() const = 0; |
100 | |
101 | protected: |
102 | mkldnn::impl::engine_kind_t kind_; |
103 | }; |
104 | |
105 | namespace mkldnn { |
106 | namespace impl { |
107 | |
108 | struct engine_factory_t: public c_compatible { |
109 | virtual size_t count() const = 0; |
110 | virtual engine_kind_t kind() const = 0; |
111 | virtual status_t engine_create(engine_t **engine, size_t index) const = 0; |
112 | }; |
113 | |
114 | } |
115 | } |
116 | |
117 | #endif |
118 | |
119 | // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s |
120 | |