Skip to content

Commit 07d659b

Browse files
committedDec 14, 2016
AMDGPU: Emit runtime metadata version 2 as YAML
Differential Revision: https://reviews.llvm.org/D25046 llvm-svn: 289674
1 parent ebd8110 commit 07d659b

14 files changed

+806
-2706
lines changed
 

‎llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void AMDGPUAsmPrinter::EmitStartOfAsmFile(Module &M) {
119119
"AMD", "AMDGPU");
120120

121121
// Emit runtime metadata.
122-
TS->emitRuntimeMetadataAsNoteElement(M);
122+
TS->emitRuntimeMetadata(M);
123123
}
124124

125125
bool AMDGPUAsmPrinter::isBlockOnlyReachableByFallthrough(
@@ -824,4 +824,3 @@ bool AMDGPUAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
824824
*TM.getSubtargetImpl(*MF->getFunction())->getRegisterInfo());
825825
return false;
826826
}
827-

‎llvm/lib/Target/AMDGPU/AMDGPURuntimeMetadata.h

+104-63
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@
1414
/// Runtime requests certain information (metadata) about kernels to be able
1515
/// to execute the kernels and answer the queries about the kernels.
1616
/// The metadata is represented as a note element in the .note ELF section of a
17-
/// binary (code object). The desc field of the note element consists of
18-
/// key-value pairs. Each key is an 8 bit unsigned integer. Each value can be
19-
/// an integer, a string, or a stream of key-value pairs. There are 3 levels of
20-
/// key-value pair streams. At the beginning of the ELF section is the top level
21-
/// key-value pair stream. A kernel-level key-value pair stream starts after
22-
/// encountering KeyKernelBegin and ends immediately before encountering
23-
/// KeyKernelEnd. A kernel-argument-level key-value pair stream starts
24-
/// after encountering KeyArgBegin and ends immediately before encountering
25-
/// KeyArgEnd. A kernel-level key-value pair stream can only appear in a top
26-
/// level key-value pair stream. A kernel-argument-level key-value pair stream
27-
/// can only appear in a kernel-level key-value pair stream.
17+
/// binary (code object). The desc field of the note element is a YAML string
18+
/// consisting of key-value pairs. Each key is a string. Each value can be
19+
/// an integer, a string, or an YAML sequence. There are 3 levels of YAML maps.
20+
/// At the beginning of the YAML string is the module level YAML map. A
21+
/// kernel-level YAML map is in the amd.Kernels sequence. A
22+
/// kernel-argument-level map is in the amd.Args sequence.
2823
///
2924
/// The format should be kept backward compatible. New enum values and bit
3025
/// fields should be appended at the end. It is suggested to bump up the
@@ -37,64 +32,46 @@
3732
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H
3833
#define LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H
3934

35+
#include <cstdint>
36+
#include <vector>
37+
#include <string>
38+
4039
namespace AMDGPU {
4140

4241
namespace RuntimeMD {
4342

4443
// Version and revision of runtime metadata
45-
const unsigned char MDVersion = 1;
44+
const unsigned char MDVersion = 2;
4645
const unsigned char MDRevision = 0;
4746

48-
// Enumeration values of keys in runtime metadata.
49-
enum Key {
50-
KeyNull = 0, // Place holder. Ignored when encountered
51-
KeyMDVersion = 1, // Runtime metadata version
52-
KeyLanguage = 2, // Language
53-
KeyLanguageVersion = 3, // Language version
54-
KeyKernelBegin = 4, // Beginning of kernel-level stream
55-
KeyKernelEnd = 5, // End of kernel-level stream
56-
KeyKernelName = 6, // Kernel name
57-
KeyArgBegin = 7, // Beginning of kernel-arg-level stream
58-
KeyArgEnd = 8, // End of kernel-arg-level stream
59-
KeyArgSize = 9, // Kernel arg size
60-
KeyArgAlign = 10, // Kernel arg alignment
61-
KeyArgTypeName = 11, // Kernel type name
62-
KeyArgName = 12, // Kernel name
63-
KeyArgKind = 13, // Kernel argument kind
64-
KeyArgValueType = 14, // Kernel argument value type
65-
KeyArgAddrQual = 15, // Kernel argument address qualifier
66-
KeyArgAccQual = 16, // Kernel argument access qualifier
67-
KeyArgIsConst = 17, // Kernel argument is const qualified
68-
KeyArgIsRestrict = 18, // Kernel argument is restrict qualified
69-
KeyArgIsVolatile = 19, // Kernel argument is volatile qualified
70-
KeyArgIsPipe = 20, // Kernel argument is pipe qualified
71-
KeyReqdWorkGroupSize = 21, // Required work group size
72-
KeyWorkGroupSizeHint = 22, // Work group size hint
73-
KeyVecTypeHint = 23, // Vector type hint
74-
KeyKernelIndex = 24, // Kernel index for device enqueue
75-
KeyMinWavesPerSIMD = 25, // Minimum number of waves per SIMD
76-
KeyMaxWavesPerSIMD = 26, // Maximum number of waves per SIMD
77-
KeyFlatWorkGroupSizeLimits = 27, // Flat work group size limits
78-
KeyMaxWorkGroupSize = 28, // Maximum work group size
79-
KeyNoPartialWorkGroups = 29, // No partial work groups
80-
KeyPrintfInfo = 30, // Prinf function call information
81-
KeyArgActualAcc = 31, // The actual kernel argument access qualifier
82-
KeyArgPointeeAlign = 32, // Alignment of pointee type
83-
};
84-
85-
enum Language : uint8_t {
86-
OpenCL_C = 0,
87-
HCC = 1,
88-
OpenMP = 2,
89-
OpenCL_CPP = 3,
90-
};
91-
92-
enum LanguageVersion : uint16_t {
93-
V100 = 100,
94-
V110 = 110,
95-
V120 = 120,
96-
V200 = 200,
97-
V210 = 210,
47+
// Name of keys for runtime metadata.
48+
namespace KeyName {
49+
const char MDVersion[] = "amd.MDVersion"; // Runtime metadata version
50+
const char Language[] = "amd.Language"; // Language
51+
const char LanguageVersion[] = "amd.LanguageVersion"; // Language version
52+
const char Kernels[] = "amd.Kernels"; // Kernels
53+
const char KernelName[] = "amd.KernelName"; // Kernel name
54+
const char Args[] = "amd.Args"; // Kernel arguments
55+
const char ArgSize[] = "amd.ArgSize"; // Kernel arg size
56+
const char ArgAlign[] = "amd.ArgAlign"; // Kernel arg alignment
57+
const char ArgTypeName[] = "amd.ArgTypeName"; // Kernel type name
58+
const char ArgName[] = "amd.ArgName"; // Kernel name
59+
const char ArgKind[] = "amd.ArgKind"; // Kernel argument kind
60+
const char ArgValueType[] = "amd.ArgValueType"; // Kernel argument value type
61+
const char ArgAddrQual[] = "amd.ArgAddrQual"; // Kernel argument address qualifier
62+
const char ArgAccQual[] = "amd.ArgAccQual"; // Kernel argument access qualifier
63+
const char ArgIsConst[] = "amd.ArgIsConst"; // Kernel argument is const qualified
64+
const char ArgIsRestrict[] = "amd.ArgIsRestrict"; // Kernel argument is restrict qualified
65+
const char ArgIsVolatile[] = "amd.ArgIsVolatile"; // Kernel argument is volatile qualified
66+
const char ArgIsPipe[] = "amd.ArgIsPipe"; // Kernel argument is pipe qualified
67+
const char ReqdWorkGroupSize[] = "amd.ReqdWorkGroupSize"; // Required work group size
68+
const char WorkGroupSizeHint[] = "amd.WorkGroupSizeHint"; // Work group size hint
69+
const char VecTypeHint[] = "amd.VecTypeHint"; // Vector type hint
70+
const char KernelIndex[] = "amd.KernelIndex"; // Kernel index for device enqueue
71+
const char NoPartialWorkGroups[] = "amd.NoPartialWorkGroups"; // No partial work groups
72+
const char PrintfInfo[] = "amd.PrintfInfo"; // Prinf function call information
73+
const char ArgActualAcc[] = "amd.ArgActualAcc"; // The actual kernel argument access qualifier
74+
const char ArgPointeeAlign[] = "amd.ArgPointeeAlign"; // Alignment of pointee type
9875
};
9976

10077
namespace KernelArg {
@@ -130,8 +107,9 @@ namespace RuntimeMD {
130107
F64 = 11,
131108
};
132109

110+
// Avoid using 'None' since it conflicts with a macro in X11 header file.
133111
enum AccessQualifer : uint8_t {
134-
None = 0,
112+
AccNone = 0,
135113
ReadOnly = 1,
136114
WriteOnly = 2,
137115
ReadWrite = 3,
@@ -146,6 +124,69 @@ namespace RuntimeMD {
146124
Region = 5,
147125
};
148126
} // namespace KernelArg
127+
128+
// Invalid values are used to indicate an optional key should not be emitted.
129+
const uint8_t INVALID_ADDR_QUAL = 0xff;
130+
const uint8_t INVALID_ACC_QUAL = 0xff;
131+
const uint32_t INVALID_KERNEL_INDEX = ~0U;
132+
133+
namespace KernelArg {
134+
// In-memory representation of kernel argument information.
135+
struct Metadata {
136+
uint32_t Size;
137+
uint32_t Align;
138+
uint32_t PointeeAlign;
139+
uint8_t Kind;
140+
uint16_t ValueType;
141+
std::string TypeName;
142+
std::string Name;
143+
uint8_t AddrQual;
144+
uint8_t AccQual;
145+
uint8_t IsVolatile;
146+
uint8_t IsConst;
147+
uint8_t IsRestrict;
148+
uint8_t IsPipe;
149+
Metadata() : Size(0), Align(0), PointeeAlign(0), Kind(0), ValueType(0),
150+
AddrQual(INVALID_ADDR_QUAL), AccQual(INVALID_ACC_QUAL), IsVolatile(0),
151+
IsConst(0), IsRestrict(0), IsPipe(0) {}
152+
};
153+
}
154+
155+
namespace Kernel {
156+
// In-memory representation of kernel information.
157+
struct Metadata {
158+
std::string Name;
159+
std::string Language;
160+
std::vector<uint8_t> LanguageVersion;
161+
std::vector<uint32_t> ReqdWorkGroupSize;
162+
std::vector<uint32_t> WorkGroupSizeHint;
163+
std::string VecTypeHint;
164+
uint32_t KernelIndex;
165+
uint8_t NoPartialWorkGroups;
166+
std::vector<KernelArg::Metadata> Args;
167+
Metadata() : KernelIndex(INVALID_KERNEL_INDEX), NoPartialWorkGroups(0) {}
168+
};
169+
}
170+
171+
namespace Program {
172+
// In-memory representation of program information.
173+
struct Metadata {
174+
std::vector<uint8_t> MDVersionSeq;
175+
std::vector<std::string> PrintfInfo;
176+
std::vector<Kernel::Metadata> Kernels;
177+
178+
explicit Metadata(){}
179+
180+
// Construct from an YAML string.
181+
explicit Metadata(const std::string &YAML);
182+
183+
// Convert to YAML string.
184+
std::string toYAML();
185+
186+
// Convert from YAML string.
187+
static Metadata fromYAML(const std::string &S);
188+
};
189+
}
149190
} // namespace RuntimeMD
150191
} // namespace AMDGPU
151192

0 commit comments

Comments
 (0)
Please sign in to comment.