1 | /******************************************************************************* |
2 | * Copyright 2021 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 | #ifndef CPU_REF_CONVOLUTION_UTILS_HPP |
18 | #define CPU_REF_CONVOLUTION_UTILS_HPP |
19 | |
20 | #include <assert.h> |
21 | |
22 | #include "common/c_types_map.hpp" |
23 | #include "common/primitive.hpp" |
24 | #include "common/type_helpers.hpp" |
25 | #include "common/utils.hpp" |
26 | |
27 | #include "cpu/cpu_convolution_pd.hpp" |
28 | #include "cpu/primitive_attr_postops.hpp" |
29 | |
30 | namespace dnnl { |
31 | namespace impl { |
32 | namespace cpu { |
33 | |
34 | namespace ref_conv_utils { |
35 | inline dim_t get_data_off(const memory_desc_wrapper &mdw, int ndims, dim_t mb, |
36 | dim_t c, dim_t id, dim_t ih, dim_t iw) { |
37 | switch (ndims) { |
38 | case 5: return mdw.off(mb, c, id, ih, iw); |
39 | case 4: return mdw.off(mb, c, ih, iw); |
40 | case 3: return mdw.off(mb, c, iw); |
41 | default: assert(!"unsupported ndims" ); return dim_t(0); |
42 | } |
43 | } |
44 | |
45 | inline dim_t get_weights_off(const memory_desc_wrapper &mdw, bool with_groups, |
46 | int ndims, dim_t g, dim_t oc, dim_t ic, dim_t kd, dim_t kh, dim_t kw) { |
47 | switch (ndims) { |
48 | case 5: |
49 | return with_groups ? mdw.off(g, oc, ic, kd, kh, kw) |
50 | : mdw.off(oc, ic, kd, kh, kw); |
51 | case 4: |
52 | return with_groups ? mdw.off(g, oc, ic, kh, kw) |
53 | : mdw.off(oc, ic, kh, kw); |
54 | case 3: |
55 | return with_groups ? mdw.off(g, oc, ic, kw) : mdw.off(oc, ic, kw); |
56 | default: assert(!"unsupported ndims" ); return dim_t(0); |
57 | } |
58 | } |
59 | } // namespace ref_conv_utils |
60 | |
61 | } // namespace cpu |
62 | } // namespace impl |
63 | } // namespace dnnl |
64 | |
65 | #endif |
66 | |
67 | // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s |
68 | |