LLVM 22.0.0git
AMDGPUMetadata.cpp
Go to the documentation of this file.
1//===--- AMDGPUMetadata.cpp -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// AMDGPU metadata definitions and in-memory representations.
11///
12//
13//===----------------------------------------------------------------------===//
14
17#include <optional>
18
19using namespace llvm::AMDGPU;
20using namespace llvm::AMDGPU::HSAMD;
21
24
25namespace llvm {
26namespace yaml {
27
28template <>
30 static void enumeration(IO &YIO, AccessQualifier &EN) {
31 YIO.enumCase(EN, "Default", AccessQualifier::Default);
32 YIO.enumCase(EN, "ReadOnly", AccessQualifier::ReadOnly);
33 YIO.enumCase(EN, "WriteOnly", AccessQualifier::WriteOnly);
34 YIO.enumCase(EN, "ReadWrite", AccessQualifier::ReadWrite);
35 }
36};
37
38template <>
49
50template <>
52 static void enumeration(IO &YIO, ValueKind &EN) {
53 YIO.enumCase(EN, "ByValue", ValueKind::ByValue);
54 YIO.enumCase(EN, "GlobalBuffer", ValueKind::GlobalBuffer);
55 YIO.enumCase(EN, "DynamicSharedPointer", ValueKind::DynamicSharedPointer);
56 YIO.enumCase(EN, "Sampler", ValueKind::Sampler);
57 YIO.enumCase(EN, "Image", ValueKind::Image);
58 YIO.enumCase(EN, "Pipe", ValueKind::Pipe);
59 YIO.enumCase(EN, "Queue", ValueKind::Queue);
60 YIO.enumCase(EN, "HiddenGlobalOffsetX", ValueKind::HiddenGlobalOffsetX);
61 YIO.enumCase(EN, "HiddenGlobalOffsetY", ValueKind::HiddenGlobalOffsetY);
62 YIO.enumCase(EN, "HiddenGlobalOffsetZ", ValueKind::HiddenGlobalOffsetZ);
63 YIO.enumCase(EN, "HiddenNone", ValueKind::HiddenNone);
64 YIO.enumCase(EN, "HiddenPrintfBuffer", ValueKind::HiddenPrintfBuffer);
65 YIO.enumCase(EN, "HiddenHostcallBuffer", ValueKind::HiddenHostcallBuffer);
66 YIO.enumCase(EN, "HiddenDefaultQueue", ValueKind::HiddenDefaultQueue);
67 YIO.enumCase(EN, "HiddenCompletionAction",
69 YIO.enumCase(EN, "HiddenMultiGridSyncArg",
71 }
72};
73
74template <>
76 static void enumeration(IO &YIO, ValueType &EN) {
77 YIO.enumCase(EN, "Struct", ValueType::Struct);
78 YIO.enumCase(EN, "I8", ValueType::I8);
79 YIO.enumCase(EN, "U8", ValueType::U8);
80 YIO.enumCase(EN, "I16", ValueType::I16);
81 YIO.enumCase(EN, "U16", ValueType::U16);
82 YIO.enumCase(EN, "F16", ValueType::F16);
83 YIO.enumCase(EN, "I32", ValueType::I32);
84 YIO.enumCase(EN, "U32", ValueType::U32);
85 YIO.enumCase(EN, "F32", ValueType::F32);
86 YIO.enumCase(EN, "I64", ValueType::I64);
87 YIO.enumCase(EN, "U64", ValueType::U64);
88 YIO.enumCase(EN, "F64", ValueType::F64);
89 }
90};
91
92template <>
93struct MappingTraits<Kernel::Attrs::Metadata> {
94 static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD) {
96 MD.mReqdWorkGroupSize, std::vector<uint32_t>());
98 MD.mWorkGroupSizeHint, std::vector<uint32_t>());
100 MD.mVecTypeHint, std::string());
102 std::string());
103 }
104};
105
106template <>
133
134template <>
163
164template <>
179
180template <>
182 static void mapping(IO &YIO, Kernel::Metadata &MD) {
185 YIO.mapOptional(Kernel::Key::Language, MD.mLanguage, std::string());
187 std::vector<uint32_t>());
188 if (!MD.mAttrs.empty() || !YIO.outputting())
190 if (!MD.mArgs.empty() || !YIO.outputting())
192 if (!MD.mCodeProps.empty() || !YIO.outputting())
194 if (!MD.mDebugProps.empty() || !YIO.outputting())
196 }
197};
198
199template <>
201 static void mapping(IO &YIO, HSAMD::Metadata &MD) {
203 YIO.mapOptional(Key::Printf, MD.mPrintf, std::vector<std::string>());
204 if (!MD.mKernels.empty() || !YIO.outputting())
206 }
207};
208
209} // end namespace yaml
210
211namespace AMDGPU {
212namespace HSAMD {
213
214std::error_code fromString(StringRef String, Metadata &HSAMetadata) {
215 yaml::Input YamlInput(String);
216 YamlInput >> HSAMetadata;
217 return YamlInput.error();
218}
219
220std::error_code toString(Metadata HSAMetadata, std::string &String) {
221 raw_string_ostream YamlStream(String);
222 yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
223 YamlOutput << HSAMetadata;
224 return std::error_code();
225}
226
227} // end namespace HSAMD
228} // end namespace AMDGPU
229} // end namespace llvm
AMDGPU metadata definitions and in-memory representations.
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence.
Root of the metadata hierarchy.
Definition Metadata.h:63
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A raw_ostream that writes to an std::string.
void mapOptional(const char *Key, T &Val)
Definition YAMLTraits.h:810
virtual bool outputting() const =0
void mapRequired(const char *Key, T &Val)
Definition YAMLTraits.h:800
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition YAMLTraits.h:745
The Input class is used to parse a yaml document into in-memory structs and vectors.
std::error_code error() override
The Output class is used to generate a yaml document from in-memory structs and vectors.
constexpr char AddrSpaceQual[]
Key for Kernel::Arg::Metadata::mAddrSpaceQual.
constexpr char ValueType[]
Key for Kernel::Arg::Metadata::mValueType. (deprecated)
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
constexpr char PointeeAlign[]
Key for Kernel::Arg::Metadata::mPointeeAlign.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
constexpr char ValueKind[]
Key for Kernel::Arg::Metadata::mValueKind.
constexpr char IsConst[]
Key for Kernel::Arg::Metadata::mIsConst.
constexpr char IsRestrict[]
Key for Kernel::Arg::Metadata::mIsRestrict.
constexpr char ActualAccQual[]
Key for Kernel::Arg::Metadata::mActualAccQual.
constexpr char AccQual[]
Key for Kernel::Arg::Metadata::mAccQual.
constexpr char IsPipe[]
Key for Kernel::Arg::Metadata::mIsPipe.
constexpr char Name[]
Key for Kernel::Arg::Metadata::mName.
constexpr char ReqdWorkGroupSize[]
Key for Kernel::Attr::Metadata::mReqdWorkGroupSize.
constexpr char VecTypeHint[]
Key for Kernel::Attr::Metadata::mVecTypeHint.
constexpr char RuntimeHandle[]
Key for Kernel::Attr::Metadata::mRuntimeHandle.
constexpr char WorkGroupSizeHint[]
Key for Kernel::Attr::Metadata::mWorkGroupSizeHint.
constexpr char NumVGPRs[]
Key for Kernel::CodeProps::Metadata::mNumVGPRs.
constexpr char NumSpilledSGPRs[]
Key for Kernel::CodeProps::Metadata::mNumSpilledSGPRs.
constexpr char IsXNACKEnabled[]
Key for Kernel::CodeProps::Metadata::mIsXNACKEnabled.
constexpr char NumSpilledVGPRs[]
Key for Kernel::CodeProps::Metadata::mNumSpilledVGPRs.
constexpr char KernargSegmentAlign[]
Key for Kernel::CodeProps::Metadata::mKernargSegmentAlign.
constexpr char IsDynamicCallStack[]
Key for Kernel::CodeProps::Metadata::mIsDynamicCallStack.
constexpr char NumSGPRs[]
Key for Kernel::CodeProps::Metadata::mNumSGPRs.
constexpr char KernargSegmentSize[]
Key for Kernel::CodeProps::Metadata::mKernargSegmentSize.
constexpr char WavefrontSize[]
Key for Kernel::CodeProps::Metadata::mWavefrontSize.
constexpr char MaxFlatWorkGroupSize[]
Key for Kernel::CodeProps::Metadata::mMaxFlatWorkGroupSize.
constexpr char GroupSegmentFixedSize[]
Key for Kernel::CodeProps::Metadata::mGroupSegmentFixedSize.
constexpr char PrivateSegmentFixedSize[]
Key for Kernel::CodeProps::Metadata::mPrivateSegmentFixedSize.
constexpr char ReservedFirstVGPR[]
Key for Kernel::DebugProps::Metadata::mReservedFirstVGPR.
constexpr char ReservedNumVGPRs[]
Key for Kernel::DebugProps::Metadata::mReservedNumVGPRs.
constexpr char DebuggerABIVersion[]
Key for Kernel::DebugProps::Metadata::mDebuggerABIVersion.
constexpr char PrivateSegmentBufferSGPR[]
Key for Kernel::DebugProps::Metadata::mPrivateSegmentBufferSGPR.
constexpr char WavefrontPrivateSegmentOffsetSGPR[]
Key for Kernel::DebugProps::Metadata::mWavefrontPrivateSegmentOffsetSGPR.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char CodeProps[]
Key for Kernel::Metadata::mCodeProps.
constexpr char Name[]
Key for Kernel::Metadata::mName.
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
constexpr char LanguageVersion[]
Key for Kernel::Metadata::mLanguageVersion.
constexpr char DebugProps[]
Key for Kernel::Metadata::mDebugProps.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
constexpr char Version[]
Key for HSA::Metadata::mVersion.
constexpr char Printf[]
Key for HSA::Metadata::mPrintf.
constexpr char Kernels[]
Key for HSA::Metadata::mKernels.
LLVM_ABI std::error_code fromString(StringRef String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
AddressSpaceQualifier
Address space qualifiers.
LLVM_ABI std::error_code toString(Metadata HSAMetadata, std::string &String)
Converts HSAMetadata to String.
AccessQualifier
Access qualifiers.
This is an optimization pass for GlobalISel generic memory operations.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
In-memory representation of kernel argument metadata.
AccessQualifier mActualAccQual
Actual access qualifier. Optional.
uint32_t mAlign
Alignment in bytes. Required.
uint32_t mPointeeAlign
Pointee alignment in bytes. Optional.
bool mIsVolatile
True if 'volatile' qualifier is specified. Optional.
ValueKind mValueKind
Value kind. Required.
bool mIsConst
True if 'const' qualifier is specified. Optional.
bool mIsRestrict
True if 'restrict' qualifier is specified. Optional.
bool mIsPipe
True if 'pipe' qualifier is specified. Optional.
AddressSpaceQualifier mAddrSpaceQual
Address space qualifier. Optional.
uint32_t mSize
Size in bytes. Required.
AccessQualifier mAccQual
Access qualifier. Optional.
std::string mTypeName
Type name. Optional.
In-memory representation of kernel attributes metadata.
std::string mRuntimeHandle
External symbol created by runtime to store the kernel address for enqueued blocks.
std::string mVecTypeHint
'vec_type_hint' attribute. Optional.
std::vector< uint32_t > mReqdWorkGroupSize
'reqd_work_group_size' attribute. Optional.
std::vector< uint32_t > mWorkGroupSizeHint
'work_group_size_hint' attribute. Optional.
In-memory representation of kernel code properties metadata.
uint16_t mNumSGPRs
Total number of SGPRs used by a wavefront. Optional.
uint64_t mKernargSegmentSize
Size in bytes of the kernarg segment memory.
uint32_t mGroupSegmentFixedSize
Size in bytes of the group segment memory required by a workgroup.
uint32_t mKernargSegmentAlign
Maximum byte alignment of variables used by the kernel in the kernarg memory segment.
uint16_t mNumSpilledSGPRs
Number of SGPRs spilled by a wavefront. Optional.
bool mIsXNACKEnabled
True if the generated machine code is capable of supporting XNACK.
uint32_t mWavefrontSize
Wavefront size. Required.
uint16_t mNumSpilledVGPRs
Number of VGPRs spilled by a workitem. Optional.
uint16_t mNumVGPRs
Total number of VGPRs used by a workitem. Optional.
bool mIsDynamicCallStack
True if the generated machine code is using a dynamically sized call stack.
uint32_t mPrivateSegmentFixedSize
Size in bytes of the private segment memory required by a workitem.
uint32_t mMaxFlatWorkGroupSize
Maximum flat work-group size supported by the kernel. Optional.
In-memory representation of kernel debug properties metadata.
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 mReservedFirstVGPR
First fixed VGPR reserved.
std::vector< uint32_t > mDebuggerABIVersion
Debugger ABI version. Optional.
uint16_t mWavefrontPrivateSegmentOffsetSGPR
Fixed SGPR used to hold the wave scratch offset for the entire kernel execution.
uint16_t mReservedNumVGPRs
Consecutive number of VGPRs reserved for debugger use.
In-memory representation of kernel metadata.
DebugProps::Metadata mDebugProps
Debug properties metadata. Optional.
Attrs::Metadata mAttrs
Attributes metadata. Optional.
std::string mLanguage
Language. Optional.
std::string mName
Kernel source name. Required.
std::vector< Arg::Metadata > mArgs
Arguments metadata. Optional.
CodeProps::Metadata mCodeProps
Code properties metadata. Optional.
std::vector< uint32_t > mLanguageVersion
Language version. Optional.
std::string mSymbolName
Kernel descriptor name. Required.
In-memory representation of HSA metadata.
std::vector< Kernel::Metadata > mKernels
Kernels metadata. Required.
std::vector< uint32_t > mVersion
HSA metadata version. Required.
std::vector< std::string > mPrintf
Printf metadata. Optional.
static void mapping(IO &YIO, HSAMD::Metadata &MD)
static void mapping(IO &YIO, Kernel::Arg::Metadata &MD)
static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD)
static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD)
static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD)
static void mapping(IO &YIO, Kernel::Metadata &MD)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:62
static void enumeration(IO &YIO, AccessQualifier &EN)
static void enumeration(IO &YIO, AddressSpaceQualifier &EN)
static void enumeration(IO &YIO, ValueKind &EN)
static void enumeration(IO &YIO, ValueType &EN)
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition YAMLTraits.h:107