updated readme file due to moving CMake scripts to the root folder
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / cpu / cpu_isa_traits.hpp
1 /*******************************************************************************
2 * Copyright 2018 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_ISA_TRAITS_HPP
18 #define CPU_ISA_TRAITS_HPP
19
20 #include <type_traits>
21
22 #define XBYAK64
23 #define XBYAK_NO_OP_NAMES
24 /* in order to make selinux happy memory that would be marked with X-bit should
25  * be obtained with mmap */
26 #define XBYAK_USE_MMAP_ALLOCATOR
27 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
28 /* turn off `size_t to other-type implicit casting` warning
29  * currently we have a lot of jit-generated instructions that
30  * take uint32_t, but we pass size_t (e.g. due to using sizeof).
31  * FIXME: replace size_t parameters with the appropriate ones */
32 #pragma warning (disable: 4267)
33 #endif
34 #include "xbyak/xbyak.h"
35 #include "xbyak/xbyak_util.h"
36
37 namespace mkldnn {
38 namespace impl {
39 namespace cpu {
40
41 typedef enum {
42     isa_any,
43     sse42,
44     avx,
45     avx2,
46     avx512_common,
47     avx512_core,
48     avx512_core_vnni,
49     avx512_mic,
50     avx512_mic_4ops,
51     avx512_core_bf16,
52     avx512_vpopcnt,
53 } cpu_isa_t;
54
55 template <cpu_isa_t> struct cpu_isa_traits {}; /* ::vlen -> 32 (for avx2) */
56
57 template <> struct cpu_isa_traits<sse42> {
58     typedef Xbyak::Xmm Vmm;
59     static constexpr int vlen_shift = 4;
60     static constexpr int vlen = 16;
61     static constexpr int n_vregs = 16;
62 };
63 template <> struct cpu_isa_traits<avx> {
64     typedef Xbyak::Ymm Vmm;
65     static constexpr int vlen_shift = 5;
66     static constexpr int vlen = 32;
67     static constexpr int n_vregs = 16;
68 };
69 template <> struct cpu_isa_traits<avx2>:
70     public cpu_isa_traits<avx> {};
71
72 template <> struct cpu_isa_traits<avx512_common> {
73     typedef Xbyak::Zmm Vmm;
74     static constexpr int vlen_shift = 6;
75     static constexpr int vlen = 64;
76     static constexpr int n_vregs = 32;
77 };
78 template <> struct cpu_isa_traits<avx512_core>:
79     public cpu_isa_traits<avx512_common> {};
80
81 template <> struct cpu_isa_traits<avx512_mic>:
82     public cpu_isa_traits<avx512_common> {};
83
84 template <> struct cpu_isa_traits<avx512_mic_4ops>:
85     public cpu_isa_traits<avx512_common> {};
86
87 template <> struct cpu_isa_traits<avx512_core_bf16>:
88     public cpu_isa_traits<avx512_common> {};
89
90 namespace {
91
92 static Xbyak::util::Cpu cpu;
93 static inline bool mayiuse(const cpu_isa_t cpu_isa) {
94     using namespace Xbyak::util;
95
96     switch (cpu_isa) {
97     case sse42:
98         return cpu.has(Cpu::tSSE42);
99     case avx:
100         return cpu.has(Cpu::tAVX);
101     case avx2:
102         return cpu.has(Cpu::tAVX2);
103     case avx512_common:
104         return cpu.has(Cpu::tAVX512F);
105     case avx512_core:
106         return true
107             && cpu.has(Cpu::tAVX512F)
108             && cpu.has(Cpu::tAVX512BW)
109             && cpu.has(Cpu::tAVX512VL)
110             && cpu.has(Cpu::tAVX512DQ);
111     case avx512_core_vnni:
112         return true
113             && cpu.has(Cpu::tAVX512F)
114             && cpu.has(Cpu::tAVX512BW)
115             && cpu.has(Cpu::tAVX512VL)
116             && cpu.has(Cpu::tAVX512DQ)
117             && cpu.has(Cpu::tAVX512_VNNI);
118     case avx512_mic:
119         return true
120             && cpu.has(Cpu::tAVX512F)
121             && cpu.has(Cpu::tAVX512CD)
122             && cpu.has(Cpu::tAVX512ER)
123             && cpu.has(Cpu::tAVX512PF);
124     case avx512_mic_4ops:
125         return true
126             && mayiuse(avx512_mic)
127             && cpu.has(Cpu::tAVX512_4FMAPS)
128             && cpu.has(Cpu::tAVX512_4VNNIW);
129     case avx512_core_bf16:
130         return true
131             && mayiuse(avx512_core_vnni)
132             && cpu.has(Cpu::tAVX512_BF);
133     case avx512_vpopcnt:
134         return true
135             && cpu.has(Cpu::tAVX512_VPOPCNTDQ);
136     case isa_any:
137         return true;
138     }
139     return false;
140 }
141 }
142
143 /* whatever is required to generate string literals... */
144 #include "z_magic.hpp"
145 #define JIT_IMPL_NAME_HELPER(prefix, isa, suffix_if_any) \
146     (isa == sse42 ? prefix STRINGIFY(sse42) : \
147     (isa == avx ? prefix STRINGIFY(avx) : \
148     (isa == avx2 ? prefix STRINGIFY(avx2) : \
149     (isa == avx512_common ? prefix STRINGIFY(avx512_common) : \
150     (isa == avx512_core ? prefix STRINGIFY(avx512_core) : \
151     (isa == avx512_mic ? prefix STRINGIFY(avx512_mic) : \
152     (isa == avx512_mic_4ops ? prefix STRINGIFY(avx512_mic_4ops) : \
153     (isa == avx512_core_bf16 ? prefix STRINGIFY(avx512_core_bf16) : \
154     prefix suffix_if_any))))))))
155
156 }
157 }
158 }
159
160 #endif