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