LLVM  5.0.0
AMDGPUCodeObjectMetadata.cpp
Go to the documentation of this file.
1 //===--- AMDGPUCodeObjectMetadata.cpp ---------------------------*- 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 
19 
20 using namespace llvm::AMDGPU;
21 using namespace llvm::AMDGPU::CodeObject;
22 
25 
26 namespace llvm {
27 namespace yaml {
28 
29 template <>
31  static void enumeration(IO &YIO, AccessQualifier &EN) {
32  YIO.enumCase(EN, "Default", AccessQualifier::Default);
33  YIO.enumCase(EN, "ReadOnly", AccessQualifier::ReadOnly);
34  YIO.enumCase(EN, "WriteOnly", AccessQualifier::WriteOnly);
35  YIO.enumCase(EN, "ReadWrite", AccessQualifier::ReadWrite);
36  }
37 };
38 
39 template <>
41  static void enumeration(IO &YIO, AddressSpaceQualifier &EN) {
42  YIO.enumCase(EN, "Private", AddressSpaceQualifier::Private);
43  YIO.enumCase(EN, "Global", AddressSpaceQualifier::Global);
44  YIO.enumCase(EN, "Constant", AddressSpaceQualifier::Constant);
45  YIO.enumCase(EN, "Local", AddressSpaceQualifier::Local);
46  YIO.enumCase(EN, "Generic", AddressSpaceQualifier::Generic);
47  YIO.enumCase(EN, "Region", AddressSpaceQualifier::Region);
48  }
49 };
50 
51 template <>
53  static void enumeration(IO &YIO, ValueKind &EN) {
54  YIO.enumCase(EN, "ByValue", ValueKind::ByValue);
55  YIO.enumCase(EN, "GlobalBuffer", ValueKind::GlobalBuffer);
56  YIO.enumCase(EN, "DynamicSharedPointer", ValueKind::DynamicSharedPointer);
57  YIO.enumCase(EN, "Sampler", ValueKind::Sampler);
58  YIO.enumCase(EN, "Image", ValueKind::Image);
59  YIO.enumCase(EN, "Pipe", ValueKind::Pipe);
60  YIO.enumCase(EN, "Queue", ValueKind::Queue);
61  YIO.enumCase(EN, "HiddenGlobalOffsetX", ValueKind::HiddenGlobalOffsetX);
62  YIO.enumCase(EN, "HiddenGlobalOffsetY", ValueKind::HiddenGlobalOffsetY);
63  YIO.enumCase(EN, "HiddenGlobalOffsetZ", ValueKind::HiddenGlobalOffsetZ);
64  YIO.enumCase(EN, "HiddenNone", ValueKind::HiddenNone);
65  YIO.enumCase(EN, "HiddenPrintfBuffer", ValueKind::HiddenPrintfBuffer);
66  YIO.enumCase(EN, "HiddenDefaultQueue", ValueKind::HiddenDefaultQueue);
67  YIO.enumCase(EN, "HiddenCompletionAction",
69  }
70 };
71 
72 template <>
74  static void enumeration(IO &YIO, ValueType &EN) {
75  YIO.enumCase(EN, "Struct", ValueType::Struct);
76  YIO.enumCase(EN, "I8", ValueType::I8);
77  YIO.enumCase(EN, "U8", ValueType::U8);
78  YIO.enumCase(EN, "I16", ValueType::I16);
79  YIO.enumCase(EN, "U16", ValueType::U16);
80  YIO.enumCase(EN, "F16", ValueType::F16);
81  YIO.enumCase(EN, "I32", ValueType::I32);
82  YIO.enumCase(EN, "U32", ValueType::U32);
83  YIO.enumCase(EN, "F32", ValueType::F32);
84  YIO.enumCase(EN, "I64", ValueType::I64);
85  YIO.enumCase(EN, "U64", ValueType::U64);
86  YIO.enumCase(EN, "F64", ValueType::F64);
87  }
88 };
89 
90 template <>
91 struct MappingTraits<Kernel::Attrs::Metadata> {
92  static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD) {
94  MD.mReqdWorkGroupSize, std::vector<uint32_t>());
96  MD.mWorkGroupSizeHint, std::vector<uint32_t>());
98  MD.mVecTypeHint, std::string());
99  }
100 };
101 
102 template <>
103 struct MappingTraits<Kernel::Arg::Metadata> {
104  static void mapping(IO &YIO, Kernel::Arg::Metadata &MD) {
110  uint32_t(0));
119  YIO.mapOptional(Kernel::Arg::Key::Name, MD.mName, std::string());
120  YIO.mapOptional(Kernel::Arg::Key::TypeName, MD.mTypeName, std::string());
121  }
122 };
123 
124 template <>
125 struct MappingTraits<Kernel::CodeProps::Metadata> {
126  static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD) {
128  MD.mKernargSegmentSize, uint64_t(0));
134  MD.mWavefrontNumSGPRs, uint16_t(0));
136  MD.mWorkitemNumVGPRs, uint16_t(0));
138  MD.mKernargSegmentAlign, uint8_t(0));
140  MD.mGroupSegmentAlign, uint8_t(0));
142  MD.mPrivateSegmentAlign, uint8_t(0));
144  MD.mWavefrontSize, uint8_t(0));
145  }
146 };
147 
148 template <>
149 struct MappingTraits<Kernel::DebugProps::Metadata> {
150  static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD) {
152  MD.mDebuggerABIVersion, std::vector<uint32_t>());
154  MD.mReservedNumVGPRs, uint16_t(0));
156  MD.mReservedFirstVGPR, uint16_t(-1));
158  MD.mPrivateSegmentBufferSGPR, uint16_t(-1));
160  MD.mWavefrontPrivateSegmentOffsetSGPR, uint16_t(-1));
161  }
162 };
163 
164 template <>
166  static void mapping(IO &YIO, Kernel::Metadata &MD) {
168  YIO.mapOptional(Kernel::Key::Language, MD.mLanguage, std::string());
170  std::vector<uint32_t>());
171  if (!MD.mAttrs.empty() || !YIO.outputting())
173  if (!MD.mArgs.empty() || !YIO.outputting())
175  if (!MD.mCodeProps.empty() || !YIO.outputting())
177  if (!MD.mDebugProps.empty() || !YIO.outputting())
179  }
180 };
181 
182 template <>
183 struct MappingTraits<CodeObject::Metadata> {
184  static void mapping(IO &YIO, CodeObject::Metadata &MD) {
186  YIO.mapOptional(Key::Printf, MD.mPrintf, std::vector<std::string>());
187  if (!MD.mKernels.empty() || !YIO.outputting())
189  }
190 };
191 
192 } // end namespace yaml
193 
194 namespace AMDGPU {
195 namespace CodeObject {
196 
197 /* static */
198 std::error_code Metadata::fromYamlString(
199  std::string YamlString, Metadata &CodeObjectMetadata) {
200  yaml::Input YamlInput(YamlString);
201  YamlInput >> CodeObjectMetadata;
202  return YamlInput.error();
203 }
204 
205 /* static */
206 std::error_code Metadata::toYamlString(
207  Metadata CodeObjectMetadata, std::string &YamlString) {
208  raw_string_ostream YamlStream(YamlString);
209  yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
210  YamlOutput << CodeObjectMetadata;
211  return std::error_code();
212 }
213 
214 } // end namespace CodeObject
215 } // end namespace AMDGPU
216 } // end namespace llvm
std::vector< uint32_t > mDebuggerABIVersion
Debugger ABI version. Optional.
static std::error_code toYamlString(Metadata CodeObjectMetadata, std::string &YamlString)
Converts CodeObjectMetadata to YamlString.
std::error_code error()
Definition: YAMLTraits.cpp:73
void mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:656
constexpr char WorkgroupGroupSegmentSize[]
Key for Kernel::CodeProps::Metadata::mWorkgroupGroupSegmentSize.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
In-memory representation of kernel debug properties metadata.
uint8_t mKernargSegmentAlign
Maximum byte alignment of variables used by the kernel in the kernarg memory segment.
static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD)
uint16_t mReservedNumVGPRs
Consecutive number of VGPRs reserved for debugger use.
uint32_t mAlign
Alignment in bytes. Required.
uint32_t mWorkgroupGroupSegmentSize
Size in bytes of the group segment memory required by a workgroup.
constexpr char Version[]
Key for CodeObject::Metadata::mVersion.
constexpr char Printf[]
Key for CodeObject::Metadata::mPrintf.
uint8_t mGroupSegmentAlign
Maximum byte alignment of variables used by the kernel in the group memory segment.
constexpr char ValueKind[]
Key for Kernel::Arg::Metadata::mValueKind.
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
constexpr char IsConst[]
Key for Kernel::Arg::Metadata::mIsConst.
constexpr char IsRestrict[]
Key for Kernel::Arg::Metadata::mIsRestrict.
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence...
Definition: YAMLTraits.h:1643
uint16_t mPrivateSegmentBufferSGPR
Fixed SGPR of the first of 4 SGPRs used to hold the scratch V# used for the entire kernel execution...
In-memory representation of kernel attributes metadata.
bool mIsConst
True if 'const' qualifier is specified. Optional.
uint8_t mPrivateSegmentAlign
Maximum byte alignment of variables used by the kernel in the private memory segment.
constexpr char ReservedNumVGPRs[]
Key for Kernel::DebugProps::Metadata::mReservedNumVGPRs.
constexpr char PointeeAlign[]
Key for Kernel::Arg::Metadata::mPointeeAlign.
uint32_t mPointeeAlign
Pointee alignment in bytes. Optional.
static void mapping(IO &YIO, Kernel::Arg::Metadata &MD)
std::vector< uint32_t > mVersion
Code object metadata version. Required.
The Input class is used to parse a yaml document into in-memory structs and vectors.
Definition: YAMLTraits.h:1108
uint8_t mWavefrontSize
Wavefront size. Expressed as a power of two. Optional.
constexpr char LanguageVersion[]
Key for Kernel::Metadata::mLanguageVersion.
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
uint16_t mWavefrontPrivateSegmentOffsetSGPR
Fixed SGPR used to hold the wave scratch offset for the entire kernel execution.
constexpr char WorkitemPrivateSegmentSize[]
Key for Kernel::CodeProps::Metadata::mWorkitemPrivateSegmentSize.
DebugProps::Metadata mDebugProps
Debug properties metadata. Optional.
static std::error_code fromYamlString(std::string YamlString, Metadata &CodeObjectMetadata)
Converts YamlString to CodeObjectMetadata.
constexpr char ReqdWorkGroupSize[]
Key for Kernel::Attr::Metadata::mReqdWorkGroupSize.
std::vector< uint32_t > mLanguageVersion
Language version. Optional.
Attrs::Metadata mAttrs
Attributes metadata. Optional.
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:590
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD)
In-memory representation of kernel code properties metadata.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
In-memory representation of kernel metadata.
constexpr char Name[]
Key for Kernel::Arg::Metadata::mName.
static void enumeration(IO &YIO, AddressSpaceQualifier &EN)
AMDGPU Code Object Metadata definitions and in-memory representations.
constexpr char WorkitemNumVGPRs[]
Key for Kernel::CodeProps::Metadata::mWorkitemNumVGPRs.
The Output class is used to generate a yaml document from in-memory structs and vectors.
Definition: YAMLTraits.h:1260
std::vector< Arg::Metadata > mArgs
Arguments metadata. Optional.
uint32_t mWorkitemPrivateSegmentSize
Size in bytes of the private segment memory required by a workitem.
bool mIsRestrict
True if 'restrict' qualifier is specified. Optional.
In-memory representation of kernel argument metadata.
constexpr char Name[]
Key for Kernel::Metadata::mName.
std::vector< std::string > mPrintf
Printf metadata. Optional.
uint16_t mWavefrontNumSGPRs
Total number of SGPRs used by a wavefront. Optional.
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
constexpr char KernargSegmentSize[]
Key for Kernel::CodeProps::Metadata::mKernargSegmentSize.
constexpr char WavefrontNumSGPRs[]
Key for Kernel::CodeProps::Metadata::mWavefrontNumSGPRs.
constexpr char CodeProps[]
Key for Kernel::Metadata::mCodeProps.
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:98
constexpr char PrivateSegmentAlign[]
Key for Kernel::CodeProps::Metadata::mPrivateSegmentAlign.
constexpr char ReservedFirstVGPR[]
Key for Kernel::DebugProps::Metadata::mReservedFirstVGPR.
std::vector< uint32_t > mWorkGroupSizeHint
'work_group_size_hint' attribute. Optional.
std::vector< Kernel::Metadata > mKernels
Kernels metadata. Optional.
constexpr char ValueType[]
Key for Kernel::Arg::Metadata::mValueType.
AccessQualifier mAccQual
Access qualifier. Optional.
constexpr char VecTypeHint[]
Key for Kernel::Attr::Metadata::mVecTypeHint.
AddressSpaceQualifier mAddrSpaceQual
Address space qualifier. Optional.
bool mIsVolatile
True if 'volatile' qualifier is specified. Optional.
uint16_t mWorkitemNumVGPRs
Total number of VGPRs used by a workitem. Optional.
constexpr char AddrSpaceQual[]
Key for Kernel::Arg::Metadata::mAddrSpaceQual.
constexpr char KernargSegmentAlign[]
Key for Kernel::CodeProps::Metadata::mKernargSegmentAlign.
constexpr char DebuggerABIVersion[]
Key for Kernel::DebugProps::Metadata::mDebuggerABIVersion.
uint64_t mKernargSegmentSize
Size in bytes of the kernarg segment memory.
CodeProps::Metadata mCodeProps
Code properties metadata. Optional.
static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
constexpr char WavefrontPrivateSegmentOffsetSGPR[]
Key for Kernel::DebugProps::Metadata::mWavefrontPrivateSegmentOffsetSGPR.
constexpr char AccQual[]
Key for Kernel::Arg::Metadata::mAccQual.
constexpr char Kernels[]
Key for CodeObject::Metadata::mKernels.
In-memory representation of code object metadata.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
std::string mVecTypeHint
'vec_type_hint' attribute. Optional.
constexpr char IsPipe[]
Key for Kernel::Arg::Metadata::mIsPipe.
constexpr char WavefrontSize[]
Key for Kernel::CodeProps::Metadata::mWavefrontSize.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
virtual bool outputting()=0
bool mIsPipe
True if 'pipe' qualifier is specified. Optional.
constexpr char GroupSegmentAlign[]
Key for Kernel::CodeProps::Metadata::mGroupSegmentAlign.
AddressSpaceQualifier
Address space qualifiers.
static void mapping(IO &YIO, CodeObject::Metadata &MD)
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:463
std::vector< uint32_t > mReqdWorkGroupSize
'reqd_work_group_size' attribute. Optional.
constexpr char DebugProps[]
Key for Kernel::Metadata::mDebugProps.
constexpr char PrivateSegmentBufferSGPR[]
Key for Kernel::DebugProps::Metadata::mPrivateSegmentBufferSGPR.
static void mapping(IO &YIO, Kernel::Metadata &MD)
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:646
constexpr char WorkGroupSizeHint[]
Key for Kernel::Attr::Metadata::mWorkGroupSizeHint.
Root of the metadata hierarchy.
Definition: Metadata.h:58