LLVM  4.0.0
AMDGPURuntimeMetadata.h
Go to the documentation of this file.
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.
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 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.
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 
35 #include <cstdint>
36 #include <vector>
37 #include <string>
38 
39 namespace AMDGPU {
40 
41 namespace RuntimeMD {
42 
43  // Version and revision of runtime metadata
44  const unsigned char MDVersion = 2;
45  const unsigned char MDRevision = 0;
46 
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
75  }
76 
77  namespace KernelArg {
78  enum Kind : uint8_t {
79  ByValue = 0,
82  Sampler = 3,
83  Image = 4,
84  Pipe = 5,
85  Queue = 6,
89  HiddenNone = 10,
93  };
94 
95  enum ValueType : uint16_t {
96  Struct = 0,
97  I8 = 1,
98  U8 = 2,
99  I16 = 3,
100  U16 = 4,
101  F16 = 5,
102  I32 = 6,
103  U32 = 7,
104  F32 = 8,
105  I64 = 9,
106  U64 = 10,
107  F64 = 11,
108  };
109 
110  // Avoid using 'None' since it conflicts with a macro in X11 header file.
111  enum AccessQualifer : uint8_t {
112  AccNone = 0,
113  ReadOnly = 1,
116  };
117 
118  enum AddressSpaceQualifer : uint8_t {
119  Private = 0,
120  Global = 1,
121  Constant = 2,
122  Local = 3,
123  Generic = 4,
124  Region = 5,
125  };
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;
132 
133  namespace KernelArg {
134  // In-memory representation of kernel argument information.
135  struct Metadata {
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),
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;
166  std::vector<KernelArg::Metadata> Args;
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  }
190 } // namespace RuntimeMD
191 } // namespace AMDGPU
192 
193 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURUNTIMEMETADATA_H
std::vector< KernelArg::Metadata > Args
std::vector< Kernel::Metadata > Kernels
const uint8_t INVALID_ADDR_QUAL
static Metadata fromYAML(const std::string &S)
const uint8_t INVALID_ACC_QUAL
const unsigned char MDRevision
const uint32_t INVALID_KERNEL_INDEX
const unsigned char MDVersion