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 | #include "mkldnn.h" |
18 | #include "engine.hpp" |
19 | #include "nstl.hpp" |
20 | |
21 | #include "c_types_map.hpp" |
22 | #include "../cpu/cpu_engine.hpp" |
23 | |
24 | namespace mkldnn { |
25 | namespace impl { |
26 | |
27 | engine_factory_t *engine_factories[] = { |
28 | &cpu::engine_factory, |
29 | nullptr, |
30 | }; |
31 | |
32 | static inline engine_factory_t *get_engine_factory(engine_kind_t kind) { |
33 | for (engine_factory_t **ef = engine_factories; *ef; ef++) |
34 | if ((*ef)->kind() == kind) |
35 | return *ef; |
36 | return nullptr; |
37 | } |
38 | |
39 | } |
40 | } |
41 | |
42 | using namespace mkldnn::impl; |
43 | using namespace mkldnn::impl::status; |
44 | |
45 | size_t mkldnn_engine_get_count(engine_kind_t kind) { |
46 | engine_factory_t *ef = get_engine_factory(kind); |
47 | return ef != nullptr ? ef->count() : 0; |
48 | } |
49 | |
50 | status_t mkldnn_engine_create(engine_t **engine, |
51 | engine_kind_t kind, size_t index) { |
52 | if (engine == nullptr) |
53 | return invalid_arguments; |
54 | |
55 | engine_factory_t *ef = get_engine_factory(kind); |
56 | if (ef == nullptr || index >= ef->count()) |
57 | return invalid_arguments; |
58 | |
59 | return ef->engine_create(engine, index); |
60 | } |
61 | |
62 | status_t mkldnn_engine_get_kind(engine_t *engine, engine_kind_t *kind) { |
63 | if (engine == nullptr) |
64 | return invalid_arguments; |
65 | *kind = engine->kind(); |
66 | return success; |
67 | } |
68 | |
69 | status_t mkldnn_engine_destroy(engine_t *engine) { |
70 | /* TODO: engine->dec_ref_count(); */ |
71 | delete engine; |
72 | return success; |
73 | } |
74 | |
75 | // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s |
76 | |