1 /*******************************************************************************
2 * Copyright 2019 Intel Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *******************************************************************************/
18 #include <mkldnn_types.h>
21 #include "c_types_map.hpp"
22 #include "type_helpers.hpp"
25 using namespace mkldnn::impl;
26 using namespace mkldnn::impl::utils;
27 using namespace mkldnn::impl::status;
28 using namespace mkldnn::impl::prop_kind;
29 using namespace mkldnn::impl::alg_kind;
30 using namespace mkldnn::impl::types;
33 status_t binarization_desc_init(binarization_desc_t *binarization_desc, prop_kind_t prop_kind,
34 alg_kind_t alg_kind, const memory_desc_t *src_desc, const memory_desc_t *dst_desc,
35 const memory_desc_t *weights_desc) {
37 && !any_null(binarization_desc, src_desc, dst_desc, weights_desc)
38 && one_of(prop_kind, forward_training, forward_inference)
39 && one_of(alg_kind, binarization_depthwise);
40 if (!args_ok) return invalid_arguments;
42 auto bd = binarization_desc_t();
43 bd.primitive_kind = primitive_kind::binarization;
44 bd.prop_kind = prop_kind;
45 bd.alg_kind = alg_kind;
46 bd.src_desc = *src_desc;
47 bd.dst_desc = *dst_desc;
48 bd.weights_desc = *weights_desc;
50 bool consistency = true
51 && memory_desc_wrapper(bd.src_desc).nelems()
52 && memory_desc_wrapper(bd.dst_desc).nelems();
53 if (!consistency) return invalid_arguments;
55 *binarization_desc = bd;
60 status_t mkldnn_binarization_forward_desc_init(binarization_desc_t *binarization_desc,
61 prop_kind_t prop_kind, alg_kind_t alg_kind,
62 const memory_desc_t *src_desc, const memory_desc_t *dst_desc, const memory_desc_t *weights_desc) {
63 if (!one_of(prop_kind, forward_training, forward_inference))
64 return invalid_arguments;
65 return binarization_desc_init(binarization_desc, prop_kind, alg_kind, src_desc, dst_desc, weights_desc);