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 | #ifndef GPU_JIT_UTILS_NGEN_TYPE_BRIDGE_HPP |
18 | #define GPU_JIT_UTILS_NGEN_TYPE_BRIDGE_HPP |
19 | |
20 | #include "common/c_types_map.hpp" |
21 | #include "gpu/compute/device_info.hpp" |
22 | #include "gpu/jit/ngen/ngen.hpp" |
23 | |
24 | namespace dnnl { |
25 | namespace impl { |
26 | namespace gpu { |
27 | namespace jit { |
28 | |
29 | inline ngen::DataType convert_dnnl_type_to_ngen(data_type_t dt) { |
30 | using namespace ngen; |
31 | |
32 | DataType dt_out = DataType::invalid; |
33 | |
34 | switch (dt) { |
35 | case data_type::f16: dt_out = DataType::hf; break; |
36 | case data_type::bf16: dt_out = DataType::bf; break; |
37 | case data_type::f32: dt_out = DataType::f; break; |
38 | case data_type::s32: dt_out = DataType::d; break; |
39 | case data_type::s8: dt_out = DataType::b; break; |
40 | case data_type::u8: dt_out = DataType::ub; break; |
41 | default: assert(!"Unknown datatype"); |
42 | } |
43 | |
44 | return dt_out; |
45 | } |
46 | |
47 | inline ngen::HW convert_dnnl_arch_to_ngen(compute::gpu_arch_t gpu_arch) { |
48 | switch (gpu_arch) { |
49 | case compute::gpu_arch_t::gen9: return ngen::HW::Gen9; |
50 | case compute::gpu_arch_t::gen11: return ngen::HW::Gen11; |
51 | case compute::gpu_arch_t::xe_lp: return ngen::HW::XeLP; |
52 | case compute::gpu_arch_t::xe_hp: return ngen::HW::XeHP; |
53 | case compute::gpu_arch_t::xe_hpg: return ngen::HW::XeHPG; |
54 | case compute::gpu_arch_t::xe_hpc: return ngen::HW::XeHPC; |
55 | case compute::gpu_arch_t::unknown: return ngen::HW::Unknown; |
56 | } |
57 | return ngen::HW::Unknown; |
58 | } |
59 | |
60 | inline compute::gpu_arch_t convert_ngen_arch_to_dnnl(ngen::HW gpu_arch) { |
61 | switch (gpu_arch) { |
62 | case ngen::HW::Gen9: return compute::gpu_arch_t::gen9; |
63 | case ngen::HW::Gen11: return compute::gpu_arch_t::gen11; |
64 | case ngen::HW::XeLP: return compute::gpu_arch_t::xe_lp; |
65 | case ngen::HW::XeHP: return compute::gpu_arch_t::xe_hp; |
66 | case ngen::HW::XeHPG: return compute::gpu_arch_t::xe_hpg; |
67 | case ngen::HW::XeHPC: return compute::gpu_arch_t::xe_hpc; |
68 | case ngen::HW::Gen10: |
69 | // Gen10 is not supported. Included here instead of default so |
70 | // warnings are emitted when new architectures are added. |
71 | case ngen::HW::Unknown: return compute::gpu_arch_t::unknown; |
72 | } |
73 | return compute::gpu_arch_t::unknown; |
74 | } |
75 | |
76 | } // namespace jit |
77 | } // namespace gpu |
78 | } // namespace impl |
79 | } // namespace dnnl |
80 | #endif |
81 | |
82 | // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s |
83 |