1//===--- AMDGPUMetadata.h ---------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// AMDGPU metadata definitions and in-memory representations.
11///
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_SUPPORT_AMDGPUMETADATA_H
16#define LLVM_SUPPORT_AMDGPUMETADATA_H
17
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Compiler.h"
20#include <cstdint>
21#include <string>
22#include <system_error>
23#include <vector>
24
25namespace llvm {
26namespace AMDGPU {
27
28//===----------------------------------------------------------------------===//
29// HSA metadata.
30//===----------------------------------------------------------------------===//
31namespace HSAMD {
32
33/// HSA metadata major version for code object V3.
34constexpr uint32_t VersionMajorV3 = 1;
35/// HSA metadata minor version for code object V3.
36constexpr uint32_t VersionMinorV3 = 0;
37
38/// HSA metadata major version for code object V4.
39constexpr uint32_t VersionMajorV4 = 1;
40/// HSA metadata minor version for code object V4.
41constexpr uint32_t VersionMinorV4 = 1;
42
43/// HSA metadata major version for code object V5.
44constexpr uint32_t VersionMajorV5 = 1;
45/// HSA metadata minor version for code object V5.
46constexpr uint32_t VersionMinorV5 = 2;
47
48/// HSA metadata major version for code object V6.
49constexpr uint32_t VersionMajorV6 = 1;
50/// HSA metadata minor version for code object V6.
51constexpr uint32_t VersionMinorV6 = 2;
52
53/// Old HSA metadata beginning assembler directive for V2. This is only used for
54/// diagnostics now.
55
56/// HSA metadata beginning assembler directive.
57constexpr char AssemblerDirectiveBegin[] = ".amd_amdgpu_hsa_metadata";
58
59/// Access qualifiers.
60enum class AccessQualifier : uint8_t {
61 Default = 0,
62 ReadOnly = 1,
63 WriteOnly = 2,
64 ReadWrite = 3,
65 Unknown = 0xff
66};
67
68/// Address space qualifiers.
69enum class AddressSpaceQualifier : uint8_t {
70 Private = 0,
71 Global = 1,
72 Constant = 2,
73 Local = 3,
74 Generic = 4,
75 Region = 5,
76 Unknown = 0xff
77};
78
79/// Value kinds.
80enum class ValueKind : uint8_t {
81 ByValue = 0,
82 GlobalBuffer = 1,
83 DynamicSharedPointer = 2,
84 Sampler = 3,
85 Image = 4,
86 Pipe = 5,
87 Queue = 6,
88 HiddenGlobalOffsetX = 7,
89 HiddenGlobalOffsetY = 8,
90 HiddenGlobalOffsetZ = 9,
91 HiddenNone = 10,
92 HiddenPrintfBuffer = 11,
93 HiddenDefaultQueue = 12,
94 HiddenCompletionAction = 13,
95 HiddenMultiGridSyncArg = 14,
96 HiddenHostcallBuffer = 15,
97 Unknown = 0xff
98};
99
100/// Value types. This is deprecated and only remains for compatibility parsing
101/// of old metadata.
102enum class ValueType : uint8_t {
103 Struct = 0,
104 I8 = 1,
105 U8 = 2,
106 I16 = 3,
107 U16 = 4,
108 F16 = 5,
109 I32 = 6,
110 U32 = 7,
111 F32 = 8,
112 I64 = 9,
113 U64 = 10,
114 F64 = 11,
115 Unknown = 0xff
116};
117
118//===----------------------------------------------------------------------===//
119// Kernel Metadata.
120//===----------------------------------------------------------------------===//
121namespace Kernel {
122
123//===----------------------------------------------------------------------===//
124// Kernel Attributes Metadata.
125//===----------------------------------------------------------------------===//
126namespace Attrs {
127
128namespace Key {
129/// Key for Kernel::Attr::Metadata::mReqdWorkGroupSize.
130constexpr char ReqdWorkGroupSize[] = "ReqdWorkGroupSize";
131/// Key for Kernel::Attr::Metadata::mWorkGroupSizeHint.
132constexpr char WorkGroupSizeHint[] = "WorkGroupSizeHint";
133/// Key for Kernel::Attr::Metadata::mVecTypeHint.
134constexpr char VecTypeHint[] = "VecTypeHint";
135/// Key for Kernel::Attr::Metadata::mRuntimeHandle.
136constexpr char RuntimeHandle[] = "RuntimeHandle";
137} // end namespace Key
138
139/// In-memory representation of kernel attributes metadata.
140struct Metadata final {
141 /// 'reqd_work_group_size' attribute. Optional.
142 std::vector<uint32_t> mReqdWorkGroupSize = std::vector<uint32_t>();
143 /// 'work_group_size_hint' attribute. Optional.
144 std::vector<uint32_t> mWorkGroupSizeHint = std::vector<uint32_t>();
145 /// 'vec_type_hint' attribute. Optional.
146 std::string mVecTypeHint = std::string();
147 /// External symbol created by runtime to store the kernel address
148 /// for enqueued blocks.
149 std::string mRuntimeHandle = std::string();
150
151 /// Default constructor.
152 Metadata() = default;
153
154 /// \returns True if kernel attributes metadata is empty, false otherwise.
155 bool empty() const {
156 return !notEmpty();
157 }
158
159 /// \returns True if kernel attributes metadata is not empty, false otherwise.
160 bool notEmpty() const {
161 return !mReqdWorkGroupSize.empty() || !mWorkGroupSizeHint.empty() ||
162 !mVecTypeHint.empty() || !mRuntimeHandle.empty();
163 }
164};
165
166} // end namespace Attrs
167
168//===----------------------------------------------------------------------===//
169// Kernel Argument Metadata.
170//===----------------------------------------------------------------------===//
171namespace Arg {
172
173namespace Key {
174/// Key for Kernel::Arg::Metadata::mName.
175constexpr char Name[] = "Name";
176/// Key for Kernel::Arg::Metadata::mTypeName.
177constexpr char TypeName[] = "TypeName";
178/// Key for Kernel::Arg::Metadata::mSize.
179constexpr char Size[] = "Size";
180/// Key for Kernel::Arg::Metadata::mOffset.
181constexpr char Offset[] = "Offset";
182/// Key for Kernel::Arg::Metadata::mAlign.
183constexpr char Align[] = "Align";
184/// Key for Kernel::Arg::Metadata::mValueKind.
185constexpr char ValueKind[] = "ValueKind";
186/// Key for Kernel::Arg::Metadata::mValueType. (deprecated)
187constexpr char ValueType[] = "ValueType";
188/// Key for Kernel::Arg::Metadata::mPointeeAlign.
189constexpr char PointeeAlign[] = "PointeeAlign";
190/// Key for Kernel::Arg::Metadata::mAddrSpaceQual.
191constexpr char AddrSpaceQual[] = "AddrSpaceQual";
192/// Key for Kernel::Arg::Metadata::mAccQual.
193constexpr char AccQual[] = "AccQual";
194/// Key for Kernel::Arg::Metadata::mActualAccQual.
195constexpr char ActualAccQual[] = "ActualAccQual";
196/// Key for Kernel::Arg::Metadata::mIsConst.
197constexpr char IsConst[] = "IsConst";
198/// Key for Kernel::Arg::Metadata::mIsRestrict.
199constexpr char IsRestrict[] = "IsRestrict";
200/// Key for Kernel::Arg::Metadata::mIsVolatile.
201constexpr char IsVolatile[] = "IsVolatile";
202/// Key for Kernel::Arg::Metadata::mIsPipe.
203constexpr char IsPipe[] = "IsPipe";
204} // end namespace Key
205
206/// In-memory representation of kernel argument metadata.
207struct Metadata final {
208 /// Name. Optional.
209 std::string mName = std::string();
210 /// Type name. Optional.
211 std::string mTypeName = std::string();
212 /// Size in bytes. Required.
213 uint32_t mSize = 0;
214 /// Offset in bytes. Required for code object v3, unused for code object v2.
215 uint32_t mOffset = 0;
216 /// Alignment in bytes. Required.
217 uint32_t mAlign = 0;
218 /// Value kind. Required.
219 ValueKind mValueKind = ValueKind::Unknown;
220 /// Pointee alignment in bytes. Optional.
221 uint32_t mPointeeAlign = 0;
222 /// Address space qualifier. Optional.
223 AddressSpaceQualifier mAddrSpaceQual = AddressSpaceQualifier::Unknown;
224 /// Access qualifier. Optional.
225 AccessQualifier mAccQual = AccessQualifier::Unknown;
226 /// Actual access qualifier. Optional.
227 AccessQualifier mActualAccQual = AccessQualifier::Unknown;
228 /// True if 'const' qualifier is specified. Optional.
229 bool mIsConst = false;
230 /// True if 'restrict' qualifier is specified. Optional.
231 bool mIsRestrict = false;
232 /// True if 'volatile' qualifier is specified. Optional.
233 bool mIsVolatile = false;
234 /// True if 'pipe' qualifier is specified. Optional.
235 bool mIsPipe = false;
236
237 /// Default constructor.
238 Metadata() = default;
239};
240
241} // end namespace Arg
242
243//===----------------------------------------------------------------------===//
244// Kernel Code Properties Metadata.
245//===----------------------------------------------------------------------===//
246namespace CodeProps {
247
248namespace Key {
249/// Key for Kernel::CodeProps::Metadata::mKernargSegmentSize.
250constexpr char KernargSegmentSize[] = "KernargSegmentSize";
251/// Key for Kernel::CodeProps::Metadata::mGroupSegmentFixedSize.
252constexpr char GroupSegmentFixedSize[] = "GroupSegmentFixedSize";
253/// Key for Kernel::CodeProps::Metadata::mPrivateSegmentFixedSize.
254constexpr char PrivateSegmentFixedSize[] = "PrivateSegmentFixedSize";
255/// Key for Kernel::CodeProps::Metadata::mKernargSegmentAlign.
256constexpr char KernargSegmentAlign[] = "KernargSegmentAlign";
257/// Key for Kernel::CodeProps::Metadata::mWavefrontSize.
258constexpr char WavefrontSize[] = "WavefrontSize";
259/// Key for Kernel::CodeProps::Metadata::mNumSGPRs.
260constexpr char NumSGPRs[] = "NumSGPRs";
261/// Key for Kernel::CodeProps::Metadata::mNumVGPRs.
262constexpr char NumVGPRs[] = "NumVGPRs";
263/// Key for Kernel::CodeProps::Metadata::mMaxFlatWorkGroupSize.
264constexpr char MaxFlatWorkGroupSize[] = "MaxFlatWorkGroupSize";
265/// Key for Kernel::CodeProps::Metadata::mIsDynamicCallStack.
266constexpr char IsDynamicCallStack[] = "IsDynamicCallStack";
267/// Key for Kernel::CodeProps::Metadata::mIsXNACKEnabled.
268constexpr char IsXNACKEnabled[] = "IsXNACKEnabled";
269/// Key for Kernel::CodeProps::Metadata::mNumSpilledSGPRs.
270constexpr char NumSpilledSGPRs[] = "NumSpilledSGPRs";
271/// Key for Kernel::CodeProps::Metadata::mNumSpilledVGPRs.
272constexpr char NumSpilledVGPRs[] = "NumSpilledVGPRs";
273} // end namespace Key
274
275/// In-memory representation of kernel code properties metadata.
276struct Metadata final {
277 /// Size in bytes of the kernarg segment memory. Kernarg segment memory
278 /// holds the values of the arguments to the kernel. Required.
279 uint64_t mKernargSegmentSize = 0;
280 /// Size in bytes of the group segment memory required by a workgroup.
281 /// This value does not include any dynamically allocated group segment memory
282 /// that may be added when the kernel is dispatched. Required.
283 uint32_t mGroupSegmentFixedSize = 0;
284 /// Size in bytes of the private segment memory required by a workitem.
285 /// Private segment memory includes arg, spill and private segments. Required.
286 uint32_t mPrivateSegmentFixedSize = 0;
287 /// Maximum byte alignment of variables used by the kernel in the
288 /// kernarg memory segment. Required.
289 uint32_t mKernargSegmentAlign = 0;
290 /// Wavefront size. Required.
291 uint32_t mWavefrontSize = 0;
292 /// Total number of SGPRs used by a wavefront. Optional.
293 uint16_t mNumSGPRs = 0;
294 /// Total number of VGPRs used by a workitem. Optional.
295 uint16_t mNumVGPRs = 0;
296 /// Maximum flat work-group size supported by the kernel. Optional.
297 uint32_t mMaxFlatWorkGroupSize = 0;
298 /// True if the generated machine code is using a dynamically sized
299 /// call stack. Optional.
300 bool mIsDynamicCallStack = false;
301 /// True if the generated machine code is capable of supporting XNACK.
302 /// Optional.
303 bool mIsXNACKEnabled = false;
304 /// Number of SGPRs spilled by a wavefront. Optional.
305 uint16_t mNumSpilledSGPRs = 0;
306 /// Number of VGPRs spilled by a workitem. Optional.
307 uint16_t mNumSpilledVGPRs = 0;
308
309 /// Default constructor.
310 Metadata() = default;
311
312 /// \returns True if kernel code properties metadata is empty, false
313 /// otherwise.
314 bool empty() const {
315 return !notEmpty();
316 }
317
318 /// \returns True if kernel code properties metadata is not empty, false
319 /// otherwise.
320 bool notEmpty() const {
321 return true;
322 }
323};
324
325} // end namespace CodeProps
326
327//===----------------------------------------------------------------------===//
328// Kernel Debug Properties Metadata.
329//===----------------------------------------------------------------------===//
330namespace DebugProps {
331
332namespace Key {
333/// Key for Kernel::DebugProps::Metadata::mDebuggerABIVersion.
334constexpr char DebuggerABIVersion[] = "DebuggerABIVersion";
335/// Key for Kernel::DebugProps::Metadata::mReservedNumVGPRs.
336constexpr char ReservedNumVGPRs[] = "ReservedNumVGPRs";
337/// Key for Kernel::DebugProps::Metadata::mReservedFirstVGPR.
338constexpr char ReservedFirstVGPR[] = "ReservedFirstVGPR";
339/// Key for Kernel::DebugProps::Metadata::mPrivateSegmentBufferSGPR.
340constexpr char PrivateSegmentBufferSGPR[] = "PrivateSegmentBufferSGPR";
341/// Key for
342/// Kernel::DebugProps::Metadata::mWavefrontPrivateSegmentOffsetSGPR.
343constexpr char WavefrontPrivateSegmentOffsetSGPR[] =
344 "WavefrontPrivateSegmentOffsetSGPR";
345} // end namespace Key
346
347/// In-memory representation of kernel debug properties metadata.
348struct Metadata final {
349 /// Debugger ABI version. Optional.
350 std::vector<uint32_t> mDebuggerABIVersion = std::vector<uint32_t>();
351 /// Consecutive number of VGPRs reserved for debugger use. Must be 0 if
352 /// mDebuggerABIVersion is not set. Optional.
353 uint16_t mReservedNumVGPRs = 0;
354 /// First fixed VGPR reserved. Must be uint16_t(-1) if
355 /// mDebuggerABIVersion is not set or mReservedFirstVGPR is 0. Optional.
356 uint16_t mReservedFirstVGPR = uint16_t(-1);
357 /// Fixed SGPR of the first of 4 SGPRs used to hold the scratch V# used
358 /// for the entire kernel execution. Must be uint16_t(-1) if
359 /// mDebuggerABIVersion is not set or SGPR not used or not known. Optional.
360 uint16_t mPrivateSegmentBufferSGPR = uint16_t(-1);
361 /// Fixed SGPR used to hold the wave scratch offset for the entire
362 /// kernel execution. Must be uint16_t(-1) if mDebuggerABIVersion is not set
363 /// or SGPR is not used or not known. Optional.
364 uint16_t mWavefrontPrivateSegmentOffsetSGPR = uint16_t(-1);
365
366 /// Default constructor.
367 Metadata() = default;
368
369 /// \returns True if kernel debug properties metadata is empty, false
370 /// otherwise.
371 bool empty() const {
372 return !notEmpty();
373 }
374
375 /// \returns True if kernel debug properties metadata is not empty, false
376 /// otherwise.
377 bool notEmpty() const {
378 return !mDebuggerABIVersion.empty();
379 }
380};
381
382} // end namespace DebugProps
383
384namespace Key {
385/// Key for Kernel::Metadata::mName.
386constexpr char Name[] = "Name";
387/// Key for Kernel::Metadata::mSymbolName.
388constexpr char SymbolName[] = "SymbolName";
389/// Key for Kernel::Metadata::mLanguage.
390constexpr char Language[] = "Language";
391/// Key for Kernel::Metadata::mLanguageVersion.
392constexpr char LanguageVersion[] = "LanguageVersion";
393/// Key for Kernel::Metadata::mAttrs.
394constexpr char Attrs[] = "Attrs";
395/// Key for Kernel::Metadata::mArgs.
396constexpr char Args[] = "Args";
397/// Key for Kernel::Metadata::mCodeProps.
398constexpr char CodeProps[] = "CodeProps";
399/// Key for Kernel::Metadata::mDebugProps.
400constexpr char DebugProps[] = "DebugProps";
401} // end namespace Key
402
403/// In-memory representation of kernel metadata.
404struct Metadata final {
405 /// Kernel source name. Required.
406 std::string mName = std::string();
407 /// Kernel descriptor name. Required.
408 std::string mSymbolName = std::string();
409 /// Language. Optional.
410 std::string mLanguage = std::string();
411 /// Language version. Optional.
412 std::vector<uint32_t> mLanguageVersion = std::vector<uint32_t>();
413 /// Attributes metadata. Optional.
414 Attrs::Metadata mAttrs = Attrs::Metadata();
415 /// Arguments metadata. Optional.
416 std::vector<Arg::Metadata> mArgs = std::vector<Arg::Metadata>();
417 /// Code properties metadata. Optional.
418 CodeProps::Metadata mCodeProps = CodeProps::Metadata();
419 /// Debug properties metadata. Optional.
420 DebugProps::Metadata mDebugProps = DebugProps::Metadata();
421
422 /// Default constructor.
423 Metadata() = default;
424};
425
426} // end namespace Kernel
427
428namespace Key {
429/// Key for HSA::Metadata::mVersion.
430constexpr char Version[] = "Version";
431/// Key for HSA::Metadata::mPrintf.
432constexpr char Printf[] = "Printf";
433/// Key for HSA::Metadata::mKernels.
434constexpr char Kernels[] = "Kernels";
435} // end namespace Key
436
437/// In-memory representation of HSA metadata.
438struct Metadata final {
439 /// HSA metadata version. Required.
440 std::vector<uint32_t> mVersion = std::vector<uint32_t>();
441 /// Printf metadata. Optional.
442 std::vector<std::string> mPrintf = std::vector<std::string>();
443 /// Kernels metadata. Required.
444 std::vector<Kernel::Metadata> mKernels = std::vector<Kernel::Metadata>();
445
446 /// Default constructor.
447 Metadata() = default;
448};
449
450/// Converts \p String to \p HSAMetadata.
451LLVM_ABI std::error_code fromString(StringRef String, Metadata &HSAMetadata);
452
453/// Converts \p HSAMetadata to \p String.
454LLVM_ABI std::error_code toString(Metadata HSAMetadata, std::string &String);
455
456//===----------------------------------------------------------------------===//
457// HSA metadata for v3 code object.
458//===----------------------------------------------------------------------===//
459namespace V3 {
460/// HSA metadata major version.
461constexpr uint32_t VersionMajor = 1;
462/// HSA metadata minor version.
463constexpr uint32_t VersionMinor = 0;
464
465/// HSA metadata beginning assembler directive.
466constexpr char AssemblerDirectiveBegin[] = ".amdgpu_metadata";
467/// HSA metadata ending assembler directive.
468constexpr char AssemblerDirectiveEnd[] = ".end_amdgpu_metadata";
469} // end namespace V3
470
471} // end namespace HSAMD
472
473//===----------------------------------------------------------------------===//
474// PAL metadata.
475//===----------------------------------------------------------------------===//
476namespace PALMD {
477
478/// PAL metadata (old linear format) assembler directive.
479constexpr char AssemblerDirective[] = ".amd_amdgpu_pal_metadata";
480
481/// PAL metadata (new MsgPack format) beginning assembler directive.
482constexpr char AssemblerDirectiveBegin[] = ".amdgpu_pal_metadata";
483
484/// PAL metadata (new MsgPack format) ending assembler directive.
485constexpr char AssemblerDirectiveEnd[] = ".end_amdgpu_pal_metadata";
486
487/// PAL metadata keys.
488enum Key : uint32_t {
489 R_2E12_COMPUTE_PGM_RSRC1 = 0x2e12,
490 R_2D4A_SPI_SHADER_PGM_RSRC1_LS = 0x2d4a,
491 R_2D0A_SPI_SHADER_PGM_RSRC1_HS = 0x2d0a,
492 R_2CCA_SPI_SHADER_PGM_RSRC1_ES = 0x2cca,
493 R_2C8A_SPI_SHADER_PGM_RSRC1_GS = 0x2c8a,
494 R_2C4A_SPI_SHADER_PGM_RSRC1_VS = 0x2c4a,
495 R_2C0A_SPI_SHADER_PGM_RSRC1_PS = 0x2c0a,
496 R_2E00_COMPUTE_DISPATCH_INITIATOR = 0x2e00,
497 R_A1B3_SPI_PS_INPUT_ENA = 0xa1b3,
498 R_A1B4_SPI_PS_INPUT_ADDR = 0xa1b4,
499 R_A1B6_SPI_PS_IN_CONTROL = 0xa1b6,
500 R_A2D5_VGT_SHADER_STAGES_EN = 0xa2d5,
501
502 LS_NUM_USED_VGPRS = 0x10000021,
503 HS_NUM_USED_VGPRS = 0x10000022,
504 ES_NUM_USED_VGPRS = 0x10000023,
505 GS_NUM_USED_VGPRS = 0x10000024,
506 VS_NUM_USED_VGPRS = 0x10000025,
507 PS_NUM_USED_VGPRS = 0x10000026,
508 CS_NUM_USED_VGPRS = 0x10000027,
509
510 LS_NUM_USED_SGPRS = 0x10000028,
511 HS_NUM_USED_SGPRS = 0x10000029,
512 ES_NUM_USED_SGPRS = 0x1000002a,
513 GS_NUM_USED_SGPRS = 0x1000002b,
514 VS_NUM_USED_SGPRS = 0x1000002c,
515 PS_NUM_USED_SGPRS = 0x1000002d,
516 CS_NUM_USED_SGPRS = 0x1000002e,
517
518 LS_SCRATCH_SIZE = 0x10000044,
519 HS_SCRATCH_SIZE = 0x10000045,
520 ES_SCRATCH_SIZE = 0x10000046,
521 GS_SCRATCH_SIZE = 0x10000047,
522 VS_SCRATCH_SIZE = 0x10000048,
523 PS_SCRATCH_SIZE = 0x10000049,
524 CS_SCRATCH_SIZE = 0x1000004a
525};
526
527} // end namespace PALMD
528} // end namespace AMDGPU
529} // end namespace llvm
530
531#endif // LLVM_SUPPORT_AMDGPUMETADATA_H
532

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of llvm/include/llvm/Support/AMDGPUMetadata.h