Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 1 | //===-- AMDGPURuntimeMetadata.h - AMDGPU Runtime Metadata -------*- 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 | /// |
| 12 | /// Enums and structure types used by runtime metadata. |
| 13 | /// |
| 14 | /// Runtime requests certain information (metadata) about kernels to be able |
| 15 | /// to execute the kernels and answer the queries about the kernels. |
Yaxun Liu | d6fbe65 | 2016-11-10 21:18:49 +0000 | [diff] [blame] | 16 | /// The metadata is represented as a note element in the .note ELF section of a |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 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. |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 23 | /// |
| 24 | /// The format should be kept backward compatible. New enum values and bit |
| 25 | /// fields should be appended at the end. It is suggested to bump up the |
| 26 | /// revision number whenever the format changes and document the change |
| 27 | /// in the revision in this header. |
| 28 | /// |
| 29 | // |
| 30 | //===----------------------------------------------------------------------===// |
| 31 | // |
| 32 | #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H |
| 33 | #define LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H |
| 34 | |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 35 | #include <cstdint> |
| 36 | #include <vector> |
| 37 | #include <string> |
| 38 | |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 39 | namespace AMDGPU { |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 40 | namespace RuntimeMD { |
| 41 | |
| 42 | // Version and revision of runtime metadata |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 43 | const unsigned char MDVersion = 2; |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 44 | const unsigned char MDRevision = 1; |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 45 | |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 46 | // Name of keys for runtime metadata. |
| 47 | namespace KeyName { |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 48 | |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 49 | // Runtime metadata version |
| 50 | const char MDVersion[] = "amd.MDVersion"; |
| 51 | |
| 52 | // Instruction set architecture information |
| 53 | const char IsaInfo[] = "amd.IsaInfo"; |
| 54 | // Wavefront size |
| 55 | const char IsaInfoWavefrontSize[] = "amd.IsaInfoWavefrontSize"; |
| 56 | // Local memory size in bytes |
| 57 | const char IsaInfoLocalMemorySize[] = "amd.IsaInfoLocalMemorySize"; |
| 58 | // Number of execution units per compute unit |
| 59 | const char IsaInfoEUsPerCU[] = "amd.IsaInfoEUsPerCU"; |
| 60 | // Maximum number of waves per execution unit |
| 61 | const char IsaInfoMaxWavesPerEU[] = "amd.IsaInfoMaxWavesPerEU"; |
| 62 | // Maximum flat work group size |
| 63 | const char IsaInfoMaxFlatWorkGroupSize[] = "amd.IsaInfoMaxFlatWorkGroupSize"; |
| 64 | // SGPR allocation granularity |
| 65 | const char IsaInfoSGPRAllocGranule[] = "amd.IsaInfoSGPRAllocGranule"; |
| 66 | // Total number of SGPRs |
| 67 | const char IsaInfoTotalNumSGPRs[] = "amd.IsaInfoTotalNumSGPRs"; |
| 68 | // Addressable number of SGPRs |
| 69 | const char IsaInfoAddressableNumSGPRs[] = "amd.IsaInfoAddressableNumSGPRs"; |
| 70 | // VGPR allocation granularity |
| 71 | const char IsaInfoVGPRAllocGranule[] = "amd.IsaInfoVGPRAllocGranule"; |
| 72 | // Total number of VGPRs |
| 73 | const char IsaInfoTotalNumVGPRs[] = "amd.IsaInfoTotalNumVGPRs"; |
| 74 | // Addressable number of VGPRs |
| 75 | const char IsaInfoAddressableNumVGPRs[] = "amd.IsaInfoAddressableNumVGPRs"; |
| 76 | |
| 77 | // Language |
| 78 | const char Language[] = "amd.Language"; |
| 79 | // Language version |
| 80 | const char LanguageVersion[] = "amd.LanguageVersion"; |
| 81 | |
| 82 | // Kernels |
| 83 | const char Kernels[] = "amd.Kernels"; |
| 84 | // Kernel name |
| 85 | const char KernelName[] = "amd.KernelName"; |
| 86 | // Kernel arguments |
| 87 | const char Args[] = "amd.Args"; |
| 88 | // Kernel argument size in bytes |
| 89 | const char ArgSize[] = "amd.ArgSize"; |
| 90 | // Kernel argument alignment |
| 91 | const char ArgAlign[] = "amd.ArgAlign"; |
| 92 | // Kernel argument type name |
| 93 | const char ArgTypeName[] = "amd.ArgTypeName"; |
| 94 | // Kernel argument name |
| 95 | const char ArgName[] = "amd.ArgName"; |
| 96 | // Kernel argument kind |
| 97 | const char ArgKind[] = "amd.ArgKind"; |
| 98 | // Kernel argument value type |
| 99 | const char ArgValueType[] = "amd.ArgValueType"; |
| 100 | // Kernel argument address qualifier |
| 101 | const char ArgAddrQual[] = "amd.ArgAddrQual"; |
| 102 | // Kernel argument access qualifier |
| 103 | const char ArgAccQual[] = "amd.ArgAccQual"; |
| 104 | // Kernel argument is const qualified |
| 105 | const char ArgIsConst[] = "amd.ArgIsConst"; |
| 106 | // Kernel argument is restrict qualified |
| 107 | const char ArgIsRestrict[] = "amd.ArgIsRestrict"; |
| 108 | // Kernel argument is volatile qualified |
| 109 | const char ArgIsVolatile[] = "amd.ArgIsVolatile"; |
| 110 | // Kernel argument is pipe qualified |
| 111 | const char ArgIsPipe[] = "amd.ArgIsPipe"; |
| 112 | // Required work group size |
| 113 | const char ReqdWorkGroupSize[] = "amd.ReqdWorkGroupSize"; |
| 114 | // Work group size hint |
| 115 | const char WorkGroupSizeHint[] = "amd.WorkGroupSizeHint"; |
| 116 | // Vector type hint |
| 117 | const char VecTypeHint[] = "amd.VecTypeHint"; |
| 118 | // Kernel index for device enqueue |
| 119 | const char KernelIndex[] = "amd.KernelIndex"; |
| 120 | // No partial work groups |
| 121 | const char NoPartialWorkGroups[] = "amd.NoPartialWorkGroups"; |
| 122 | // Prinf function call information |
| 123 | const char PrintfInfo[] = "amd.PrintfInfo"; |
| 124 | // The actual kernel argument access qualifier |
| 125 | const char ArgActualAcc[] = "amd.ArgActualAcc"; |
| 126 | // Alignment of pointee type |
| 127 | const char ArgPointeeAlign[] = "amd.ArgPointeeAlign"; |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 128 | |
| 129 | } // end namespace KeyName |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 130 | |
| 131 | namespace KernelArg { |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 132 | |
Yaxun Liu | 6389140 | 2016-09-07 17:44:00 +0000 | [diff] [blame] | 133 | enum Kind : uint8_t { |
| 134 | ByValue = 0, |
| 135 | GlobalBuffer = 1, |
| 136 | DynamicSharedPointer = 2, |
| 137 | Sampler = 3, |
| 138 | Image = 4, |
| 139 | Pipe = 5, |
| 140 | Queue = 6, |
| 141 | HiddenGlobalOffsetX = 7, |
| 142 | HiddenGlobalOffsetY = 8, |
| 143 | HiddenGlobalOffsetZ = 9, |
| 144 | HiddenNone = 10, |
| 145 | HiddenPrintfBuffer = 11, |
| 146 | HiddenDefaultQueue = 12, |
| 147 | HiddenCompletionAction = 13, |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | enum ValueType : uint16_t { |
| 151 | Struct = 0, |
| 152 | I8 = 1, |
| 153 | U8 = 2, |
| 154 | I16 = 3, |
| 155 | U16 = 4, |
| 156 | F16 = 5, |
| 157 | I32 = 6, |
| 158 | U32 = 7, |
| 159 | F32 = 8, |
| 160 | I64 = 9, |
| 161 | U64 = 10, |
| 162 | F64 = 11, |
| 163 | }; |
| 164 | |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 165 | // Avoid using 'None' since it conflicts with a macro in X11 header file. |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 166 | enum AccessQualifer : uint8_t { |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 167 | AccNone = 0, |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 168 | ReadOnly = 1, |
| 169 | WriteOnly = 2, |
| 170 | ReadWrite = 3, |
| 171 | }; |
Yaxun Liu | c7cbd72 | 2016-08-15 16:54:25 +0000 | [diff] [blame] | 172 | |
| 173 | enum AddressSpaceQualifer : uint8_t { |
| 174 | Private = 0, |
| 175 | Global = 1, |
| 176 | Constant = 2, |
| 177 | Local = 3, |
Yaxun Liu | 6389140 | 2016-09-07 17:44:00 +0000 | [diff] [blame] | 178 | Generic = 4, |
| 179 | Region = 5, |
Yaxun Liu | c7cbd72 | 2016-08-15 16:54:25 +0000 | [diff] [blame] | 180 | }; |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 181 | |
| 182 | } // end namespace KernelArg |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 183 | |
| 184 | // Invalid values are used to indicate an optional key should not be emitted. |
| 185 | const uint8_t INVALID_ADDR_QUAL = 0xff; |
| 186 | const uint8_t INVALID_ACC_QUAL = 0xff; |
| 187 | const uint32_t INVALID_KERNEL_INDEX = ~0U; |
| 188 | |
| 189 | namespace KernelArg { |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 190 | |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 191 | // In-memory representation of kernel argument information. |
| 192 | struct Metadata { |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 193 | uint32_t Size = 0; |
| 194 | uint32_t Align = 0; |
| 195 | uint32_t PointeeAlign = 0; |
| 196 | uint8_t Kind = 0; |
| 197 | uint16_t ValueType = 0; |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 198 | std::string TypeName; |
| 199 | std::string Name; |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 200 | uint8_t AddrQual = INVALID_ADDR_QUAL; |
| 201 | uint8_t AccQual = INVALID_ACC_QUAL; |
| 202 | uint8_t IsVolatile = 0; |
| 203 | uint8_t IsConst = 0; |
| 204 | uint8_t IsRestrict = 0; |
| 205 | uint8_t IsPipe = 0; |
| 206 | |
| 207 | Metadata() = default; |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 208 | }; |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 209 | |
| 210 | } // end namespace KernelArg |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 211 | |
| 212 | namespace Kernel { |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 213 | |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 214 | // In-memory representation of kernel information. |
| 215 | struct Metadata { |
| 216 | std::string Name; |
| 217 | std::string Language; |
| 218 | std::vector<uint8_t> LanguageVersion; |
| 219 | std::vector<uint32_t> ReqdWorkGroupSize; |
| 220 | std::vector<uint32_t> WorkGroupSizeHint; |
| 221 | std::string VecTypeHint; |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 222 | uint32_t KernelIndex = INVALID_KERNEL_INDEX; |
| 223 | uint8_t NoPartialWorkGroups = 0; |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 224 | std::vector<KernelArg::Metadata> Args; |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 225 | |
| 226 | Metadata() = default; |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 227 | }; |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 228 | |
| 229 | } // end namespace Kernel |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 230 | |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 231 | namespace IsaInfo { |
| 232 | |
| 233 | /// \brief In-memory representation of instruction set architecture |
| 234 | /// information. |
| 235 | struct Metadata { |
| 236 | /// \brief Wavefront size. |
| 237 | unsigned WavefrontSize = 0; |
| 238 | /// \brief Local memory size in bytes. |
| 239 | unsigned LocalMemorySize = 0; |
| 240 | /// \brief Number of execution units per compute unit. |
| 241 | unsigned EUsPerCU = 0; |
| 242 | /// \brief Maximum number of waves per execution unit. |
| 243 | unsigned MaxWavesPerEU = 0; |
| 244 | /// \brief Maximum flat work group size. |
| 245 | unsigned MaxFlatWorkGroupSize = 0; |
| 246 | /// \brief SGPR allocation granularity. |
| 247 | unsigned SGPRAllocGranule = 0; |
| 248 | /// \brief Total number of SGPRs. |
| 249 | unsigned TotalNumSGPRs = 0; |
| 250 | /// \brief Addressable number of SGPRs. |
| 251 | unsigned AddressableNumSGPRs = 0; |
| 252 | /// \brief VGPR allocation granularity. |
| 253 | unsigned VGPRAllocGranule = 0; |
| 254 | /// \brief Total number of VGPRs. |
| 255 | unsigned TotalNumVGPRs = 0; |
| 256 | /// \brief Addressable number of VGPRs. |
| 257 | unsigned AddressableNumVGPRs = 0; |
| 258 | |
| 259 | Metadata() = default; |
| 260 | }; |
| 261 | |
| 262 | } // end namespace IsaInfo |
| 263 | |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 264 | namespace Program { |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 265 | |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 266 | // In-memory representation of program information. |
| 267 | struct Metadata { |
| 268 | std::vector<uint8_t> MDVersionSeq; |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 269 | IsaInfo::Metadata IsaInfo; |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 270 | std::vector<std::string> PrintfInfo; |
| 271 | std::vector<Kernel::Metadata> Kernels; |
| 272 | |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 273 | explicit Metadata() = default; |
Yaxun Liu | 07d659b | 2016-12-14 17:16:52 +0000 | [diff] [blame] | 274 | |
| 275 | // Construct from an YAML string. |
| 276 | explicit Metadata(const std::string &YAML); |
| 277 | |
| 278 | // Convert to YAML string. |
| 279 | std::string toYAML(); |
| 280 | |
| 281 | // Convert from YAML string. |
| 282 | static Metadata fromYAML(const std::string &S); |
| 283 | }; |
Eugene Zelenko | 734bb7b | 2017-01-20 17:52:16 +0000 | [diff] [blame] | 284 | |
| 285 | } //end namespace Program |
| 286 | |
| 287 | } // end namespace RuntimeMD |
| 288 | } // end namespace AMDGPU |
Yaxun Liu | a711cc7 | 2016-07-16 05:09:21 +0000 | [diff] [blame] | 289 | |
| 290 | #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H |