1/*******************************************************************************
2* Copyright 2017-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_UNI_BATCH_NORMALIZATION_HPP
18#define CPU_X64_JIT_UNI_BATCH_NORMALIZATION_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#include "cpu/cpu_batch_normalization_pd.hpp"
28#include "cpu/x64/cpu_isa_traits.hpp"
29#include "cpu/x64/jit_avx512_core_bf16cvt.hpp"
30
31namespace dnnl {
32namespace impl {
33namespace cpu {
34namespace x64 {
35
36namespace bnorm_impl {
37template <cpu_isa_t isa>
38struct driver_t;
39}
40
41template <cpu_isa_t isa>
42struct jit_uni_batch_normalization_fwd_t : public primitive_t {
43 struct pd_t : public cpu_batch_normalization_fwd_pd_t {
44 pd_t(const batch_normalization_desc_t *adesc,
45 const primitive_attr_t *attr,
46 const batch_normalization_fwd_pd_t *hint_fwd_pd)
47 : cpu_batch_normalization_fwd_pd_t(adesc, attr, hint_fwd_pd) {}
48
49 DECLARE_COMMON_PD_T(
50 JIT_IMPL_NAME_HELPER("bnorm_jit:",
51 (src_md()->data_type == data_type::bf16)
52 ? (mayiuse(avx512_core_bf16)
53 ? avx512_core_bf16
54 : mayiuse(avx512_core)
55 ? bf16_emulation_t::
56 get_isa()
57 : avx2_vnni_2)
58 : (src_md()->data_type == data_type::f16)
59 ? (mayiuse(avx512_core_fp16)
60 ? avx512_core_fp16
61 : avx2_vnni_2)
62 : isa,
63 ""),
64 jit_uni_batch_normalization_fwd_t);
65
66 status_t init(engine_t *engine);
67 int nthr_; // To not exceed the limit in execute used for set up.
68 };
69
70 jit_uni_batch_normalization_fwd_t(const pd_t *apd);
71 ~jit_uni_batch_normalization_fwd_t();
72
73 status_t init(engine_t *engine) override;
74
75 status_t execute(const exec_ctx_t &ctx) const override;
76
77private:
78 const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
79
80 bnorm_impl::driver_t<isa> *bnorm_driver_;
81};
82
83template <cpu_isa_t isa>
84struct jit_uni_batch_normalization_bwd_t : public primitive_t {
85 struct pd_t : public cpu_batch_normalization_bwd_pd_t {
86 pd_t(const batch_normalization_desc_t *adesc,
87 const primitive_attr_t *attr,
88 const batch_normalization_fwd_pd_t *hint_fwd_pd)
89 : cpu_batch_normalization_bwd_pd_t(adesc, attr, hint_fwd_pd) {}
90
91 DECLARE_COMMON_PD_T(
92 JIT_IMPL_NAME_HELPER("bnorm_jit:",
93 (src_md()->data_type == data_type::bf16)
94 ? (mayiuse(avx512_core_bf16)
95 ? avx512_core_bf16
96 : bf16_emulation_t::get_isa())
97 : (src_md()->data_type == data_type::f16)
98 ? avx512_core_fp16
99 : isa,
100 ""),
101 jit_uni_batch_normalization_bwd_t);
102
103 status_t init(engine_t *engine);
104 int nthr_; // To not exceed the limit in execute used for set up.
105 };
106
107 jit_uni_batch_normalization_bwd_t(const pd_t *apd);
108 ~jit_uni_batch_normalization_bwd_t();
109
110 status_t init(engine_t *engine) override;
111
112 status_t execute(const exec_ctx_t &ctx) const override;
113
114private:
115 const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
116
117 bnorm_impl::driver_t<isa> *bnorm_driver_;
118};
119
120} // namespace x64
121} // namespace cpu
122} // namespace impl
123} // namespace dnnl
124
125#endif
126
127// vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
128