1 | /******************************************************************************* |
2 | * Copyright 2019-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 | #include "cpu/cpu_engine.hpp" |
18 | |
19 | #include "cpu/ref_layer_normalization.hpp" |
20 | #include "cpu/simple_layer_normalization.hpp" |
21 | |
22 | #if DNNL_X64 |
23 | #include "cpu/x64/jit_uni_layer_normalization.hpp" |
24 | using namespace dnnl::impl::cpu::x64; |
25 | #endif |
26 | |
27 | namespace dnnl { |
28 | namespace impl { |
29 | namespace cpu { |
30 | |
31 | namespace { |
32 | using namespace dnnl::impl::data_type; |
33 | using namespace dnnl::impl::prop_kind; |
34 | |
35 | // clang-format off |
36 | const std::map<pk_impl_key_t, std::vector<impl_list_item_t>> &impl_list_map() { |
37 | static const std::map<pk_impl_key_t, std::vector<impl_list_item_t>> the_map = REG_LNORM_P({ |
38 | {{forward}, { |
39 | CPU_INSTANCE_X64(jit_uni_layer_normalization_fwd_t) |
40 | CPU_INSTANCE(simple_layer_normalization_fwd_t) |
41 | CPU_INSTANCE(ref_layer_normalization_fwd_t) |
42 | nullptr, |
43 | }}, |
44 | {{backward}, REG_BWD_PK({ |
45 | CPU_INSTANCE_X64(jit_uni_layer_normalization_bwd_t) |
46 | CPU_INSTANCE(simple_layer_normalization_bwd_t) |
47 | CPU_INSTANCE(ref_layer_normalization_bwd_t) |
48 | nullptr, |
49 | })}, |
50 | }); |
51 | return the_map; |
52 | } |
53 | // clang-format on |
54 | } // namespace |
55 | |
56 | const impl_list_item_t *get_layer_normalization_impl_list( |
57 | const layer_normalization_desc_t *desc) { |
58 | static const impl_list_item_t empty_list[] = {nullptr}; |
59 | |
60 | const bool is_fwd = utils::one_of( |
61 | desc->prop_kind, forward_training, forward_inference); |
62 | prop_kind_t prop_kind = is_fwd ? forward : backward; |
63 | |
64 | pk_impl_key_t key {prop_kind}; |
65 | |
66 | const auto impl_list_it = impl_list_map().find(key); |
67 | return impl_list_it != impl_list_map().cend() ? impl_list_it->second.data() |
68 | : empty_list; |
69 | } |
70 | |
71 | } // namespace cpu |
72 | } // namespace impl |
73 | } // namespace dnnl |
74 | |