1 /*******************************************************************************
2 * Copyright 2018 Intel Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *******************************************************************************/
17 #ifndef CPU_JIT_AVX512_CORE_FP32_WINO_CONV_2x3_HPP
18 #define CPU_JIT_AVX512_CORE_FP32_WINO_CONV_2x3_HPP
22 #include "c_types_map.hpp"
23 #include "cpu_convolution_pd.hpp"
24 #include "cpu_engine.hpp"
25 #include "mkldnn_thread.hpp"
26 #include "type_helpers.hpp"
29 #include "jit_primitive_conf.hpp"
30 #include "jit_generator.hpp"
36 struct jit_avx512_core_fp32_wino_conv_2x3_fwd_ker_t;
37 struct jit_avx512_core_fp32_wino_conv_2x3_src_trans_t;
38 struct jit_avx512_core_fp32_wino_conv_2x3_dst_trans_t;
40 struct jit_avx512_core_fp32_wino_conv_2x3_fwd_t : public cpu_primitive_t {
41 struct pd_t : public cpu_convolution_fwd_pd_t {
42 pd_t(engine_t *engine, const convolution_desc_t *adesc,
43 const primitive_attr_t *attr,
44 const typename pd_t::base_class *hint_fwd_pd)
45 : cpu_convolution_fwd_pd_t(engine, adesc, attr, hint_fwd_pd)
49 JIT_IMPL_NAME_HELPER("jit_fp32_wino_2x3:", avx512_core, ""),
50 jit_avx512_core_fp32_wino_conv_2x3_fwd_t);
52 virtual status_t init() override {
53 using namespace prop_kind;
54 using namespace memory_format;
55 assert(this->engine()->kind() == engine_kind::cpu);
56 bool ok = true && this->set_default_params() == status::success
57 && utils::one_of(this->desc()->prop_kind, forward_inference)
58 && utils::one_of(this->desc()->alg_kind,
59 alg_kind::convolution_auto,
60 alg_kind::convolution_winograd)
61 && this->desc()->src_desc.data_type == data_type::f32
62 && this->desc()->dst_desc.data_type == data_type::f32
63 && this->desc()->weights_desc.data_type == data_type::f32
64 && IMPLICATION(this->with_bias(),
65 utils::one_of(this->desc()->bias_desc.data_type,
68 return status::unimplemented;
70 memory_desc_t expect_wei_md = *(this->weights_pd_.desc());
71 status_t jit_conf_result = jit_conf(expect_wei_md);
72 if (jit_conf_result != success) return jit_conf_result;
74 cpu_memory_t::pd_t new_weights_pd(this->engine_, &expect_wei_md);
75 if (this->weights_pd_.desc()->format == any)
76 this->weights_pd_ = new_weights_pd;
77 if (!this->weights_pd_.is_equal(&new_weights_pd))
82 if (this->desc()->alg_kind == alg_kind::convolution_auto)
83 CHECK(this->set_alg_kind(alg_kind::convolution_winograd));
88 jit_conv_conf_2x3_wino_t jcp_;
91 status_t jit_conf(memory_desc_t& expect_wei_md);
93 void init_scratchpad() {
94 using namespace memory_tracking::names;
96 auto scratchpad = this->scratchpad_registry().registrar();
98 int wino_size_offset = (jcp_.yb / 2) * (jcp_.xb / 2) + jcp_.xb;
100 size_t V_sz = (size_t)jcp_.ic * 16 * wino_size_offset * jcp_.nthr;
101 scratchpad.book(key_wino_V, sizeof(float) * V_sz, PAGE_4K);
103 size_t M_sz = (size_t)jcp_.oc * 16 * wino_size_offset * jcp_.nthr;
104 scratchpad.book(key_wino_M, sizeof(float) * M_sz, PAGE_4K);
106 if (wants_padded_bias()) {
107 assert(jcp_.ngroups == 1);
108 scratchpad.book(key_conv_padded_bias, sizeof(float) * jcp_.oc);
112 virtual status_t set_default_params() override {
113 using namespace memory_format;
114 if (this->src_pd_.desc()->format == any)
115 CHECK(this->src_pd_.set_format(nChw16c));
116 if (this->dst_pd_.desc()->format == any)
117 CHECK(this->dst_pd_.set_format(nChw16c));
118 if (this->bias_pd_.desc()->format == any)
119 CHECK(this->bias_pd_.set_format(x));
120 return status::success;
124 jit_avx512_core_fp32_wino_conv_2x3_fwd_t(const pd_t *apd,
125 const input_vector &inputs, const output_vector &outputs);
127 ~jit_avx512_core_fp32_wino_conv_2x3_fwd_t();
129 virtual void execute(event_t *e) const {
131 e->set_state(event_t::ready);
135 void execute_forward() const;
136 void execute_forward_small_mb() const;
137 void execute_forward_mbN() const;
138 const pd_t *pd() const { return (const pd_t *)primitive_t::pd(); }
140 jit_avx512_core_fp32_wino_conv_2x3_fwd_ker_t *kernel_;
141 jit_avx512_core_fp32_wino_conv_2x3_src_trans_t *src_trans_;
142 jit_avx512_core_fp32_wino_conv_2x3_dst_trans_t *dst_trans_;