1 /*******************************************************************************
2 * Copyright 2018 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 depthwise_desc_init(depthwise_desc_t *depthwise_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, const memory_desc_t *bias_desc) {
37 && !any_null(depthwise_desc, src_desc, dst_desc)
38 && one_of(prop_kind, forward_training, forward_inference)
39 && one_of(alg_kind, depthwise_scale_shift, depthwise_prelu);
40 if (!args_ok) return invalid_arguments;
42 auto dd = depthwise_desc_t();
43 dd.primitive_kind = primitive_kind::depthwise;
44 dd.prop_kind = prop_kind;
45 dd.alg_kind = alg_kind;
46 dd.src_desc = *src_desc;
47 dd.dst_desc = *dst_desc;
48 dd.weights_desc = *weights_desc;
50 const bool with_bias = bias_desc && bias_desc->format != memory_format::undef;
51 dd.bias_desc = with_bias ? *bias_desc : zero_md();
53 bool consistency = true
54 && memory_desc_wrapper(dd.src_desc).nelems()
55 && memory_desc_wrapper(dd.dst_desc).nelems();
56 if (!consistency) return invalid_arguments;
63 status_t mkldnn_depthwise_forward_desc_init(depthwise_desc_t *depthwise_desc,
64 prop_kind_t prop_kind, alg_kind_t alg_kind,
65 const memory_desc_t *src_desc, const memory_desc_t *dst_desc, const memory_desc_t *weights_desc,
66 const memory_desc_t *bias_desc) {
67 if (!one_of(prop_kind, forward_training, forward_inference))
68 return invalid_arguments;
69 return depthwise_desc_init(depthwise_desc, prop_kind, alg_kind, src_desc, dst_desc,
70 weights_desc, bias_desc);
73 status_t mkldnn_depthwise_forward_desc_init(depthwise_desc_t *depthwise_desc,
74 prop_kind_t prop_kind, alg_kind_t alg_kind,
75 const memory_desc_t *src_desc, const memory_desc_t *dst_desc, const memory_desc_t *weights_desc) {
76 if (!one_of(prop_kind, forward_training, forward_inference))
77 return invalid_arguments;
78 return depthwise_desc_init(depthwise_desc, prop_kind, alg_kind, src_desc, dst_desc,
79 weights_desc, nullptr);