1/*******************************************************************************
2* Copyright 2017-2020 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_ELTWISE_HPP
18#define CPU_X64_JIT_UNI_ELTWISE_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_eltwise_pd.hpp"
28
29#include "cpu/x64/cpu_isa_traits.hpp"
30
31namespace dnnl {
32namespace impl {
33namespace cpu {
34namespace x64 {
35
36struct jit_uni_eltwise_kernel;
37
38template <cpu_isa_t isa, impl::data_type_t d_type>
39struct jit_uni_eltwise_fwd_t : public primitive_t {
40 struct pd_t : public cpu_eltwise_fwd_pd_t {
41 using cpu_eltwise_fwd_pd_t::cpu_eltwise_fwd_pd_t;
42
43 DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit:",
44 ((d_type == data_type::bf16)
45 && mayiuse(avx512_core_bf16))
46 ? avx512_core_bf16
47 : isa,
48 ""),
49 jit_uni_eltwise_fwd_t);
50
51 status_t init(engine_t *engine);
52 };
53
54 jit_uni_eltwise_fwd_t(const pd_t *apd);
55 virtual ~jit_uni_eltwise_fwd_t();
56
57 typedef typename prec_traits<d_type>::type data_t;
58
59 status_t init(engine_t *engine) override;
60
61 status_t execute(const exec_ctx_t &ctx) const override;
62
63private:
64 const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
65 std::unique_ptr<jit_uni_eltwise_kernel> kernel_;
66};
67
68template <cpu_isa_t isa, impl::data_type_t d_type>
69struct jit_uni_eltwise_bwd_t : public primitive_t {
70 struct pd_t : public cpu_eltwise_bwd_pd_t {
71 using cpu_eltwise_bwd_pd_t::cpu_eltwise_bwd_pd_t;
72
73 DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit:",
74 ((d_type == data_type::bf16)
75 && mayiuse(avx512_core_bf16))
76 ? avx512_core_bf16
77 : isa,
78 ""),
79 jit_uni_eltwise_bwd_t);
80
81 status_t init(engine_t *engine);
82 };
83
84 jit_uni_eltwise_bwd_t(const pd_t *apd);
85 virtual ~jit_uni_eltwise_bwd_t();
86
87 typedef typename prec_traits<d_type>::type data_t;
88
89 status_t init(engine_t *engine) override;
90
91 status_t execute(const exec_ctx_t &ctx) const override;
92
93private:
94 const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
95 std::unique_ptr<jit_uni_eltwise_kernel> kernel_;
96};
97
98} // namespace x64
99} // namespace cpu
100} // namespace impl
101} // namespace dnnl
102
103#endif
104