Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / common / binarization.cpp
1 /*******************************************************************************
2 * Copyright 2019 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_types.h>
19 #include "mkldnn.h"
20
21 #include "c_types_map.hpp"
22 #include "type_helpers.hpp"
23 #include "utils.hpp"
24
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;
31
32 namespace {
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) {
36     bool args_ok = true
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;
41
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;
49
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;
54
55     *binarization_desc = bd;
56     return success;
57 }
58 }
59
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);
66 }