| 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 | #include "mkldnn.h" |
| 19 | |
| 20 | #include "c_types_map.hpp" |
| 21 | #include "engine.hpp" |
| 22 | #include "type_helpers.hpp" |
| 23 | #include "utils.hpp" |
| 24 | |
| 25 | #include "reorder_pd.hpp" |
| 26 | |
| 27 | using namespace mkldnn::impl; |
| 28 | using namespace mkldnn::impl::utils; |
| 29 | using namespace mkldnn::impl::status; |
| 30 | |
| 31 | status_t mkldnn_reorder_primitive_desc_create( |
| 32 | primitive_desc_t **reorder_pd, |
| 33 | engine_t *src_engine, const memory_desc_t *src_md, |
| 34 | engine_t *dst_engine, const memory_desc_t *dst_md, |
| 35 | const primitive_attr_t *attr) { |
| 36 | if (any_null(reorder_pd, src_engine, src_md, dst_engine, dst_md)) |
| 37 | return invalid_arguments; |
| 38 | |
| 39 | auto s_ek = src_engine->kind(); |
| 40 | auto d_ek = dst_engine->kind(); |
| 41 | if (!IMPLICATION(s_ek != d_ek, one_of(engine_kind::cpu, s_ek, d_ek))) |
| 42 | return invalid_arguments; |
| 43 | |
| 44 | auto r_pd = reinterpret_cast<reorder_pd_t **>(reorder_pd); |
| 45 | auto s_mdw = memory_desc_wrapper(*src_md); |
| 46 | auto d_mdw = memory_desc_wrapper(*dst_md); |
| 47 | |
| 48 | if (!s_mdw.consistent_with(d_mdw)) |
| 49 | return invalid_arguments; |
| 50 | |
| 51 | auto e = (s_ek != engine_kind::cpu) ? src_engine : dst_engine; |
| 52 | |
| 53 | const primitive_attr_t dummy_attr; |
| 54 | if (attr == NULL) |
| 55 | attr = &dummy_attr; |
| 56 | |
| 57 | for (auto r = e->get_reorder_implementation_list(); *r; ++r) { |
| 58 | if ((*r)(r_pd, e, attr, src_engine, src_md, dst_engine, dst_md) |
| 59 | == success) { |
| 60 | (*r_pd)->init_info(); |
| 61 | (*r_pd)->init_scratchpad_md(); |
| 62 | return success; |
| 63 | } |
| 64 | } |
| 65 | return unimplemented; |
| 66 | } |
| 67 | |
| 68 | // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s |
| 69 | |