14
14
// / Runtime requests certain information (metadata) about kernels to be able
15
15
// / to execute the kernels and answer the queries about the kernels.
16
16
// / 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.
28
23
// /
29
24
// / The format should be kept backward compatible. New enum values and bit
30
25
// / fields should be appended at the end. It is suggested to bump up the
37
32
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H
38
33
#define LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H
39
34
35
+ #include < cstdint>
36
+ #include < vector>
37
+ #include < string>
38
+
40
39
namespace AMDGPU {
41
40
42
41
namespace RuntimeMD {
43
42
44
43
// Version and revision of runtime metadata
45
- const unsigned char MDVersion = 1 ;
44
+ const unsigned char MDVersion = 2 ;
46
45
const unsigned char MDRevision = 0 ;
47
46
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
98
75
};
99
76
100
77
namespace KernelArg {
@@ -130,8 +107,9 @@ namespace RuntimeMD {
130
107
F64 = 11 ,
131
108
};
132
109
110
+ // Avoid using 'None' since it conflicts with a macro in X11 header file.
133
111
enum AccessQualifer : uint8_t {
134
- None = 0 ,
112
+ AccNone = 0 ,
135
113
ReadOnly = 1 ,
136
114
WriteOnly = 2 ,
137
115
ReadWrite = 3 ,
@@ -146,6 +124,69 @@ namespace RuntimeMD {
146
124
Region = 5 ,
147
125
};
148
126
} // 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
+ }
149
190
} // namespace RuntimeMD
150
191
} // namespace AMDGPU
151
192
0 commit comments