1 | /******************************************************************************* |
---|---|
2 | * Copyright 2019-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_RESAMPLING_HPP |
18 | #define CPU_REF_RESAMPLING_HPP |
19 | |
20 | #include <cassert> |
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/platform.hpp" |
28 | #include "cpu/primitive_attr_postops.hpp" |
29 | |
30 | #include "cpu/cpu_resampling_pd.hpp" |
31 | |
32 | namespace dnnl { |
33 | namespace impl { |
34 | namespace cpu { |
35 | |
36 | struct ref_resampling_fwd_t : public primitive_t { |
37 | struct pd_t : public cpu_resampling_fwd_pd_t { |
38 | using cpu_resampling_fwd_pd_t::cpu_resampling_fwd_pd_t; |
39 | |
40 | DECLARE_COMMON_PD_T("ref:any", ref_resampling_fwd_t); |
41 | |
42 | status_t init(engine_t *engine) { |
43 | using namespace data_type; |
44 | using sm = primitive_attr_t::skip_mask_t; |
45 | |
46 | bool ok = is_fwd() |
47 | && platform::has_data_type_support(src_md()->data_type) |
48 | && platform::has_data_type_support(dst_md()->data_type) |
49 | && set_default_params() == status::success |
50 | && attr()->has_default_values( |
51 | sm::post_ops, dst_md()->data_type) |
52 | && attr_.set_default_formats(dst_md(0)) == status::success; |
53 | if (!ok) return status::unimplemented; |
54 | |
55 | return status::success; |
56 | } |
57 | }; |
58 | |
59 | ref_resampling_fwd_t(const pd_t *apd); |
60 | ~ref_resampling_fwd_t(); |
61 | |
62 | status_t execute(const exec_ctx_t &ctx) const override { |
63 | execute_forward(ctx); |
64 | return status::success; |
65 | } |
66 | |
67 | private: |
68 | const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); } |
69 | void execute_forward(const exec_ctx_t &ctx) const; |
70 | |
71 | const ref_post_ops_t ref_post_ops_; |
72 | }; |
73 | |
74 | struct ref_resampling_bwd_t : public primitive_t { |
75 | struct pd_t : public cpu_resampling_bwd_pd_t { |
76 | using cpu_resampling_bwd_pd_t::cpu_resampling_bwd_pd_t; |
77 | |
78 | DECLARE_COMMON_PD_T("ref:any", ref_resampling_bwd_t); |
79 | |
80 | status_t init(engine_t *engine) { |
81 | using namespace data_type; |
82 | bool ok = !is_fwd() |
83 | && platform::has_data_type_support(diff_src_md()->data_type) |
84 | && platform::has_data_type_support(diff_dst_md()->data_type) |
85 | && set_default_params() == status::success |
86 | && attr()->has_default_values(); |
87 | if (!ok) return status::unimplemented; |
88 | |
89 | return status::success; |
90 | } |
91 | }; |
92 | |
93 | ref_resampling_bwd_t(const pd_t *apd); |
94 | ~ref_resampling_bwd_t(); |
95 | |
96 | status_t execute(const exec_ctx_t &ctx) const override { |
97 | execute_backward(ctx); |
98 | return status::success; |
99 | } |
100 | |
101 | private: |
102 | const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); } |
103 | void execute_backward(const exec_ctx_t &ctx) const; |
104 | }; |
105 | |
106 | } // namespace cpu |
107 | } // namespace impl |
108 | } // namespace dnnl |
109 | |
110 | #endif |
111 |