1 | /******************************************************************************* |
2 | * Copyright 2021-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_AVX512_CORE_AMX_DECONVOLUTION_HPP |
18 | #define CPU_X64_JIT_AVX512_CORE_AMX_DECONVOLUTION_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/amx_tile_configure.hpp" |
29 | #include "cpu/x64/jit_avx512_core_amx_conv_kernel.hpp" |
30 | |
31 | namespace dnnl { |
32 | namespace impl { |
33 | namespace cpu { |
34 | namespace x64 { |
35 | |
36 | struct jit_avx512_core_amx_deconvolution_fwd_t : public primitive_t { |
37 | struct pd_t : public cpu_deconvolution_fwd_pd_t { |
38 | pd_t(const deconvolution_desc_t *adesc, const primitive_attr_t *attr, |
39 | const typename pd_t::base_class *hint_fwd_pd) |
40 | : cpu_deconvolution_fwd_pd_t(adesc, attr, hint_fwd_pd), jcp_() {} |
41 | |
42 | DECLARE_COMMON_PD_T( |
43 | JIT_IMPL_NAME_HELPER("jit_deconvolution:" , jcp_.isa, "" ), |
44 | jit_avx512_core_amx_deconvolution_fwd_t); |
45 | |
46 | status_t init(engine_t *engine) { |
47 | using namespace data_type; |
48 | using smask_t = primitive_attr_t::skip_mask_t; |
49 | bool is_bf16_deconvolution = true |
50 | && utils::everyone_is(true, |
51 | utils::one_of(src_md_.data_type, bf16), |
52 | weights_md_.data_type == bf16, |
53 | utils::one_of(dst_md_.data_type, f32, bf16)) |
54 | && IMPLICATION(with_bias(), |
55 | utils::one_of(bias_md_.data_type, f32, bf16)) |
56 | && attr()->has_default_values(smask_t::post_ops); |
57 | bool is_int8_deconvolution = true |
58 | && utils::everyone_is(true, |
59 | utils::one_of(src_md_.data_type, s8, u8), |
60 | weights_md_.data_type == s8, |
61 | utils::one_of(dst_md_.data_type, f32, s32, s8, u8)) |
62 | && IMPLICATION(with_bias(), |
63 | utils::one_of(bias_md_.data_type, f32, s32, s8, u8)) |
64 | && attr()->has_default_values( |
65 | smask_t::scales_runtime | smask_t::post_ops); |
66 | |
67 | bool ok = is_fwd() |
68 | && (desc()->alg_kind & alg_kind::deconvolution_direct) |
69 | && (is_bf16_deconvolution || is_int8_deconvolution) |
70 | && !has_zero_dim_memory(); |
71 | if (!ok) return status::unimplemented; |
72 | |
73 | CHECK(jit_avx512_core_amx_bwd_data_kernel_t::init_conf(jcp_, |
74 | *desc(), dst_md_, weights_md_, src_md_, &bias_md_, attr_, |
75 | dnnl_get_max_threads())); |
76 | |
77 | auto scratchpad = scratchpad_registry().registrar(); |
78 | jit_avx512_core_amx_bwd_data_kernel_t::init_scratchpad( |
79 | scratchpad, jcp_, *attr()); |
80 | |
81 | return status::success; |
82 | } |
83 | |
84 | jit_conv_conf_t jcp_; |
85 | }; |
86 | |
87 | jit_avx512_core_amx_deconvolution_fwd_t(const pd_t *apd) |
88 | : primitive_t(apd) {} |
89 | |
90 | status_t init(engine_t *engine) override { |
91 | CHECK(safe_ptr_assign(kernel_, |
92 | new jit_avx512_core_amx_bwd_data_kernel_t( |
93 | pd()->jcp_, *pd()->attr()))); |
94 | return kernel_->create_kernel(); |
95 | } |
96 | |
97 | status_t execute(const exec_ctx_t &ctx) const override { |
98 | const auto &_pd = pd(); |
99 | if (_pd->jcp_.is_depthwise) { |
100 | assert(!"_pd->jcp_.is_depthwise not implemented" ); |
101 | return status::unimplemented; |
102 | } else |
103 | return execute_forward(ctx); |
104 | } |
105 | |
106 | private: |
107 | status_t execute_forward(const exec_ctx_t &ctx) const; |
108 | const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); } |
109 | void prepare_padded_bias(const char *&bias, |
110 | const memory_tracking::grantor_t &scratchpad) const; |
111 | |
112 | std::unique_ptr<jit_avx512_core_amx_bwd_data_kernel_t> kernel_; |
113 | }; |
114 | |
115 | } // namespace x64 |
116 | } // namespace cpu |
117 | } // namespace impl |
118 | } // namespace dnnl |
119 | |
120 | #endif |
121 | |
122 | // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s |
123 | |