CLRX  1
An unofficial OpenCL extensions designed for Radeon GPUs
CLHelper.h
Go to the documentation of this file.
1 /*
2  * CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3  * Copyright (C) 2014-2018 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_CLHELPER_H__
24 #define __CLRX_CLHELPER_H__
25 
26 #include <CLRX/Config.h>
27 #include <exception>
28 #include <vector>
29 #include <utility>
30 #ifdef __APPLE__
31 # include <OpenCL/cl.h>
32 #else
33 # include <CL/cl.h>
34 #endif
35 #include <CLRX/amdasm/Commons.h>
36 #include <CLRX/utils/Containers.h>
37 #include <CLRX/utils/CString.h>
38 #include <CLRX/utils/Utilities.h>
39 #include <CLRX/utils/GPUId.h>
40 
41 
42 namespace CLRX
43 {
44 
46 class CLError: public Exception
47 {
48 private:
49  cl_int error;
50 public:
52  CLError();
53 
55  explicit CLError(const char* _description);
56 
58  CLError(cl_int _error, const char* _description);
59 
61  virtual ~CLError() noexcept;
62 
64  const char* what() const noexcept;
65 
67  int code() const
68  { return error; }
69 };
70 
72 extern cl_platform_id chooseCLPlatformForCLRX();
73 
75 extern std::vector<cl_platform_id> chooseCLPlatformsForCLRX();
76 
77 enum : Flags
78 {
81 };
82 
84 struct CLAsmSetup
85 {
90  bool is64Bit;
94 };
95 
97 extern CLAsmSetup assemblerSetupForCLDevice(cl_device_id clDevice, Flags flags = 0,
98  Flags asmFlags = 0);
99 
101 extern Array<cxbyte> createBinaryForOpenCL(const CLAsmSetup& asmSetup,
102  const char* sourceCode, size_t sourceCodeLen = 0);
103 
105 extern Array<cxbyte> createBinaryForOpenCL(const CLAsmSetup& asmSetup,
106  const std::vector<std::pair<CString, uint64_t> >& defSymbols,
107  const char* sourceCode, size_t sourceCodeLen = 0);
108 
110 extern cl_program createProgramForCLDevice(cl_context clContext, cl_device_id clDevice,
111  const CLAsmSetup& asmSetup, const Array<cxbyte>& binary,
112  CString* buildLog = nullptr);
113 
115 extern cl_program createProgramForCLDevice(cl_context clContext, cl_device_id clDevice,
116  const CLAsmSetup& asmSetup, const char* sourceCode, size_t sourceCodeLen = 0,
117  CString* buildLog = nullptr);
118 
120 extern cl_program createProgramForCLDevice(cl_context clContext, cl_device_id clDevice,
121  const CLAsmSetup& asmSetup,
122  const std::vector<std::pair<CString, uint64_t> >& defSymbols,
123  const char* sourceCode, size_t sourceCodeLen = 0,
124  CString* buildLog = nullptr);
125 
126 };
127 
128 #endif
cl_program createProgramForCLDevice(cl_context clContext, cl_device_id clDevice, const CLAsmSetup &asmSetup, const Array< cxbyte > &binary, CString *buildLog=nullptr)
create (build program) binary for OpenCL device
common definitions for assembler and disassembler
int code() const
get OpenCL error code
Definition: CLHelper.h:67
uint32_t Flags
type for declaring various flags
Definition: Utilities.h:97
BinaryFormat
binary for Disassembler
Definition: Commons.h:33
std::vector< cl_platform_id > chooseCLPlatformsForCLRX()
choose suitable OpenCL many platforms for CLRX assembler programs
structure that holds assembler setup for OpenCL programs
Definition: CLHelper.h:84
an array class
Definition: Containers.h:38
bool newROCmBinFormat
new ROCm binary format
Definition: CLHelper.h:93
CLAsmSetup assemblerSetupForCLDevice(cl_device_id clDevice, Flags flags=0, Flags asmFlags=0)
get assembler setup(compile assembler code) binary for OpenCL device
Configuration header.
Array< cxbyte > createBinaryForOpenCL(const CLAsmSetup &asmSetup, const char *sourceCode, size_t sourceCodeLen=0)
create program binary for OpenCL
bool is64Bit
if binary is 64-bit
Definition: CLHelper.h:90
force using AMD OpenCL 2.0 binary format
Definition: CLHelper.h:79
virtual ~CLError() noexcept
destructor
BinaryFormat binaryFormat
binary format
Definition: CLHelper.h:87
main namespace
Definition: AsmDefs.h:38
error class based on std::exception
Definition: CLHelper.h:46
unsigned int cxuint
unsigned int
Definition: Config.h:223
const char * what() const noexcept
get what
GPUDeviceType
type of GPU device
Definition: GPUId.h:51
CString options
OpenCL base options.
Definition: CLHelper.h:91
utilities for other libraries and programs
exception class
Definition: Utilities.h:58
Flags asmFlags
assembler flags
Definition: CLHelper.h:92
force using AMD OpenCL 1.2 binary format
Definition: CLHelper.h:80
GPU identification utilities.
cxuint driverVersion
driver version
Definition: CLHelper.h:88
cl_platform_id chooseCLPlatformForCLRX()
choose suitable OpenCL platform for CLRX assembler programs
GPUDeviceType deviceType
device typ
Definition: CLHelper.h:86
cxuint llvmVersion
LLVM version.
Definition: CLHelper.h:89
simple C-string container
Definition: CString.h:38
containers and other utils for other libraries and programs
C-style string class.