Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / common / roi_pooling.cpp
1 /*******************************************************************************
2 * Copyright 2016 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 "utils.hpp"
23
24 using namespace mkldnn::impl;
25 using namespace mkldnn::impl::utils;
26 using namespace mkldnn::impl::status;
27 using namespace mkldnn::impl::prop_kind;
28 using namespace mkldnn::impl::alg_kind;
29
30 namespace {
31 status_t roi_pooling_desc_init(roi_pooling_desc_t *roi_pool_desc,
32         prop_kind_t prop_kind, alg_kind_t algorithm,
33         memory_desc_t *src_descs, int num_src, const memory_desc_t *dst_desc,
34         int pooled_h, int pooled_w, double spatial_scale) {
35     
36     auto pd = roi_pooling_desc_t();
37     pd.primitive_kind = primitive_kind::roi_pooling;
38     pd.prop_kind = prop_kind;
39     pd.pooled_h = pooled_h;
40     pd.pooled_w = pooled_w;
41     pd.spatial_scale = spatial_scale;
42     pd.alg_kind = algorithm;
43
44     pd.src_desc = src_descs;
45     pd.num_src = num_src;
46     pd.dst_desc = *dst_desc;
47
48     *roi_pool_desc = pd;
49     return success;
50 }
51 }
52
53 status_t mkldnn_roi_pooling_forward_desc_init(roi_pooling_desc_t *roi_pooling_desc,
54         prop_kind_t prop_kind, alg_kind_t algorithm,
55         memory_desc_t *src_desc, int num_src,
56         const memory_desc_t *dst_desc,
57         int pooled_h, int pooled_w, double spatial_scale) {
58     if (!one_of(prop_kind, forward_inference))
59         return invalid_arguments;
60
61     if (!one_of(algorithm, mkldnn_roi_pooling_max, mkldnn_roi_pooling_bilinear))
62         return invalid_arguments;
63
64     return roi_pooling_desc_init(roi_pooling_desc, prop_kind, algorithm, src_desc, num_src, dst_desc,
65         pooled_h, pooled_w, spatial_scale);
66 }
67
68 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s