1/*******************************************************************************
2* Copyright 2016-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_X64_LRN_JIT_UNI_LRN_HPP
18#define CPU_X64_LRN_JIT_UNI_LRN_HPP
19
20#include <memory>
21#include "common/c_types_map.hpp"
22#include "common/primitive.hpp"
23#include "common/type_helpers.hpp"
24#include "common/utils.hpp"
25
26#include "cpu/cpu_lrn_pd.hpp"
27#include "cpu/x64/cpu_isa_traits.hpp"
28#include "cpu/x64/lrn/jit_uni_lrn_kernel.hpp"
29
30namespace dnnl {
31namespace impl {
32namespace cpu {
33namespace x64 {
34
35template <cpu_isa_t isa, data_type_t d_type>
36struct jit_uni_lrn_fwd_t : public primitive_t {
37 struct pd_t : public cpu_lrn_fwd_pd_t {
38 using cpu_lrn_fwd_pd_t::cpu_lrn_fwd_pd_t;
39
40 DECLARE_COMMON_PD_T(
41 JIT_IMPL_NAME_HELPER("jit:", isa, ""), jit_uni_lrn_fwd_t);
42
43 status_t init(engine_t *engine);
44
45 format_tag_t dat_tag_;
46 };
47
48 jit_uni_lrn_fwd_t(const pd_t *apd);
49 ~jit_uni_lrn_fwd_t();
50
51 using data_t = typename prec_traits<d_type>::type;
52
53 status_t init(engine_t *engine) override;
54
55 status_t execute(const exec_ctx_t &ctx) const override {
56 return execute_forward(ctx);
57 }
58
59private:
60 status_t execute_forward(const exec_ctx_t &ctx) const;
61 const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
62
63 std::unique_ptr<jit_uni_lrn_fwd_kernel_t<isa, d_type>> ker_, ker_first_,
64 ker_last_;
65 static constexpr int VECTOR_LENGTH
66 = jit_uni_lrn_fwd_kernel_t<isa, d_type>::VECTOR_LENGTH;
67};
68
69template <cpu_isa_t isa, data_type_t d_type>
70struct jit_uni_lrn_bwd_t : public primitive_t {
71 struct pd_t : public cpu_lrn_bwd_pd_t {
72 using cpu_lrn_bwd_pd_t::cpu_lrn_bwd_pd_t;
73
74 DECLARE_COMMON_PD_T(
75 JIT_IMPL_NAME_HELPER("jit:", isa, ""), jit_uni_lrn_bwd_t);
76
77 status_t init(engine_t *engine);
78
79 format_tag_t dat_tag_;
80 };
81
82 jit_uni_lrn_bwd_t(const pd_t *apd);
83 ~jit_uni_lrn_bwd_t();
84
85 using data_t = typename prec_traits<d_type>::type;
86
87 status_t init(engine_t *engine) override;
88
89 status_t execute(const exec_ctx_t &ctx) const override {
90 return execute_backward(ctx);
91 }
92
93private:
94 status_t execute_backward(const exec_ctx_t &ctx) const;
95 const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
96
97 std::unique_ptr<jit_uni_lrn_bwd_kernel_t<isa, d_type>> ker_, ker_first_,
98 ker_last_;
99 static constexpr int VECTOR_LENGTH
100 = jit_uni_lrn_bwd_kernel_t<isa, d_type>::VECTOR_LENGTH;
101};
102
103} // namespace x64
104} // namespace cpu
105} // namespace impl
106} // namespace dnnl
107
108#endif
109
110// vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
111