CLRX  1
An unofficial OpenCL extensions designed for Radeon GPUs
AmdBinGen.h
Go to the documentation of this file.
1 /*
2  * CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3  * Copyright (C) 2014-2017 Mateusz Szpakowski
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
23 #ifndef __CLRX_AMDBINGEN_H__
24 #define __CLRX_AMDBINGEN_H__
25 
26 #include <CLRX/Config.h>
27 #include <cstddef>
28 #include <cstdint>
29 #include <string>
30 #include <ostream>
31 #include <vector>
33 #include <CLRX/utils/Containers.h>
34 #include <CLRX/utils/GPUId.h>
35 #include <CLRX/utils/InputOutput.h>
36 
38 namespace CLRX
39 {
40 
43 {
51  size_t constSpaceSize;
52  uint32_t resId;
54 
56  static AmdKernelArgInput arg(const CString& argName, const CString& typeName,
57  KernelArgType argType)
58  {
59  return { argName, typeName, argType, KernelArgType::VOID, KernelPtrSpace::NONE,
60  KARG_PTR_NORMAL, 0, 0, 0, true };
61  }
63  static AmdKernelArgInput gptr(const CString& argName, const CString& typeName,
64  KernelArgType ptrType, cxuint structSize = 0, cxbyte ptrAccess = KARG_PTR_NORMAL,
65  uint32_t resId = BINGEN_DEFAULT, bool used = true)
66  {
67  return { argName, typeName, KernelArgType::POINTER, ptrType,
69  }
71  static AmdKernelArgInput cptr(const CString& argName, const CString& typeName,
72  KernelArgType ptrType, cxuint structSize = 0, cxbyte ptrAccess = KARG_PTR_NORMAL,
73  size_t constSpaceSize = 0, uint32_t resId = BINGEN_DEFAULT, bool used = true)
74  {
75  return { argName, typeName, KernelArgType::POINTER, ptrType,
77  }
79  static AmdKernelArgInput lptr(const CString& argName, const CString& typeName,
80  KernelArgType ptrType, cxuint structSize = 0)
81  {
82  return { argName, typeName, KernelArgType::POINTER, ptrType,
84  }
85 
87  static AmdKernelArgInput img(const CString& argName, const CString& typeName,
88  KernelArgType imgType, cxbyte ptrAccess = KARG_PTR_READ_ONLY,
89  uint32_t resId = BINGEN_DEFAULT, bool used = true)
90  {
91  return { argName, typeName, imgType, KernelArgType::VOID, KernelPtrSpace::GLOBAL,
92  ptrAccess, 0, 0, resId, used };
93  }
94 };
95 
98 {
99  uint32_t dataClass;
100  uint32_t apiSlot;
101  uint32_t regStart;
102  uint32_t regSize;
103 };
104 
107 {
108  std::vector<AmdKernelArgInput> args;
109  std::vector<cxuint> samplers;
110  uint32_t dimMask;
111  uint32_t reqdWorkGroupSize[3];
112  uint32_t usedVGPRsNum;
113  uint32_t usedSGPRsNum;
114  uint32_t pgmRSRC2;
115  uint32_t floatMode;
116  size_t hwLocalSize;
117  uint32_t hwRegion;
118  uint32_t scratchBufferSize;
119  uint32_t uavPrivate;
120  uint32_t uavId;
121  uint32_t constBufferId;
122  uint32_t printfId;
123  uint32_t privateId;
124  uint32_t earlyExit;
125  uint32_t condOut;
126  bool ieeeMode;
128  bool tgSize;
129  bool usePrintf;
131  std::vector<AmdUserData> userDatas;
132 };
133 
136 {
138  size_t dataSize;
139  const cxbyte* data;
140  size_t headerSize;
141  const cxbyte* header;
142  size_t metadataSize;
143  const char* metadata;
144  std::vector<CALNoteInput> calNotes;
145  bool useConfig;
147  size_t codeSize;
148  const cxbyte* code;
149  std::vector<BinSection> extraSections;
150  std::vector<BinSymbol> extraSymbols;
151 };
152 
154 struct AmdInput
155 {
156  bool is64Bit;
158  size_t globalDataSize;
160  uint32_t driverVersion;
163  std::vector<AmdKernelInput> kernels;
164  std::vector<BinSection> extraSections;
165  std::vector<BinSymbol> extraSymbols;
166 
168  void addKernel(const AmdKernelInput& kernelInput);
170  void addKernel(AmdKernelInput&& kernelInput);
171 
173 
181  void addKernel(const char* kernelName, size_t codeSize, const cxbyte* code,
182  const AmdKernelConfig& config, size_t dataSize = 0,
183  const cxbyte* data = nullptr);
185 
196  void addKernel(const char* kernelName, size_t codeSize, const cxbyte* code,
197  const std::vector<CALNoteInput>& calNotes, const cxbyte* header,
198  size_t metadataSize, const char* metadata,
199  size_t dataSize = 0, const cxbyte* data = nullptr);
200 
202  void addEmptyKernel(const char* kernelName);
203 };
204 
207 {
208 private:
209  bool manageable;
210  const AmdInput* input;
211 
212  void generateInternal(std::ostream* osPtr, std::vector<char>* vPtr,
213  Array<cxbyte>* aPtr) const;
214 public:
216 
218  AmdGPUBinGenerator(const AmdInput* amdInput);
220 
228  AmdGPUBinGenerator(bool _64bitMode, GPUDeviceType deviceType, uint32_t driverVersion,
229  size_t globalDataSize, const cxbyte* globalData,
230  const std::vector<AmdKernelInput>& kernelInputs);
232  AmdGPUBinGenerator(bool _64bitMode, GPUDeviceType deviceType, uint32_t driverVersion,
233  size_t globalDataSize, const cxbyte* globalData,
234  std::vector<AmdKernelInput>&& kernelInputs);
236 
238  const AmdInput* getInput() const
239  { return input; }
240 
242  void setInput(const AmdInput* input);
243 
245  void generate(Array<cxbyte>& array) const;
246 
248  void generate(std::ostream& os) const;
249 
251  void generate(std::vector<char>& vector) const;
252 };
253 
255 extern uint32_t detectAmdDriverVersion();
256 
257 };
258 
259 #endif
AmdKernelConfig config
kernel&#39;s configuration
Definition: AmdBinGen.h:146
uint32_t condOut
CALNOTE_CONDOUT value.
Definition: AmdBinGen.h:125
static AmdKernelArgInput lptr(const CString &argName, const CString &typeName, KernelArgType ptrType, cxuint structSize=0)
create local pointer
Definition: AmdBinGen.h:79
CString driverInfo
driver info
Definition: AmdBinGen.h:162
pointer to local memory
non copyable and non movable base structure (class)
Definition: Utilities.h:43
uint32_t constBufferId
constant buffer id
Definition: AmdBinGen.h:121
uint32_t scratchBufferSize
size of scratch buffer
Definition: AmdBinGen.h:118
KernelPtrSpace
kernel pointer type of argument
Definition: AmdBinaries.h:103
uint32_t printfId
UAV ID for printf.
Definition: AmdBinGen.h:122
uint32_t detectAmdDriverVersion()
detect driver version in the system
pointer to global memory
uint32_t dataClass
type of data
Definition: AmdBinGen.h:99
none operation
std::vector< BinSection > extraSections
extra sections
Definition: AmdBinGen.h:164
uint32_t uavPrivate
uav private size
Definition: AmdBinGen.h:119
size_t metadataSize
metadata size (used if useConfig=false)
Definition: AmdBinGen.h:142
bool usePrintf
if kernel uses printf function
Definition: AmdBinGen.h:129
std::vector< BinSection > extraSections
list of extra sections
Definition: AmdBinGen.h:149
size_t dataSize
data size
Definition: AmdBinGen.h:138
uint32_t privateId
private id (???)
Definition: AmdBinGen.h:123
bool tgSize
enable tgSize
Definition: AmdBinGen.h:128
GPUDeviceType deviceType
GPU device type.
Definition: AmdBinGen.h:157
AMD kernel input.
Definition: AmdBinGen.h:135
uint32_t usedVGPRsNum
number of used VGPRs
Definition: AmdBinGen.h:112
const cxbyte * code
code
Definition: AmdBinGen.h:148
AMD OpenCL kernel argument description.
Definition: AmdBinGen.h:42
an array class
Definition: Containers.h:38
bool useConstantData
if const data required
Definition: AmdBinGen.h:130
KernelArgType argType
argument type
Definition: AmdBinGen.h:46
Configuration header.
uint32_t regStart
number of beginning SGPR register
Definition: AmdBinGen.h:101
const cxbyte * data
data
Definition: AmdBinGen.h:139
bool ieeeMode
IEEE mode.
Definition: AmdBinGen.h:126
kernel configuration
Definition: AmdBinGen.h:106
std::vector< AmdKernelInput > kernels
kernels
Definition: AmdBinGen.h:163
static AmdKernelArgInput arg(const CString &argName, const CString &typeName, KernelArgType argType)
create simple type argument
Definition: AmdBinGen.h:56
static AmdKernelArgInput cptr(const CString &argName, const CString &typeName, KernelArgType ptrType, cxuint structSize=0, cxbyte ptrAccess=KARG_PTR_NORMAL, size_t constSpaceSize=0, uint32_t resId=BINGEN_DEFAULT, bool used=true)
create constant pointer
Definition: AmdBinGen.h:71
uint32_t earlyExit
CALNOTE_EARLYEXIT value.
Definition: AmdBinGen.h:124
user data for in CAL PROGINFO
Definition: AmdBinGen.h:97
size_t hwLocalSize
used local size (not local defined in kernel arguments)
Definition: AmdBinGen.h:116
KernelArgType
kernel argument type
Definition: AmdBinaries.h:72
uint32_t floatMode
float mode
Definition: AmdBinGen.h:115
input output utilities
size_t constSpaceSize
constant space size
Definition: AmdBinGen.h:51
AMD binaries handling.
unsigned char cxbyte
unsigned byte
Definition: Config.h:215
std::vector< CALNoteInput > calNotes
CAL Note array (used if useConfig=false)
Definition: AmdBinGen.h:144
read only image
Definition: AmdBinaries.h:115
main namespace
Definition: AsmDefs.h:38
CString compileOptions
compile options
Definition: AmdBinGen.h:161
if set in field then field has been filled later
Definition: ElfBinaries.h:50
KernelArgType pointerType
pointer type
Definition: AmdBinGen.h:47
unsigned int cxuint
unsigned int
Definition: Config.h:223
CString typeName
name of type of argument
Definition: AmdBinGen.h:45
cxbyte ptrAccess
pointer access flags
Definition: AmdBinGen.h:49
bool is64Bit
is 64-bit binary
Definition: AmdBinGen.h:156
uint32_t hwRegion
hwRegion ????
Definition: AmdBinGen.h:117
std::vector< AmdKernelArgInput > args
arguments
Definition: AmdBinGen.h:108
uint32_t dimMask
mask of dimension (bits: 0 - X, 1 - Y, 2 - Z)
Definition: AmdBinGen.h:110
size_t globalDataSize
global constant data size
Definition: AmdBinGen.h:158
KernelPtrSpace ptrSpace
pointer space for argument if argument is pointer or image
Definition: AmdBinGen.h:48
cxuint structSize
structure size (if structure)
Definition: AmdBinGen.h:50
GPUDeviceType
type of GPU device
Definition: GPUId.h:51
uint32_t uavId
uavid, first uavid for kernel argument minus 1
Definition: AmdBinGen.h:120
cxbyte exceptions
enabled exception handling
Definition: AmdBinGen.h:127
static AmdKernelArgInput gptr(const CString &argName, const CString &typeName, KernelArgType ptrType, cxuint structSize=0, cxbyte ptrAccess=KARG_PTR_NORMAL, uint32_t resId=BINGEN_DEFAULT, bool used=true)
create global pointer
Definition: AmdBinGen.h:63
std::vector< AmdUserData > userDatas
user datas
Definition: AmdBinGen.h:131
CString kernelName
kernel name
Definition: AmdBinGen.h:137
uint32_t resId
uavid or cbid or counterId
Definition: AmdBinGen.h:52
no special flags
Definition: AmdBinaries.h:114
const cxbyte * header
kernel header size (used if useConfig=false)
Definition: AmdBinGen.h:141
std::vector< BinSymbol > extraSymbols
list of extra symbols
Definition: AmdBinGen.h:150
CString argName
argument name
Definition: AmdBinGen.h:44
uint32_t usedSGPRsNum
number of used SGPRs
Definition: AmdBinGen.h:113
size_t headerSize
kernel header size (used if useConfig=false)
Definition: AmdBinGen.h:140
GPU identification utilities.
const cxbyte * globalData
global constant data
Definition: AmdBinGen.h:159
uint32_t regSize
number of used SGPRS registers
Definition: AmdBinGen.h:102
uint32_t pgmRSRC2
pgmRSRC2 register value
Definition: AmdBinGen.h:114
main Input for AmdGPUBinGenerator
Definition: AmdBinGen.h:154
size_t codeSize
code size
Definition: AmdBinGen.h:147
uint32_t driverVersion
driver version (majorVersion*100 + minorVersion)
Definition: AmdBinGen.h:160
static AmdKernelArgInput img(const CString &argName, const CString &typeName, KernelArgType imgType, cxbyte ptrAccess=KARG_PTR_READ_ONLY, uint32_t resId=BINGEN_DEFAULT, bool used=true)
create image
Definition: AmdBinGen.h:87
std::vector< BinSymbol > extraSymbols
extra symbols
Definition: AmdBinGen.h:165
uint32_t apiSlot
slot
Definition: AmdBinGen.h:100
const AmdInput * getInput() const
get input
Definition: AmdBinGen.h:238
main AMD GPU Binary generator
Definition: AmdBinGen.h:206
cxbyte used
flags that indicate how kernel uses this argument (1 - used)
Definition: AmdBinGen.h:53
std::vector< cxuint > samplers
defined samplers
Definition: AmdBinGen.h:109
bool useConfig
true if configuration has been used to generate binary
Definition: AmdBinGen.h:145
simple C-string container
Definition: CString.h:38
containers and other utils for other libraries and programs
const char * metadata
kernel&#39;s metadata (used if useConfig=false)
Definition: AmdBinGen.h:143
pointer to constant memory