1 | /******************************************************************************* |
2 | * Copyright 2022 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_X64_JIT_BRGEMM_DECONV_HPP |
18 | #define CPU_X64_JIT_BRGEMM_DECONV_HPP |
19 | |
20 | #include "common/c_types_map.hpp" |
21 | #include "common/dnnl_thread.hpp" |
22 | #include "common/memory_tracking.hpp" |
23 | #include "common/primitive.hpp" |
24 | #include "common/utils.hpp" |
25 | |
26 | #include "cpu/cpu_deconvolution_pd.hpp" |
27 | |
28 | #include "cpu/x64/jit_brgemm_1x1_conv.hpp" |
29 | #include "cpu/x64/jit_brgemm_conv.hpp" |
30 | #include "cpu/x64/jit_brgemm_conv_bwd_strided.hpp" |
31 | |
32 | namespace dnnl { |
33 | namespace impl { |
34 | namespace cpu { |
35 | namespace x64 { |
36 | |
37 | template <cpu_isa_t isa> |
38 | struct brgemm_deconvolution_fwd_t : public primitive_t { |
39 | |
40 | struct pd_t : public cpu_deconvolution_fwd_pd_t { |
41 | pd_t(const deconvolution_desc_t *adesc, const primitive_attr_t *attr, |
42 | const typename pd_t::hint_class *hint_fwd_pd) |
43 | : cpu_deconvolution_fwd_pd_t(adesc, attr, hint_fwd_pd) {} |
44 | |
45 | ~pd_t() = default; |
46 | |
47 | DECLARE_COMMON_PD_T(conv_pd_->name(), brgemm_deconvolution_fwd_t); |
48 | |
49 | status_t init(engine_t *engine); |
50 | |
51 | bool output_scales_mask_ok() const { |
52 | using namespace data_type; |
53 | const auto &mask = attr()->output_scales_.mask_; |
54 | return IMPLICATION(!utils::one_of(src_md()->data_type, s8, u8), |
55 | attr()->output_scales_.has_default_values()) |
56 | && (mask == 0 || mask == 1 << 1); |
57 | } |
58 | |
59 | bool post_ops_ok() const { |
60 | return attr()->post_ops_.find(primitive_kind::convolution) == -1; |
61 | } |
62 | |
63 | bool zero_points_ok() const { |
64 | using namespace data_type; |
65 | int mask_src = 0, mask_dst = 0; |
66 | attr()->zero_points_.get(DNNL_ARG_SRC, &mask_src); |
67 | attr()->zero_points_.get(DNNL_ARG_DST, &mask_dst); |
68 | |
69 | return IMPLICATION(!utils::one_of(src_md()->data_type, s8, u8), |
70 | attr()->zero_points_.has_default_values()) |
71 | && attr()->zero_points_.has_default_values(DNNL_ARG_WEIGHTS) |
72 | && (mask_src == 0 || mask_src == 1 << 1) |
73 | && (mask_dst == 0 || mask_dst == 1 << 1); |
74 | } |
75 | |
76 | std::shared_ptr<primitive_desc_t> conv_pd_; |
77 | bool has_strides_ = false; |
78 | }; |
79 | |
80 | brgemm_deconvolution_fwd_t(const pd_t *apd) : primitive_t(apd) {}; |
81 | |
82 | ~brgemm_deconvolution_fwd_t() = default; |
83 | |
84 | status_t init(engine_t *engine) override; |
85 | |
86 | status_t execute(const exec_ctx_t &ctx) const override; |
87 | |
88 | private: |
89 | const pd_t *pd() const { |
90 | return static_cast<const pd_t *>(primitive_t::pd().get()); |
91 | } |
92 | |
93 | std::shared_ptr<primitive_t> conv_p_; |
94 | }; |
95 | |
96 | } // namespace x64 |
97 | } // namespace cpu |
98 | } // namespace impl |
99 | } // namespace dnnl |
100 | |
101 | #endif |
102 | |
103 | // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s |
104 | |