blob: 78c8754117f05cce62a57678627bb49c46787260 [file] [log] [blame]
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +00001//===--- AMDGPUCodeObjectMetadata.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 Code Object Metadata definitions and in-memory
12/// representations.
13///
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATA_H
18#define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATA_H
19
20#include <cstdint>
21#include <string>
22#include <system_error>
23#include <vector>
24
25namespace llvm {
26namespace AMDGPU {
27
28//===----------------------------------------------------------------------===//
29// Code Object Metadata.
30//===----------------------------------------------------------------------===//
31namespace CodeObject {
32
33/// \brief Code object metadata major version.
34constexpr uint32_t MetadataVersionMajor = 1;
35/// \brief Code object metadata minor version.
36constexpr uint32_t MetadataVersionMinor = 0;
37
38/// \brief Code object metadata beginning assembler directive.
39constexpr char MetadataAssemblerDirectiveBegin[] =
40 ".amdgpu_code_object_metadata";
41/// \brief Code object metadata ending assembler directive.
42constexpr char MetadataAssemblerDirectiveEnd[] =
43 ".end_amdgpu_code_object_metadata";
44
45/// \brief Access qualifiers.
46enum class AccessQualifier : uint8_t {
47 Default = 0,
48 ReadOnly = 1,
49 WriteOnly = 2,
50 ReadWrite = 3,
51 Unknown = 0xff
52};
53
54/// \brief Address space qualifiers.
55enum class AddressSpaceQualifier : uint8_t {
56 Private = 0,
57 Global = 1,
58 Constant = 2,
59 Local = 3,
60 Generic = 4,
61 Region = 5,
62 Unknown = 0xff
63};
64
65/// \brief Value kinds.
66enum class ValueKind : uint8_t {
67 ByValue = 0,
68 GlobalBuffer = 1,
69 DynamicSharedPointer = 2,
70 Sampler = 3,
71 Image = 4,
72 Pipe = 5,
73 Queue = 6,
74 HiddenGlobalOffsetX = 7,
75 HiddenGlobalOffsetY = 8,
76 HiddenGlobalOffsetZ = 9,
77 HiddenNone = 10,
78 HiddenPrintfBuffer = 11,
79 HiddenDefaultQueue = 12,
80 HiddenCompletionAction = 13,
81 Unknown = 0xff
82};
83
84/// \brief Value types.
85enum class ValueType : uint8_t {
86 Struct = 0,
87 I8 = 1,
88 U8 = 2,
89 I16 = 3,
90 U16 = 4,
91 F16 = 5,
92 I32 = 6,
93 U32 = 7,
94 F32 = 8,
95 I64 = 9,
96 U64 = 10,
97 F64 = 11,
98 Unknown = 0xff
99};
100
101//===----------------------------------------------------------------------===//
102// Instruction Set Architecture Metadata (ISA).
103//===----------------------------------------------------------------------===//
104namespace Isa {
105
106namespace Key {
107/// \brief Key for Isa::Metadata::mWavefrontSize.
108constexpr char WavefrontSize[] = "WavefrontSize";
109/// \brief Key for Isa::Metadata::mLocalMemorySize.
110constexpr char LocalMemorySize[] = "LocalMemorySize";
111/// \brief Key for Isa::Metadata::mEUsPerCU.
112constexpr char EUsPerCU[] = "EUsPerCU";
113/// \brief Key for Isa::Metadata::mMaxWavesPerEU.
114constexpr char MaxWavesPerEU[] = "MaxWavesPerEU";
115/// \brief Key for Isa::Metadata::mMaxFlatWorkGroupSize.
116constexpr char MaxFlatWorkGroupSize[] = "MaxFlatWorkGroupSize";
117/// \brief Key for Isa::Metadata::mSGPRAllocGranule.
118constexpr char SGPRAllocGranule[] = "SGPRAllocGranule";
119/// \brief Key for Isa::Metadata::mTotalNumSGPRs.
120constexpr char TotalNumSGPRs[] = "TotalNumSGPRs";
121/// \brief Key for Isa::Metadata::mAddressableNumSGPRs.
122constexpr char AddressableNumSGPRs[] = "AddressableNumSGPRs";
123/// \brief Key for Isa::Metadata::mVGPRAllocGranule.
124constexpr char VGPRAllocGranule[] = "VGPRAllocGranule";
125/// \brief Key for Isa::Metadata::mTotalNumVGPRs.
126constexpr char TotalNumVGPRs[] = "TotalNumVGPRs";
127/// \brief Key for Isa::Metadata::mAddressableNumVGPRs.
128constexpr char AddressableNumVGPRs[] = "AddressableNumVGPRs";
129} // end namespace Key
130
131/// \brief In-memory representation of instruction set architecture metadata.
132struct Metadata final {
133 /// \brief Wavefront size. Required.
134 uint32_t mWavefrontSize = 0;
135 /// \brief Local memory size in bytes. Required.
136 uint32_t mLocalMemorySize = 0;
137 /// \brief Number of execution units per compute unit. Required.
138 uint32_t mEUsPerCU = 0;
139 /// \brief Maximum number of waves per execution unit. Required.
140 uint32_t mMaxWavesPerEU = 0;
141 /// \brief Maximum flat work group size. Required.
142 uint32_t mMaxFlatWorkGroupSize = 0;
143 /// \brief SGPR allocation granularity. Required.
144 uint32_t mSGPRAllocGranule = 0;
145 /// \brief Total number of SGPRs. Required.
146 uint32_t mTotalNumSGPRs = 0;
147 /// \brief Addressable number of SGPRs. Required.
148 uint32_t mAddressableNumSGPRs = 0;
149 /// \brief VGPR allocation granularity. Required.
150 uint32_t mVGPRAllocGranule = 0;
151 /// \brief Total number of VGPRs. Required.
152 uint32_t mTotalNumVGPRs = 0;
153 /// \brief Addressable number of VGPRs. Required.
154 uint32_t mAddressableNumVGPRs = 0;
155
156 /// \brief Default constructor.
157 Metadata() = default;
158};
159
160} // end namespace Isa
161
162//===----------------------------------------------------------------------===//
163// Kernel Metadata.
164//===----------------------------------------------------------------------===//
165namespace Kernel {
166
167//===----------------------------------------------------------------------===//
168// Kernel Attributes Metadata.
169//===----------------------------------------------------------------------===//
170namespace Attrs {
171
172namespace Key {
173/// \brief Key for Kernel::Attr::Metadata::mReqdWorkGroupSize.
174constexpr char ReqdWorkGroupSize[] = "ReqdWorkGroupSize";
175/// \brief Key for Kernel::Attr::Metadata::mWorkGroupSizeHint.
176constexpr char WorkGroupSizeHint[] = "WorkGroupSizeHint";
177/// \brief Key for Kernel::Attr::Metadata::mVecTypeHint.
178constexpr char VecTypeHint[] = "VecTypeHint";
179} // end namespace Key
180
181/// \brief In-memory representation of kernel attributes metadata.
182struct Metadata final {
183 /// \brief 'reqd_work_group_size' attribute. Optional.
184 std::vector<uint32_t> mReqdWorkGroupSize = std::vector<uint32_t>();
185 /// \brief 'work_group_size_hint' attribute. Optional.
186 std::vector<uint32_t> mWorkGroupSizeHint = std::vector<uint32_t>();
187 /// \brief 'vec_type_hint' attribute. Optional.
188 std::string mVecTypeHint = std::string();
189
190 /// \brief Default constructor.
191 Metadata() = default;
192
193 /// \returns True if kernel attributes metadata is empty, false otherwise.
194 bool empty() const {
195 return mReqdWorkGroupSize.empty() &&
196 mWorkGroupSizeHint.empty() &&
197 mVecTypeHint.empty();
198 }
199
200 /// \returns True if kernel attributes metadata is not empty, false otherwise.
201 bool notEmpty() const {
202 return !empty();
203 }
204};
205
206} // end namespace Attrs
207
208//===----------------------------------------------------------------------===//
209// Kernel Argument Metadata.
210//===----------------------------------------------------------------------===//
211namespace Arg {
212
213namespace Key {
214/// \brief Key for Kernel::Arg::Metadata::mSize.
215constexpr char Size[] = "Size";
216/// \brief Key for Kernel::Arg::Metadata::mAlign.
217constexpr char Align[] = "Align";
218/// \brief Key for Kernel::Arg::Metadata::mValueKind.
219constexpr char Kind[] = "Kind";
220/// \brief Key for Kernel::Arg::Metadata::mValueType.
221constexpr char ValueType[] = "ValueType";
222/// \brief Key for Kernel::Arg::Metadata::mPointeeAlign.
223constexpr char PointeeAlign[] = "PointeeAlign";
224/// \brief Key for Kernel::Arg::Metadata::mAccQual.
225constexpr char AccQual[] = "AccQual";
226/// \brief Key for Kernel::Arg::Metadata::mAddrSpaceQual.
227constexpr char AddrSpaceQual[] = "AddrSpaceQual";
228/// \brief Key for Kernel::Arg::Metadata::mIsConst.
229constexpr char IsConst[] = "IsConst";
230/// \brief Key for Kernel::Arg::Metadata::mIsPipe.
231constexpr char IsPipe[] = "IsPipe";
232/// \brief Key for Kernel::Arg::Metadata::mIsRestrict.
233constexpr char IsRestrict[] = "IsRestrict";
234/// \brief Key for Kernel::Arg::Metadata::mIsVolatile.
235constexpr char IsVolatile[] = "IsVolatile";
236/// \brief Key for Kernel::Arg::Metadata::mName.
237constexpr char Name[] = "Name";
238/// \brief Key for Kernel::Arg::Metadata::mTypeName.
239constexpr char TypeName[] = "TypeName";
240} // end namespace Key
241
242/// \brief In-memory representation of kernel argument metadata.
243struct Metadata final {
244 /// \brief Size in bytes. Required.
245 uint32_t mSize = 0;
246 /// \brief Alignment in bytes. Required.
247 uint32_t mAlign = 0;
248 /// \brief Value kind. Required.
249 ValueKind mValueKind = ValueKind::Unknown;
250 /// \brief Value type. Required.
251 ValueType mValueType = ValueType::Unknown;
252 /// \brief Pointee alignment in bytes. Optional.
253 uint32_t mPointeeAlign = 0;
254 /// \brief Access qualifier. Optional.
255 AccessQualifier mAccQual = AccessQualifier::Unknown;
256 /// \brief Address space qualifier. Optional.
257 AddressSpaceQualifier mAddrSpaceQual = AddressSpaceQualifier::Unknown;
258 /// \brief True if 'const' qualifier is specified. Optional.
259 bool mIsConst = false;
260 /// \brief True if 'pipe' qualifier is specified. Optional.
261 bool mIsPipe = false;
262 /// \brief True if 'restrict' qualifier is specified. Optional.
263 bool mIsRestrict = false;
264 /// \brief True if 'volatile' qualifier is specified. Optional.
265 bool mIsVolatile = false;
266 /// \brief Name. Optional.
267 std::string mName = std::string();
268 /// \brief Type name. Optional.
269 std::string mTypeName = std::string();
270
271 /// \brief Default constructor.
272 Metadata() = default;
273};
274
275} // end namespace Arg
276
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000277//===----------------------------------------------------------------------===//
278// Kernel Code Properties Metadata.
279//===----------------------------------------------------------------------===//
280namespace CodeProps {
281
282namespace Key {
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000283/// \brief Key for Kernel::CodeProps::Metadata::mKernargSegmentSize.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000284constexpr char KernargSegmentSize[] = "KernargSegmentSize";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000285/// \brief Key for Kernel::CodeProps::Metadata::mWorkgroupGroupSegmentSize.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000286constexpr char WorkgroupGroupSegmentSize[] = "WorkgroupGroupSegmentSize";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000287/// \brief Key for Kernel::CodeProps::Metadata::mWorkitemPrivateSegmentSize.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000288constexpr char WorkitemPrivateSegmentSize[] = "WorkitemPrivateSegmentSize";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000289/// \brief Key for Kernel::CodeProps::Metadata::mWavefrontNumSGPRs.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000290constexpr char WavefrontNumSGPRs[] = "WavefrontNumSGPRs";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000291/// \brief Key for Kernel::CodeProps::Metadata::mWorkitemNumVGPRs.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000292constexpr char WorkitemNumVGPRs[] = "WorkitemNumVGPRs";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000293/// \brief Key for Kernel::CodeProps::Metadata::mKernargSegmentAlign.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000294constexpr char KernargSegmentAlign[] = "KernargSegmentAlign";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000295/// \brief Key for Kernel::CodeProps::Metadata::mGroupSegmentAlign.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000296constexpr char GroupSegmentAlign[] = "GroupSegmentAlign";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000297/// \brief Key for Kernel::CodeProps::Metadata::mPrivateSegmentAlign.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000298constexpr char PrivateSegmentAlign[] = "PrivateSegmentAlign";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000299/// \brief Key for Kernel::CodeProps::Metadata::mWavefrontSize.
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000300constexpr char WavefrontSize[] = "WavefrontSize";
301} // end namespace Key
302
303/// \brief In-memory representation of kernel code properties metadata.
304struct Metadata final {
305 /// \brief Size in bytes of the kernarg segment memory. Kernarg segment memory
306 /// holds the values of the arguments to the kernel. Optional.
307 uint64_t mKernargSegmentSize = 0;
308 /// \brief Size in bytes of the group segment memory required by a workgroup.
309 /// This value does not include any dynamically allocated group segment memory
310 /// that may be added when the kernel is dispatched. Optional.
311 uint32_t mWorkgroupGroupSegmentSize = 0;
312 /// \brief Size in bytes of the private segment memory required by a workitem.
313 /// Private segment memory includes arg, spill and private segments. Optional.
314 uint32_t mWorkitemPrivateSegmentSize = 0;
315 /// \brief Total number of SGPRs used by a wavefront. Optional.
316 uint16_t mWavefrontNumSGPRs = 0;
317 /// \brief Total number of VGPRs used by a workitem. Optional.
318 uint16_t mWorkitemNumVGPRs = 0;
319 /// \brief Maximum byte alignment of variables used by the kernel in the
320 /// kernarg memory segment. Expressed as a power of two. Optional.
321 uint8_t mKernargSegmentAlign = 0;
322 /// \brief Maximum byte alignment of variables used by the kernel in the
323 /// group memory segment. Expressed as a power of two. Optional.
324 uint8_t mGroupSegmentAlign = 0;
325 /// \brief Maximum byte alignment of variables used by the kernel in the
326 /// private memory segment. Expressed as a power of two. Optional.
327 uint8_t mPrivateSegmentAlign = 0;
328 /// \brief Wavefront size. Expressed as a power of two. Optional.
329 uint8_t mWavefrontSize = 0;
330
331 /// \brief Default constructor.
332 Metadata() = default;
333
334 /// \returns True if kernel code properties metadata is empty, false
335 /// otherwise.
336 bool empty() const {
337 return !notEmpty();
338 }
339
340 /// \returns True if kernel code properties metadata is not empty, false
341 /// otherwise.
342 bool notEmpty() const {
343 return mKernargSegmentSize || mWorkgroupGroupSegmentSize ||
344 mWorkitemPrivateSegmentSize || mWavefrontNumSGPRs ||
345 mWorkitemNumVGPRs || mKernargSegmentAlign || mGroupSegmentAlign ||
346 mPrivateSegmentAlign || mWavefrontSize;
347 }
348};
349
350} // end namespace CodeProps
351
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000352//===----------------------------------------------------------------------===//
353// Kernel Debug Properties Metadata.
354//===----------------------------------------------------------------------===//
355namespace DebugProps {
356
357namespace Key {
358/// \brief Key for Kernel::DebugProps::Metadata::mDebuggerABIVersion.
359constexpr char DebuggerABIVersion[] = "DebuggerABIVersion";
360/// \brief Key for Kernel::DebugProps::Metadata::mReservedNumVGPRs.
361constexpr char ReservedNumVGPRs[] = "ReservedNumVGPRs";
362/// \brief Key for Kernel::DebugProps::Metadata::mReservedFirstVGPR.
363constexpr char ReservedFirstVGPR[] = "ReservedFirstVGPR";
364/// \brief Key for Kernel::DebugProps::Metadata::mPrivateSegmentBufferSGPR.
365constexpr char PrivateSegmentBufferSGPR[] = "PrivateSegmentBufferSGPR";
366/// \brief Key for
367/// Kernel::DebugProps::Metadata::mWavefrontPrivateSegmentOffsetSGPR.
368constexpr char WavefrontPrivateSegmentOffsetSGPR[] =
369 "WavefrontPrivateSegmentOffsetSGPR";
370} // end namespace Key
371
372/// \brief In-memory representation of kernel debug properties metadata.
373struct Metadata final {
374 /// \brief Debugger ABI version. Optional.
375 std::vector<uint32_t> mDebuggerABIVersion = std::vector<uint32_t>();
376 /// \brief Consecutive number of VGPRs reserved for debugger use. Must be 0 if
377 /// mDebuggerABIVersion is not set. Optional.
378 uint16_t mReservedNumVGPRs = 0;
379 /// \brief First fixed VGPR reserved. Must be uint16_t(-1) if
380 /// mDebuggerABIVersion is not set or mReservedFirstVGPR is 0. Optional.
381 uint16_t mReservedFirstVGPR = uint16_t(-1);
382 /// \brief Fixed SGPR of the first of 4 SGPRs used to hold the scratch V# used
383 /// for the entire kernel execution. Must be uint16_t(-1) if
384 /// mDebuggerABIVersion is not set or SGPR not used or not known. Optional.
385 uint16_t mPrivateSegmentBufferSGPR = uint16_t(-1);
386 /// \brief Fixed SGPR used to hold the wave scratch offset for the entire
387 /// kernel execution. Must be uint16_t(-1) if mDebuggerABIVersion is not set
388 /// or SGPR is not used or not known. Optional.
389 uint16_t mWavefrontPrivateSegmentOffsetSGPR = uint16_t(-1);
390
391 /// \brief Default constructor.
392 Metadata() = default;
393
394 /// \returns True if kernel debug properties metadata is empty, false
395 /// otherwise.
396 bool empty() const {
397 return !notEmpty();
398 }
399
400 /// \returns True if kernel debug properties metadata is not empty, false
401 /// otherwise.
402 bool notEmpty() const {
403 return !mDebuggerABIVersion.empty();
404 }
405};
406
407} // end namespace DebugProps
408
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +0000409namespace Key {
410/// \brief Key for Kernel::Metadata::mName.
411constexpr char Name[] = "Name";
412/// \brief Key for Kernel::Metadata::mLanguage.
413constexpr char Language[] = "Language";
414/// \brief Key for Kernel::Metadata::mLanguageVersion.
415constexpr char LanguageVersion[] = "LanguageVersion";
416/// \brief Key for Kernel::Metadata::mAttrs.
417constexpr char Attrs[] = "Attrs";
418/// \brief Key for Kernel::Metadata::mArgs.
419constexpr char Args[] = "Args";
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000420/// \brief Key for Kernel::Metadata::mCodeProps.
421constexpr char CodeProps[] = "CodeProps";
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000422/// \brief Key for Kernel::Metadata::mDebugProps.
423constexpr char DebugProps[] = "DebugProps";
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +0000424} // end namespace Key
425
426/// \brief In-memory representation of kernel metadata.
427struct Metadata final {
428 /// \brief Name. Required.
429 std::string mName = std::string();
430 /// \brief Language. Optional.
431 std::string mLanguage = std::string();
432 /// \brief Language version. Optional.
433 std::vector<uint32_t> mLanguageVersion = std::vector<uint32_t>();
434 /// \brief Attributes metadata. Optional.
435 Attrs::Metadata mAttrs = Attrs::Metadata();
436 /// \brief Arguments metadata. Optional.
437 std::vector<Arg::Metadata> mArgs = std::vector<Arg::Metadata>();
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +0000438 /// \brief Code properties metadata. Optional.
439 CodeProps::Metadata mCodeProps = CodeProps::Metadata();
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +0000440 /// \brief Debug properties metadata. Optional.
441 DebugProps::Metadata mDebugProps = DebugProps::Metadata();
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +0000442
443 /// \brief Default constructor.
444 Metadata() = default;
445};
446
447} // end namespace Kernel
448
449namespace Key {
450/// \brief Key for CodeObject::Metadata::mVersion.
451constexpr char Version[] = "Version";
452/// \brief Key for CodeObject::Metadata::mIsa.
453constexpr char Isa[] = "Isa";
454/// \brief Key for CodeObject::Metadata::mPrintf.
455constexpr char Printf[] = "Printf";
456/// \brief Key for CodeObject::Metadata::mKernels.
457constexpr char Kernels[] = "Kernels";
458} // end namespace Key
459
460/// \brief In-memory representation of code object metadata.
461struct Metadata final {
462 /// \brief Code object metadata version. Required.
463 std::vector<uint32_t> mVersion = std::vector<uint32_t>();
464 /// \brief Instruction set architecture metadata. Optional.
465 Isa::Metadata mIsa = Isa::Metadata();
466 /// \brief Printf metadata. Optional.
467 std::vector<std::string> mPrintf = std::vector<std::string>();
468 /// \brief Kernels metadata. Optional.
469 std::vector<Kernel::Metadata> mKernels = std::vector<Kernel::Metadata>();
470
471 /// \brief Default constructor.
472 Metadata() = default;
473
474 /// \brief Converts \p YamlString to \p CodeObjectMetadata.
475 static std::error_code fromYamlString(std::string YamlString,
476 Metadata &CodeObjectMetadata);
477
478 /// \brief Converts \p CodeObjectMetadata to \p YamlString.
479 static std::error_code toYamlString(Metadata CodeObjectMetadata,
480 std::string &YamlString);
481};
482
483} // end namespace CodeObject
484} // end namespace AMDGPU
485} // end namespace llvm
486
487#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATA_H