17 #include "../../common/helper/helper.hpp" 30 #include "errors_map.txt" 41 #ifdef __CL_ENABLE_EXCEPTIONS 42 #define GET_DEVICE_INFO_NAME_TYPE(NAME, TYPE) \ 44 get_device_info_##NAME(const cl::Device &device, cl_device_info info) { \ 48 const cl_int error = device.getInfo(info, &value); \ 50 if (error != CL_SUCCESS) { \ 51 std::cerr << "! Device::getInfo(" << info << ") error in get " \ 53 << error_name(error) << '"' <<std::endl; \ 56 catch (const cl::Error &e) { \ 57 std::cerr << "! Device::getInfo(" << info << ") exception in get " \ 59 << e.what() << '"' << std::endl; \ 65 #define GET_DEVICE_INFO_NAME_TYPE(NAME, TYPE) \ 67 get_device_info_##NAME(const cl::Device &device, cl_device_info info) { \ 70 const cl_int error = device.getInfo(info, &value); \ 72 if (error != CL_SUCCESS) { \ 73 std::cerr << "! Device::getInfo(" << info << ") error in get " \ 75 << error_name(error) << '"' <<std::endl; \ 82 #define GET_DEVICE_INFO_TYPE(TYPE) GET_DEVICE_INFO_NAME_TYPE(TYPE, TYPE) 102 #undef GET_DEVICE_INFO_NAME_TYPE 103 #undef GET_DEVICE_INFO_TYPE 110 #ifdef __CL_ENABLE_EXCEPTIONS 113 const cl_int error = device.getInfo(info, &value);
115 if (error != CL_SUCCESS) {
116 std::cerr <<
"! Device::getInfo(" << info <<
") error in get string: \"" 119 #ifdef __CL_ENABLE_EXCEPTIONS 121 catch (
const cl::Error &e) {
122 std::cerr <<
"! Device::getInfo(" << info <<
") exception to get string: \"" 123 << e.what() <<
'"' << std::endl;
133 std::vector<cl::Platform> platforms;
135 cl::Platform::get(&platforms);
136 for (cl::Platform platform : platforms) {
137 std::vector<cl::Device> devices;
139 platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
141 if (!devices.empty()) {
146 std::cerr <<
"! No GPU found!" << std::endl;
164 std::cout <<
" Driver version: \"";
167 std::cout <<
" Device name: \"";
170 std::cout <<
" address_bits: ";
173 std::cout <<
" available?: ";
176 std::cout <<
" built in kernels: \"";
179 std::cout <<
" compiler available?: ";
182 std::cout <<
" double fp config: ";
185 std::cout <<
" endian little? ";
188 std::cout <<
" extensions: \"";
191 std::cout <<
" global mem cache size: ";
194 std::cout <<
" global mem cache type: ";
197 std::cout <<
" global mem cacheline size: ";
200 std::cout <<
" global mem size: ";
203 std::cout <<
" image max array size: ";
206 std::cout <<
" image max buffer size: ";
209 std::cout <<
" image support? ";
212 std::cout <<
" linker available?: ";
215 std::cout <<
" local mem size: ";
218 std::cout <<
" local mem type: ";
221 std::cout <<
" max clock frequency: ";
224 std::cout <<
" max compute units: ";
227 std::cout <<
" max constant buffer size: ";
230 std::cout <<
" max mem alloc size: ";
233 std::cout <<
" max work group size: ";
236 std::cout <<
" max work item sizes:";
238 std::cout <<
' ' << item_size;
240 std::cout << std::endl;
242 std::cout <<
" mem base addr align: ";
245 std::cout <<
" min_data_type_align_size: ";
248 std::cout <<
" OpenCL C version: \"";
251 std::cout <<
" Profile: \"";
254 std::cout <<
" SPIR versions: \"";
257 std::cout <<
" type: ";
260 std::cout <<
" version: \"";
263 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 265 std::cout <<
" compute capability major NV: ";
268 std::cout <<
" compute capability minor NV: ";
271 std::cout <<
" registers per block NV: ";
274 std::cout <<
" warp size NV: ";
277 std::cout <<
" GPU overlap NV: ";
280 std::cout <<
" kernel exec timeout NV: ";
283 std::cout <<
" integrated memory NV: ";
291 bool only_if_error,
bool exit_if_error) {
292 if ((code != 0) || !only_if_error) {
293 if (!message.empty()) {
294 message =
" " + message;
297 std::cerr <<
"! OpenCL error " 312 std::cout << std::string(30,
'=') << std::endl;
314 std::string platform_name;
315 std::string platform_vendor;
316 std::string platform_version;
317 std::string platform_profile;
318 std::string platform_extensions;
320 platform.getInfo(CL_PLATFORM_NAME, &platform_name);
321 platform.getInfo(CL_PLATFORM_VENDOR, &platform_vendor);
322 platform.getInfo(CL_PLATFORM_VERSION, &platform_version);
323 platform.getInfo(CL_PLATFORM_PROFILE, &platform_profile);
324 platform.getInfo(CL_PLATFORM_EXTENSIONS, &platform_extensions);
334 std::vector<cl::Device> devices;
337 platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
338 for (cl::Device device : devices) {
346 std::vector<cl::Platform> platforms;
349 cl::Platform::get(&platforms);
350 for (cl::Platform platform : platforms) {
cl_ulong get_device_info_cl_ulong(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
cl::Device get_first_device_gpu()
Return the first GPU device found. If not found then print an error message and exit.
cl_device_type get_device_info_cl_device_type(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
std::string remove_last_if_null(const std::string &s)
If s terminates by a null character then return a copy of s without this last character, else return s.
std::string get_device_info_string(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
#define GET_DEVICE_INFO_NAME_TYPE(NAME, TYPE)
cl_uint get_device_info_cl_uint(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
std::string error_name(cl_int code)
Return the error name corresponding to the error code.
cl_device_local_mem_type get_device_info_cl_device_local_mem_type(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
cl_device_fp_config get_device_info_cl_device_fp_config(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
void print_device(const cl::Device &device)
Print information on this device.
Some generic helper functions for programs.
void print_platform(const cl::Platform &platform)
Print information on this platform.
void print_error(cl_int code, std::string message, bool only_if_error, bool exit_if_error)
Print an error message corresponding to the error code.
size_t get_device_info_size_t(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
#define GET_DEVICE_INFO_TYPE(TYPE)
void print_platforms()
Print information on all platforms.
cl_bool get_device_info_cl_bool(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
cl_device_mem_cache_type get_device_info_cl_device_mem_cache_type(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.
const std::map< int32_t, std::string > errors_map
Table associating error codes to error names.
std::string to_string(bool b)
Return the string "true" if b, else "false".
VECTOR_CLASS<::size_t > get_device_info_vector_size_t(const cl::Device &device, cl_device_info info)
Return the corresponding information about the device.