LLVM  6.0.0svn
AMDGPUMetadata.cpp
Go to the documentation of this file.
1 //===--- AMDGPUMetadata.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 metadata definitions and in-memory representations.
12 ///
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "llvm/ADT/Twine.h"
19 
20 using namespace llvm::AMDGPU;
21 using namespace llvm::AMDGPU::HSAMD;
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 <>
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());
100  std::string());
101  }
102 };
103 
104 template <>
106  static void mapping(IO &YIO, Kernel::Arg::Metadata &MD) {
107  YIO.mapOptional(Kernel::Arg::Key::Name, MD.mName, std::string());
108  YIO.mapOptional(Kernel::Arg::Key::TypeName, MD.mTypeName, std::string());
114  uint32_t(0));
125  }
126 };
127 
128 template <>
130  static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD) {
140  MD.mWavefrontSize);
142  MD.mNumSGPRs, uint16_t(0));
144  MD.mNumVGPRs, uint16_t(0));
148  MD.mIsDynamicCallStack, false);
150  MD.mIsXNACKEnabled, false);
151  }
152 };
153 
154 template <>
156  static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD) {
158  MD.mDebuggerABIVersion, std::vector<uint32_t>());
160  MD.mReservedNumVGPRs, uint16_t(0));
162  MD.mReservedFirstVGPR, uint16_t(-1));
164  MD.mPrivateSegmentBufferSGPR, uint16_t(-1));
166  MD.mWavefrontPrivateSegmentOffsetSGPR, uint16_t(-1));
167  }
168 };
169 
170 template <>
172  static void mapping(IO &YIO, Kernel::Metadata &MD) {
175  YIO.mapOptional(Kernel::Key::Language, MD.mLanguage, std::string());
177  std::vector<uint32_t>());
178  if (!MD.mAttrs.empty() || !YIO.outputting())
180  if (!MD.mArgs.empty() || !YIO.outputting())
182  if (!MD.mCodeProps.empty() || !YIO.outputting())
184  if (!MD.mDebugProps.empty() || !YIO.outputting())
186  }
187 };
188 
189 template <>
190 struct MappingTraits<HSAMD::Metadata> {
191  static void mapping(IO &YIO, HSAMD::Metadata &MD) {
193  YIO.mapOptional(Key::Printf, MD.mPrintf, std::vector<std::string>());
194  if (!MD.mKernels.empty() || !YIO.outputting())
196  }
197 };
198 
199 } // end namespace yaml
200 
201 namespace AMDGPU {
202 namespace HSAMD {
203 
204 std::error_code fromString(std::string String, Metadata &HSAMetadata) {
205  yaml::Input YamlInput(String);
206  YamlInput >> HSAMetadata;
207  return YamlInput.error();
208 }
209 
210 std::error_code toString(Metadata HSAMetadata, std::string &String) {
211  raw_string_ostream YamlStream(String);
212  yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
213  YamlOutput << HSAMetadata;
214  return std::error_code();
215 }
216 
217 } // end namespace HSAMD
218 
219 namespace PALMD {
220 
221 std::error_code toString(const Metadata &PALMetadata, std::string &String) {
222  raw_string_ostream Stream(String);
223  for (auto I = PALMetadata.begin(), E = PALMetadata.end(); I != E; ++I) {
224  Stream << Twine(I == PALMetadata.begin() ? " 0x" : ",0x");
225  Stream << Twine::utohexstr(*I);
226  }
227  Stream.flush();
228  return std::error_code();
229 }
230 
231 } // end namespace PALMD
232 } // end namespace AMDGPU
233 } // end namespace llvm
constexpr char IsXNACKEnabled[]
Key for Kernel::CodeProps::Metadata::mIsXNACKEnabled.
std::vector< uint32_t > mLanguageVersion
Language version. Optional.
In-memory representation of HSA metadata.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
std::error_code error()
Definition: YAMLTraits.cpp:73
constexpr char GroupSegmentFixedSize[]
Key for Kernel::CodeProps::Metadata::mGroupSegmentFixedSize.
uint16_t mNumVGPRs
Total number of VGPRs used by a workitem. Optional.
void mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:656
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
constexpr char Name[]
Key for Kernel::Metadata::mName.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD)
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
constexpr char PointeeAlign[]
Key for Kernel::Arg::Metadata::mPointeeAlign.
uint32_t mPrivateSegmentFixedSize
Size in bytes of the private segment memory required by a workitem.
bool mIsConst
True if &#39;const&#39; qualifier is specified. Optional.
ValueKind mValueKind
Value kind. Required.
constexpr char ReqdWorkGroupSize[]
Key for Kernel::Attr::Metadata::mReqdWorkGroupSize.
uint16_t mReservedFirstVGPR
First fixed VGPR reserved.
uint32_t mWavefrontSize
Wavefront size. Required.
constexpr char KernargSegmentAlign[]
Key for Kernel::CodeProps::Metadata::mKernargSegmentAlign.
#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
AccessQualifier mActualAccQual
Actual access qualifier. Optional.
constexpr char RuntimeHandle[]
Key for Kernel::Attr::Metadata::mRuntimeHandle.
constexpr char ReservedFirstVGPR[]
Key for Kernel::DebugProps::Metadata::mReservedFirstVGPR.
constexpr char PrivateSegmentBufferSGPR[]
Key for Kernel::DebugProps::Metadata::mPrivateSegmentBufferSGPR.
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
constexpr char KernargSegmentSize[]
Key for Kernel::CodeProps::Metadata::mKernargSegmentSize.
bool mIsXNACKEnabled
True if the generated machine code is capable of supporting XNACK.
In-memory representation of kernel debug properties metadata.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static void enumeration(IO &YIO, AccessQualifier &EN)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
constexpr char AddrSpaceQual[]
Key for Kernel::Arg::Metadata::mAddrSpaceQual.
constexpr char Printf[]
Key for HSA::Metadata::mPrintf.
constexpr char DebuggerABIVersion[]
Key for Kernel::DebugProps::Metadata::mDebuggerABIVersion.
std::vector< Arg::Metadata > mArgs
Arguments metadata. Optional.
static void mapping(IO &YIO, Kernel::Arg::Metadata &MD)
std::error_code fromString(std::string String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
The Input class is used to parse a yaml document into in-memory structs and vectors.
Definition: YAMLTraits.h:1108
std::string mTypeName
Type name. Optional.
static void enumeration(IO &YIO, ValueKind &EN)
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
uint16_t mNumSGPRs
Total number of SGPRs used by a wavefront. Optional.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool mIsPipe
True if &#39;pipe&#39; qualifier is specified. Optional.
uint32_t mKernargSegmentAlign
Maximum byte alignment of variables used by the kernel in the kernarg memory segment.
constexpr char IsPipe[]
Key for Kernel::Arg::Metadata::mIsPipe.
bool mIsVolatile
True if &#39;volatile&#39; qualifier is specified. Optional.
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:590
uint32_t mSize
Size in bytes. Required.
static void mapping(IO &YIO, HSAMD::Metadata &MD)
std::string mRuntimeHandle
External symbol created by runtime to store the kernel address for enqueued blocks.
static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD)
std::string mSymbolName
Kernel descriptor name. Required.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
In-memory representation of kernel metadata.
ValueType mValueType
Value type. Required.
constexpr char WavefrontSize[]
Key for Kernel::CodeProps::Metadata::mWavefrontSize.
ValueKind
Value kinds.
std::vector< uint32_t > mVersion
HSA metadata version. Required.
std::vector< uint32_t > mReqdWorkGroupSize
&#39;reqd_work_group_size&#39; attribute. Optional.
In-memory representation of kernel argument metadata.
static void enumeration(IO &YIO, AddressSpaceQualifier &EN)
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
CodeProps::Metadata mCodeProps
Code properties metadata. Optional.
constexpr char ActualAccQual[]
Key for Kernel::Arg::Metadata::mActualAccQual.
uint32_t mAlign
Alignment in bytes. Required.
Attrs::Metadata mAttrs
Attributes metadata. Optional.
constexpr char IsDynamicCallStack[]
Key for Kernel::CodeProps::Metadata::mIsDynamicCallStack.
The Output class is used to generate a yaml document from in-memory structs and vectors.
Definition: YAMLTraits.h:1260
In-memory representation of kernel attributes metadata.
constexpr char Version[]
Key for HSA::Metadata::mVersion.
constexpr char NumSGPRs[]
Key for Kernel::CodeProps::Metadata::mNumSGPRs.
AccessQualifier
Access qualifiers.
DebugProps::Metadata mDebugProps
Debug properties metadata. Optional.
constexpr char IsRestrict[]
Key for Kernel::Arg::Metadata::mIsRestrict.
std::vector< std::string > mPrintf
Printf metadata. Optional.
uint16_t mPrivateSegmentBufferSGPR
Fixed SGPR of the first of 4 SGPRs used to hold the scratch V# used for the entire kernel execution...
uint16_t mReservedNumVGPRs
Consecutive number of VGPRs reserved for debugger use.
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:98
std::vector< uint32_t > mWorkGroupSizeHint
&#39;work_group_size_hint&#39; attribute. Optional.
uint32_t mPointeeAlign
Pointee alignment in bytes. Optional.
constexpr char CodeProps[]
Key for Kernel::Metadata::mCodeProps.
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:385
constexpr char Name[]
Key for Kernel::Arg::Metadata::mName.
constexpr char LanguageVersion[]
Key for Kernel::Metadata::mLanguageVersion.
constexpr char ValueType[]
Key for Kernel::Arg::Metadata::mValueType.
constexpr char MaxFlatWorkGroupSize[]
Key for Kernel::CodeProps::Metadata::mMaxFlatWorkGroupSize.
constexpr char NumVGPRs[]
Key for Kernel::CodeProps::Metadata::mNumVGPRs.
constexpr char Kernels[]
Key for HSA::Metadata::mKernels.
static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD)
constexpr char PrivateSegmentFixedSize[]
Key for Kernel::CodeProps::Metadata::mPrivateSegmentFixedSize.
std::error_code toString(Metadata HSAMetadata, std::string &String)
Converts HSAMetadata to String.
uint32_t mMaxFlatWorkGroupSize
Maximum flat work-group size supported by the kernel. Optional.
bool mIsDynamicCallStack
True if the generated machine code is using a dynamically sized call stack.
constexpr char DebugProps[]
Key for Kernel::Metadata::mDebugProps.
AddressSpaceQualifier
Address space qualifiers.
#define I(x, y, z)
Definition: MD5.cpp:58
constexpr char VecTypeHint[]
Key for Kernel::Attr::Metadata::mVecTypeHint.
constexpr char AccQual[]
Key for Kernel::Arg::Metadata::mAccQual.
bool mIsRestrict
True if &#39;restrict&#39; qualifier is specified. Optional.
In-memory representation of kernel code properties metadata.
constexpr char IsConst[]
Key for Kernel::Arg::Metadata::mIsConst.
constexpr char WorkGroupSizeHint[]
Key for Kernel::Attr::Metadata::mWorkGroupSizeHint.
virtual bool outputting()=0
uint16_t mWavefrontPrivateSegmentOffsetSGPR
Fixed SGPR used to hold the wave scratch offset for the entire kernel execution.
uint64_t mKernargSegmentSize
Size in bytes of the kernarg segment memory.
static void enumeration(IO &YIO, ValueType &EN)
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:462
constexpr char WavefrontPrivateSegmentOffsetSGPR[]
Key for Kernel::DebugProps::Metadata::mWavefrontPrivateSegmentOffsetSGPR.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
AddressSpaceQualifier mAddrSpaceQual
Address space qualifier. Optional.
constexpr char ReservedNumVGPRs[]
Key for Kernel::DebugProps::Metadata::mReservedNumVGPRs.
std::string mName
Kernel source name. Required.
uint32_t mGroupSegmentFixedSize
Size in bytes of the group segment memory required by a workgroup.
AMDGPU metadata definitions and in-memory representations.
static void mapping(IO &YIO, Kernel::Metadata &MD)
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:646
std::vector< Kernel::Metadata > mKernels
Kernels metadata. Required.
Root of the metadata hierarchy.
Definition: Metadata.h:58
constexpr char ValueKind[]
Key for Kernel::Arg::Metadata::mValueKind.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::vector< uint32_t > Metadata
PAL metadata represented as a vector.
std::vector< uint32_t > mDebuggerABIVersion
Debugger ABI version. Optional.
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...
Definition: PointerUnion.h:87
AccessQualifier mAccQual
Access qualifier. Optional.
std::string mLanguage
Language. Optional.
std::string mVecTypeHint
&#39;vec_type_hint&#39; attribute. Optional.