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
19#include "c_types_map.hpp"
20#include "nstl.hpp"
21#include "primitive_desc.hpp"
22
23using namespace mkldnn::impl;
24using namespace mkldnn::impl::status;
25
26status_t primitive_desc_t::query(query_t what, int idx, void *result) const {
27 auto safe_ret_md = [&](const memory_desc_t *_) {
28 if (_ == nullptr) return not_required;
29 *(const memory_desc_t **)result = _;
30 return success;
31 };
32
33 switch (what) {
34 case query::engine: *(engine_t**)result = engine(); break;
35 case query::primitive_kind: *(primitive_kind_t*)result = kind(); break;
36
37 case query::scratchpad_engine:
38 *(engine_t**)result = scratchpad_engine(); break;
39
40 case query::memory_consumption_s64:
41 *(dim_t *)result = scratchpad_size(scratchpad_mode::library); break;
42
43 case query::op_d:
44 if (idx != 0 || op_desc() == nullptr) return invalid_arguments;
45 *(const_c_op_desc_t *)result
46 = static_cast<const_c_op_desc_t>(op_desc()); break;
47
48 case query::src_md: return safe_ret_md(src_md(idx));
49 case query::diff_src_md: return safe_ret_md(diff_src_md(idx));
50 case query::dst_md: return safe_ret_md(dst_md(idx));
51 case query::diff_dst_md: return safe_ret_md(diff_dst_md(idx));
52 case query::weights_md: return safe_ret_md(weights_md(idx));
53 case query::diff_weights_md: return safe_ret_md(diff_weights_md(idx));
54 case query::workspace_md:
55 if (idx != 0) return status::invalid_arguments;
56 return safe_ret_md(workspace_md(idx));
57 case query::scratchpad_md:
58 if (idx != 0) return status::invalid_arguments;
59 return safe_ret_md(scratchpad_md(idx));
60
61 case query::num_of_inputs_s32: *(int*)result = n_inputs(); break;
62 case query::num_of_outputs_s32: *(int*)result = n_outputs(); break;
63
64 case query::impl_info_str: *(const char **)result = name(); break;
65
66 default: return unimplemented;
67 }
68 return success;
69}
70
71status_t mkldnn_primitive_desc_get_attr(const primitive_desc_t *primitive_desc,
72 const primitive_attr_t **attr) {
73 if (utils::any_null(primitive_desc, attr))
74 return invalid_arguments;
75
76 *attr = primitive_desc->attr();
77 return success;
78}
79