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 <assert.h> |
18 | |
19 | #include "mkldnn.h" |
20 | |
21 | #include "c_types_map.hpp" |
22 | #include "engine.hpp" |
23 | #include "primitive_desc.hpp" |
24 | #include "type_helpers.hpp" |
25 | #include "primitive_iterator.hpp" |
26 | |
27 | using namespace mkldnn::impl; |
28 | using namespace mkldnn::impl::status; |
29 | |
30 | status_t mkldnn_primitive_desc_iterator_create( |
31 | primitive_desc_iterator_t **iterator, const_c_op_desc_t c_op_desc, |
32 | const primitive_attr_t *attr, engine_t *engine, |
33 | const primitive_desc_t *hint_fwd_pd) { |
34 | const op_desc_t *op_desc = (const op_desc_t *)c_op_desc; |
35 | |
36 | auto it = new primitive_desc_iterator_t(engine, op_desc, attr, hint_fwd_pd); |
37 | if (it == nullptr) return out_of_memory; |
38 | |
39 | ++(*it); |
40 | if (*it == it->end()) { |
41 | delete it; |
42 | return unimplemented; |
43 | } |
44 | |
45 | *iterator = it; |
46 | return success; |
47 | } |
48 | |
49 | status_t mkldnn_primitive_desc_iterator_next( |
50 | primitive_desc_iterator_t *iterator) { |
51 | if (iterator == nullptr) return invalid_arguments; |
52 | ++(*iterator); |
53 | return *iterator == iterator->end() ? iterator_ends : success; |
54 | } |
55 | |
56 | primitive_desc_t *mkldnn_primitive_desc_iterator_fetch( |
57 | const primitive_desc_iterator_t *iterator) { |
58 | if (iterator == nullptr) return nullptr; |
59 | return *(*iterator); |
60 | } |
61 | |
62 | status_t mkldnn_primitive_desc_clone(primitive_desc_t **primitive_desc, |
63 | const primitive_desc_t *existing_primitive_desc) { |
64 | if (utils::any_null(primitive_desc, existing_primitive_desc)) |
65 | return invalid_arguments; |
66 | return safe_ptr_assign<primitive_desc_t>(*primitive_desc, |
67 | existing_primitive_desc->clone()); |
68 | } |
69 | |
70 | status_t mkldnn_primitive_desc_iterator_destroy( |
71 | primitive_desc_iterator_t *iterator) { |
72 | if (iterator != nullptr) |
73 | delete iterator; |
74 | return success; |
75 | } |
76 | |
77 | status_t mkldnn_primitive_desc_create(primitive_desc_t **primitive_desc, |
78 | const_c_op_desc_t c_op_desc, const primitive_attr_t *attr, |
79 | engine_t *engine, const primitive_desc_t *hint_fwd_pd) { |
80 | const op_desc_t *op_desc = (const op_desc_t *)c_op_desc; |
81 | |
82 | mkldnn_primitive_desc_iterator it(engine, op_desc, attr, hint_fwd_pd); |
83 | ++it; |
84 | if (it == it.end()) return unimplemented; |
85 | |
86 | return safe_ptr_assign<primitive_desc_t>(*primitive_desc, *it); |
87 | } |
88 | |
89 | // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s |
90 | |