blob: d25f131529a9d7c1922c4cef4e470f75e1a92cdc [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
277namespace Key {
278/// \brief Key for Kernel::Metadata::mName.
279constexpr char Name[] = "Name";
280/// \brief Key for Kernel::Metadata::mLanguage.
281constexpr char Language[] = "Language";
282/// \brief Key for Kernel::Metadata::mLanguageVersion.
283constexpr char LanguageVersion[] = "LanguageVersion";
284/// \brief Key for Kernel::Metadata::mAttrs.
285constexpr char Attrs[] = "Attrs";
286/// \brief Key for Kernel::Metadata::mArgs.
287constexpr char Args[] = "Args";
288} // end namespace Key
289
290/// \brief In-memory representation of kernel metadata.
291struct Metadata final {
292 /// \brief Name. Required.
293 std::string mName = std::string();
294 /// \brief Language. Optional.
295 std::string mLanguage = std::string();
296 /// \brief Language version. Optional.
297 std::vector<uint32_t> mLanguageVersion = std::vector<uint32_t>();
298 /// \brief Attributes metadata. Optional.
299 Attrs::Metadata mAttrs = Attrs::Metadata();
300 /// \brief Arguments metadata. Optional.
301 std::vector<Arg::Metadata> mArgs = std::vector<Arg::Metadata>();
302
303 /// \brief Default constructor.
304 Metadata() = default;
305};
306
307} // end namespace Kernel
308
309namespace Key {
310/// \brief Key for CodeObject::Metadata::mVersion.
311constexpr char Version[] = "Version";
312/// \brief Key for CodeObject::Metadata::mIsa.
313constexpr char Isa[] = "Isa";
314/// \brief Key for CodeObject::Metadata::mPrintf.
315constexpr char Printf[] = "Printf";
316/// \brief Key for CodeObject::Metadata::mKernels.
317constexpr char Kernels[] = "Kernels";
318} // end namespace Key
319
320/// \brief In-memory representation of code object metadata.
321struct Metadata final {
322 /// \brief Code object metadata version. Required.
323 std::vector<uint32_t> mVersion = std::vector<uint32_t>();
324 /// \brief Instruction set architecture metadata. Optional.
325 Isa::Metadata mIsa = Isa::Metadata();
326 /// \brief Printf metadata. Optional.
327 std::vector<std::string> mPrintf = std::vector<std::string>();
328 /// \brief Kernels metadata. Optional.
329 std::vector<Kernel::Metadata> mKernels = std::vector<Kernel::Metadata>();
330
331 /// \brief Default constructor.
332 Metadata() = default;
333
334 /// \brief Converts \p YamlString to \p CodeObjectMetadata.
335 static std::error_code fromYamlString(std::string YamlString,
336 Metadata &CodeObjectMetadata);
337
338 /// \brief Converts \p CodeObjectMetadata to \p YamlString.
339 static std::error_code toYamlString(Metadata CodeObjectMetadata,
340 std::string &YamlString);
341};
342
343} // end namespace CodeObject
344} // end namespace AMDGPU
345} // end namespace llvm
346
347#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATA_H