Debian Codegraph @

visa/iga/IGALibrary/api/iga_bxml_enums.hpp

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2018-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #ifndef IGA_BXML_TYPES_HPP
10 #define IGA_BXML_TYPES_HPP
11
12 // C++17 allows inline variables, but until then we need a data structure
13 #include <array>
14 #include <cstdint>
15
16 namespace iga {
17 struct BfnFC {
18 uint32_t value;
19 constexpr explicit BfnFC(uint8_t val) : value(val) {}
20 const char *c_str() const;
21 };
22
23 // used for if, else, and goto
24 enum class BranchCtrl {
25 OFF,
26 ON,
27 };
28
29 // used for instructions that lack a subfunction
30 enum class InvalidFC { INVALID = -1 };
31
32 // Math function control (selector)
33 enum class MathFC {
34 INVALID = -1,
35 INV = 1,
36 LOG,
37 EXP,
38 SQT,
39 RSQT,
40 SIN,
41 COS,
42 FDIV,
43 POW,
44 IDIV,
45 IQOT,
46 IREM,
47 INVM,
48 RSQTM,
49 TANH,
50 SIGM
51 };
52 // static const MathFC ALL_MathFCs[] ... need C++17
53 static const std::array<MathFC, 16> ALL_MathFCs{
54 MathFC::INV, MathFC::LOG, MathFC::EXP, MathFC::SQT,
55 MathFC::RSQT, MathFC::SIN, MathFC::COS, MathFC::FDIV,
56 MathFC::POW, MathFC::IDIV, MathFC::IQOT, MathFC::IREM,
57 MathFC::INVM, MathFC::RSQTM, MathFC::TANH, MathFC::SIGM,
58 };
59 unsigned GetSourceCount(MathFC mfc);
60 static inline bool IsMacro(MathFC mfc) {
61 return mfc == MathFC::INVM || mfc == MathFC::RSQTM;
62 }
63 enum class ShuffleFC {
64 INVALID = -1,
65 UP = 0,
66 UPZ,
67 DN,
68 DNZ,
69 XOR,
70 IDX,
71 IDX4
72 };
73
74 static const std::array<ShuffleFC, 7>
75 ALL_ShuffleFC {
76 ShuffleFC::UP, ShuffleFC::UPZ, ShuffleFC::DN, ShuffleFC::DNZ,
77 ShuffleFC::XOR, ShuffleFC::IDX, ShuffleFC::IDX4
78 };
79
80 enum class LfsrFC {
81 INVALID = -1,
82 LFSR_b32 = 0, // Single 32-bit seed/polynomial
83 LFSR_b16v2, // Two 16-bit seeds/polynomials packed in 32 bits
84 LFSR_b8v4 // Four 8-bit seeds/polynomials packed in 32 bits
85 };
86
87 static const std::array<LfsrFC, 3>
88 ALL_LfsrFC {
89 LfsrFC::LFSR_b32, LfsrFC::LFSR_b16v2, LfsrFC::LFSR_b8v4
90 };
91
92 // Send shared function ID
93 enum class SFID {
94 INVALID = -1,
95 NULL_ = 0, // the null shared function
96 UGML, // untyped global memory (low bandwidth) for XeHPC
97 SMPL, // sampler
98 GTWY, // gateway
99 DC2, // data cache 2
100 RC, // render cache
101 URB, // unified return buffer
102 TS, // thread spawner (until XeHPG)
103 VME, // video motion estimation (until XeHPG)
104 DCRO, // data cache read-only
105 DC0, // data cache 0
106 PIXI, // pixel interpolator
107 DC1, // data cache 1
108 CRE, // check and refinement engine (until XeHPG)
109 SLM, // shared local memory (XeHPG+)
110 UGM, // untyped global memory (XeHPG+)
111 BTD, // bindless thread dispatcher (XeHPG+)
112 RTA, // ray tracing accellerator (XeHPG+)
113 TGM, // typed global memory (XeHPG+)
114 A0REG = 0x100, // for <XE SFID can be indirect
115 };
116 static const std::array<SFID,
117 19
118 >
119 ALL_SFIDS{
120 SFID::NULL_, SFID::UGML, SFID::SMPL, SFID::GTWY, SFID::DC2,
121 SFID::RC, SFID::URB, SFID::TS, SFID::VME, SFID::DCRO,
122 SFID::DC0, SFID::PIXI, SFID::DC1, SFID::CRE, SFID::SLM,
123 SFID::UGM, SFID::BTD, SFID::RTA, SFID::TGM,
124 };
125
126
127 // The sync instruction's subfunction
128 enum class SyncFC {
129 INVALID = -1,
130 NOP = 0,
131 ALLRD = 2,
132 ALLWR = 3,
133 FLUSH = 12,
134 FENCE = 13, // XeHPC
135 BAR = 14,
136 HOST = 15,
137 };
138 // static const SyncFC ALL_SyncFCs[] ...
139 static const std::array<SyncFC, 7> ALL_SyncFCs {
140 SyncFC::NOP, SyncFC::ALLRD, SyncFC::ALLWR, SyncFC::FLUSH,
141 SyncFC::FENCE, // XeHPC
142 SyncFC::BAR, SyncFC::HOST,
143 };
144
145 // The DpasFC function control fuses the systolic count and repeat counts
146 // into a single subfunction.
147 enum class DpasFC {
148 // ordinal values are now (SystolicCount << 8) | (RepeatCount)
149 // encoding has to do something special because it's platform specific
150 INVALID = -1,
151 //
152 F_1X1 = (1 << 8) | 1,
153 F_1X2 = (1 << 8) | 2,
154 F_1X3 = (1 << 8) | 3,
155 F_1X4 = (1 << 8) | 4,
156 F_1X5 = (1 << 8) | 5,
157 F_1X6 = (1 << 8) | 6,
158 F_1X7 = (1 << 8) | 7,
159 F_1X8 = (1 << 8) | 8,
160 F_2X1 = (2 << 8) | 1,
161 F_2X2 = (2 << 8) | 2,
162 F_2X3 = (2 << 8) | 3,
163 F_2X4 = (2 << 8) | 4,
164 F_2X5 = (2 << 8) | 5,
165 F_2X6 = (2 << 8) | 6,
166 F_2X7 = (2 << 8) | 7,
167 F_2X8 = (2 << 8) | 8,
168 F_4X1 = (4 << 8) | 1,
169 F_4X2 = (4 << 8) | 2,
170 F_4X3 = (4 << 8) | 3,
171 F_4X4 = (4 << 8) | 4,
172 F_4X5 = (4 << 8) | 5,
173 F_4X6 = (4 << 8) | 6,
174 F_4X7 = (4 << 8) | 7,
175 F_4X8 = (4 << 8) | 8,
176 F_8X1 = (8 << 8) | 1,
177 F_8X2 = (8 << 8) | 2,
178 F_8X3 = (8 << 8) | 3,
179 F_8X4 = (8 << 8) | 4,
180 F_8X5 = (8 << 8) | 5,
181 F_8X6 = (8 << 8) | 6,
182 F_8X7 = (8 << 8) | 7,
183 F_8X8 = (8 << 8) | 8,
184 };
185
186 // static const DpasFC ALL_DpasFCs[] ...
187 static const std::array<DpasFC, 48> ALL_DpasFCs {
188 DpasFC::F_1X1, DpasFC::F_1X2, DpasFC::F_1X3, DpasFC::F_1X4, DpasFC::F_1X5,
189 DpasFC::F_1X6, DpasFC::F_1X7, DpasFC::F_1X8, DpasFC::F_2X1, DpasFC::F_2X2,
190 DpasFC::F_2X3, DpasFC::F_2X4, DpasFC::F_2X5, DpasFC::F_2X6, DpasFC::F_2X7,
191 DpasFC::F_2X8, DpasFC::F_4X1, DpasFC::F_4X2, DpasFC::F_4X3, DpasFC::F_4X4,
192 DpasFC::F_4X5, DpasFC::F_4X6, DpasFC::F_4X7, DpasFC::F_4X8, DpasFC::F_8X1,
193 DpasFC::F_8X2, DpasFC::F_8X3, DpasFC::F_8X4, DpasFC::F_8X5, DpasFC::F_8X6,
194 DpasFC::F_8X7, DpasFC::F_8X8,
195 };
196
197 static inline uint32_t GetDpasSystolicDepth(DpasFC sf) {
198 return uint32_t(sf) >> 8;
199 }
200 static inline uint32_t GetDpasRepeatCount(DpasFC sf) {
201 return uint32_t(sf) & 0xFF;
202 }
203 static inline uint32_t GetDpasSystolicDepthEncoding(DpasFC sf) {
204 switch (GetDpasSystolicDepth(sf)) {
205 case 1:
206 return 0;
207 case 2:
208 return 1;
209 case 4:
210 return 2;
211 case 8:
212 return 3;
213 default:
214 return 0xFFFFFFFF; // unreachable
215 }
216 }
217 static inline uint32_t GetDpasRepeatCountEncoding(DpasFC sf) {
218 return GetDpasRepeatCount(sf) - 1;
219 }
220 static inline DpasFC GetDpasFC(uint32_t sysD, uint32_t repC) {
221 return DpasFC((sysD << 8) | repC);
222 }
223
224 // dnscl instruction's modes and types
225 enum class DnsclMode {
226 INVALID = -1,
227 MODE0, // Packs the output following the downscale instruction's Mode0
228 MODE1, // Packs the output following the downscale instruction's Mode1
229 MODE2, // Packs the output following the downscale instruction's Mode2
230 MODE3 // Packs the output following the downscale instruction's Mode3
231 };
232
233 static const std::array<DnsclMode, 4>
234 ALL_DnsclMode {
235 DnsclMode::MODE0,
236 DnsclMode::MODE1,
237 DnsclMode::MODE2,
238 DnsclMode::MODE3
239 };
240
241 enum class ConvDstDataType {
242 INVALID = -1,
243 E2M1,
244 INT4
245 };
246
247 static const std::array<ConvDstDataType, 3>
248 ALL_ConvDstDataType {
249 ConvDstDataType::E2M1,
250 ConvDstDataType::INT4
251 };
252
253 enum class ConvSrcDataType {
254 INVALID = -1,
255 HF,
256 BF
257 };
258
259 static const std::array<ConvSrcDataType, 2>
260 ALL_ConvSrcDataType {
261 ConvSrcDataType::HF,
262 ConvSrcDataType::BF,
263 };
264
265 enum class RoundingMode {
266 INVALID = -1,
267 SRAND,
268 RNE
269 };
270
271 static const std::array<RoundingMode, 2>
272 ALL_RoundingMode {
273 RoundingMode::SRAND,
274 RoundingMode::RNE,
275 };
276
277 struct DnsclFC {
278 // dnscl FC is composed by 4 parts: ConvSrcDataType, ConvDstDataType,
279 // DnsclMode and RoundingMode.
280 ConvSrcDataType convSrcTy : 8;
281 ConvDstDataType convDstTy : 8;
282 DnsclMode dnsclMode : 8;
283 RoundingMode roundingMode : 8;
284
285 constexpr explicit DnsclFC(ConvSrcDataType srcTy, ConvDstDataType dstTy,
286 DnsclMode dm, RoundingMode rm)
287 : convSrcTy(srcTy), convDstTy(dstTy), dnsclMode(dm), roundingMode(rm) {}
288 };
289
290 // An instruction subfunction is a set of immediate-encoded control bits
291 // that control the behavior of some EU instruction. We permit an
292 // Instruction to have exactly one of these fields.
293 //
294 // For instance, the 'math' instruction (Op::MATH) must have a subfunction
295 // to select the specific math operation to execute.
296 //
297 //
298 // This is a union data type containing all the valid subfunctions
299 // that an instruction may have
300 // e.g.
301 // send.<SUBFUNC> ...
302 // sync.<SUBFUNC> ...
303 // math.<SUBFUNC> ...
304 // For instructions that contain multiple paramters pair the two
305 // together into a single value via a pairing function
306 // (search for "Pairing Function" if unfamiliar).
307 // E.g. DPAS has both a systolic depth and repeat count.
308 // One way to pair that is to use the high half of the integer
309 // to hold one, and the low half to hold the other.
310 //
311 // NOTE: it's fine to use struct pair{uint16_t x; uint16_t y;};
312 // so long as the structure fits in 4B (we could make this wider, but
313 // don't go crazy and beware of issues with ragged union sizes).
314 //
315 // **: SFID is a littly wonky here since in <=GEN11 it is part of the
316 // send extended descriptor. Hence, parsing and decoding have to get
317 // it in different parts of their respective algorithms.
318 struct Subfunction {
319 union {
320 InvalidFC invalid; // for operations without a subfunction
321 BranchCtrl branch; // for if/else/goto on GEN8+
322 MathFC math; // op == Op::MATH
323 SFID send; // op == Op::SEND* (**)
324 SyncFC sync; // op == Op::SYNC
325 BfnFC bfn; // BFN subfunction index (low 8 bits are relevent)
326 DpasFC dpas; // op == Op::DPAS || op == Op::DPASW
327 ShuffleFC shuffle; // shuffle function (up, upz, dn, dnz, id, idx4)
328 LfsrFC lfsr; // lfsr function control
329 DnsclFC dnscl; // dnscl function control
330 // NOTE: this does *not* correspond to any direct encoding
331 // since that can vary from platform to platform.
332 uint32_t bits;
333 };
334 constexpr Subfunction() : Subfunction(InvalidFC::INVALID) {}
335 constexpr Subfunction(InvalidFC sf) : invalid(sf) {}
336 constexpr Subfunction(BranchCtrl sf) : branch(sf) {}
337 constexpr Subfunction(MathFC sf) : math(sf) {}
338 constexpr Subfunction(SFID sf) : send(sf) {}
339 constexpr Subfunction(SyncFC sf) : sync(sf) {}
340 constexpr Subfunction(BfnFC bf) : bfn(bf) {}
341 constexpr Subfunction(DpasFC sf) : dpas(sf) {}
342 constexpr Subfunction(ShuffleFC sf) : shuffle(sf) {}
343 constexpr Subfunction(LfsrFC sf) : lfsr(sf) {}
344 constexpr Subfunction(DnsclFC sf) : dnscl(sf) {}
345
346 bool isValid() const { return invalid != InvalidFC::INVALID; }
347 };
348 static_assert(sizeof(Subfunction) == 4, "Subfunction should be 4B");
349 } // namespace iga
350 #endif // _IGA_BXML_TYPES_HPP