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_INNER_PRODUCT_UTILS_HPP |
18 | #define CPU_REF_INNER_PRODUCT_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 | namespace dnnl { |
28 | namespace impl { |
29 | namespace cpu { |
30 | |
31 | namespace ref_ip_utils { |
32 | inline dim_t get_data_off(const memory_desc_wrapper &mdw, int ndims, dim_t mb, |
33 | dim_t c, dim_t id, dim_t ih, dim_t iw) { |
34 | switch (ndims) { |
35 | case 5: return mdw.off(mb, c, id, ih, iw); |
36 | case 4: return mdw.off(mb, c, ih, iw); |
37 | case 3: return mdw.off(mb, c, iw); |
38 | case 2: return mdw.off(mb, c); |
39 | default: assert(!"unsupported ndims" ); return dim_t(0); |
40 | } |
41 | } |
42 | |
43 | inline dim_t get_weights_off(const memory_desc_wrapper &mdw, int ndims, |
44 | dim_t oc, dim_t ic, dim_t kd, dim_t kh, dim_t kw) { |
45 | switch (ndims) { |
46 | case 5: return mdw.off(oc, ic, kd, kh, kw); |
47 | case 4: return mdw.off(oc, ic, kh, kw); |
48 | case 3: return mdw.off(oc, ic, kw); |
49 | case 2: return mdw.off(oc, ic); |
50 | default: assert(!"unsupported ndims" ); return dim_t(0); |
51 | } |
52 | } |
53 | } // namespace ref_ip_utils |
54 | |
55 | } // namespace cpu |
56 | } // namespace impl |
57 | } // namespace dnnl |
58 | |
59 | #endif |
60 | |
61 | // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s |
62 | |