19 unsigned int iDivUp(
unsigned int dividend,
unsigned int divisor){
20 return (dividend % divisor == 0) ? (dividend / divisor) : (dividend / divisor + 1);
25 cl_uint num_platforms = 0;
26 cl_platform_id* clPlatformIDs;
29 ciErrNum = clGetPlatformIDs( 0,
nullptr, &num_platforms);
30 if ( ciErrNum != CL_SUCCESS)
32 MITK_ERROR<<
" Error " << ciErrNum <<
" in clGetPlatformIDs() \n";
33 throw std::bad_exception();
37 clPlatformIDs =
new cl_platform_id[num_platforms];
39 ciErrNum = clGetPlatformIDs( num_platforms, clPlatformIDs,
nullptr);
40 if(ciErrNum == CL_SUCCESS)
42 *selectedPlatform = clPlatformIDs[0];
54 MITK_INFO <<
"Examining cl_mem object: " << memobj
55 <<
"\n------------------\n";
58 cl_mem_object_type objtype;
59 clErr = clGetMemObjectInfo( memobj, CL_MEM_TYPE,
sizeof(cl_mem_object_type),&objtype,
nullptr);
64 case CL_MEM_OBJECT_BUFFER:
65 MITK_INFO <<
"CL_MEM_TYPE \t" <<
"BUFFER_OBJ" <<
"\n";
67 case CL_MEM_OBJECT_IMAGE2D:
68 MITK_INFO <<
"CL_MEM_TYPE \t" <<
"2D IMAGE" <<
"\n";
70 case CL_MEM_OBJECT_IMAGE3D:
71 MITK_INFO <<
"CL_MEM_TYPE \t" <<
"3D IMAGE" <<
"\n";
74 MITK_INFO <<
"CL_MEM_TYPE \t" <<
"[could not resolve]" <<
"\n";
80 clErr = clGetMemObjectInfo( memobj, CL_MEM_FLAGS,
sizeof(cl_mem_flags),&flags,
nullptr);
85 case CL_MEM_READ_ONLY:
86 MITK_INFO <<
"CL_MEM_FLAGS \t" <<
"CL_MEM_READ_ONLY" <<
"\n";
88 case CL_MEM_WRITE_ONLY:
89 MITK_INFO <<
"CL_MEM_FLAGS \t" <<
"CL_MEM_WRITE_ONLY" <<
"\n";
91 case CL_MEM_READ_WRITE:
92 MITK_INFO <<
"CL_MEM_FLAGS \t" <<
"CL_MEM_READ_WRITE" <<
"\n";
95 MITK_INFO <<
"CL_MEM_FLAGS \t" <<
"not resolved, " << flags <<
"\n";
101 clErr = clGetMemObjectInfo( memobj, CL_MEM_SIZE,
sizeof(memsize),&memsize,
nullptr);
104 MITK_INFO <<
"CL_MEM_SIZE \t" << memsize <<
"\n";
108 clErr = clGetMemObjectInfo( memobj, CL_MEM_HOST_PTR,
sizeof(
void*), (
void*) &hostptr,
nullptr);
111 MITK_INFO <<
"CL_MEM_HOST_PTR \t" << hostptr <<
"\n";
115 clErr = clGetMemObjectInfo( memobj, CL_MEM_CONTEXT,
sizeof(cl_context), &gpuctxt,
nullptr);
118 MITK_INFO <<
"CL_CONTEXT \t\t" << gpuctxt <<
"\n";
122 clErr = clGetMemObjectInfo( memobj, CL_MEM_REFERENCE_COUNT,
sizeof(cl_uint), &refs,
nullptr);
125 MITK_INFO <<
"CL_REF_COUNT \t" << refs <<
"\n";
127 MITK_INFO <<
"================== \n" << std::endl;
132 char device_string[1024];
134 clGetDeviceInfo(device, CL_DEVICE_NAME,
sizeof(device_string), &device_string,
nullptr);
135 MITK_INFO(
"ocl.log")<<
" Device : " << device_string;
139 clGetDeviceInfo(device, CL_DEVICE_TYPE,
sizeof(type), &type,
nullptr);
140 if( type & CL_DEVICE_TYPE_CPU )
141 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_TYPE: CL_DEVICE_TYPE_CPU";
142 if( type & CL_DEVICE_TYPE_GPU )
143 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_TYPE: CL_DEVICE_TYPE_GPU";
144 if( type & CL_DEVICE_TYPE_ACCELERATOR )
145 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_TYPE: CL_DEVICE_TYPE_ACCELERATOR";
146 if( type & CL_DEVICE_TYPE_DEFAULT )
147 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_TYPE: CL_DEVICE_TYPE_DEFAULT";
150 cl_uint compute_units;
151 clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(compute_units), &compute_units,
nullptr);
152 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_MAX_COMPUTE_UNITS:" << compute_units;
155 size_t workitem_size[3];
156 clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_SIZES,
sizeof(workitem_size), &workitem_size,
nullptr);
157 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_MAX_WORK_ITEM_SIZES:\t"<< workitem_size[0]<< workitem_size[1]<< workitem_size[2];
160 size_t workgroup_size;
161 clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE,
sizeof(workgroup_size), &workgroup_size,
nullptr);
162 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_MAX_WORK_GROUP_SIZE:" << workgroup_size;
165 cl_uint clock_frequency;
166 clGetDeviceInfo(device, CL_DEVICE_MAX_CLOCK_FREQUENCY,
sizeof(clock_frequency), &clock_frequency,
nullptr);
167 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_MAX_CLOCK_FREQUENCY:"<< clock_frequency / 1000;
170 cl_bool image_support;
171 clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT,
sizeof(image_support), &image_support,
nullptr);
172 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_IMAGE_SUPPORT:\t" << image_support;
176 clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE,
sizeof(mem_size), &mem_size,
nullptr);
177 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_GLOBAL_MEM_SIZE:\t\t"<<(
unsigned int)(mem_size / (1024 * 1024))<<
"Mbytes";
180 clGetDeviceInfo(device, CL_DEVICE_LOCAL_MEM_SIZE,
sizeof(mem_size), &mem_size,
nullptr);
181 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_LOCAL_MEM_SIZE:\t\t"<< (
unsigned int)(mem_size / (1024)) <<
"KByte\n";
184 clGetDeviceInfo(device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE,
sizeof(mem_size), &mem_size,
nullptr);
185 MITK_INFO(
"ocl.log") <<
" CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:\t\t" << (
unsigned int)(mem_size / (1024)) <<
"KByte";
188 clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH,
sizeof(workgroup_size), &workgroup_size,
nullptr);
189 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_IMAGE2D_MAX_WIDTH:\t" << workgroup_size;
191 clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT,
sizeof(workgroup_size), &workgroup_size,
nullptr);
192 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_IMAGE2D_MAX_HEIGHT:\t" << workgroup_size;
194 clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_WIDTH,
sizeof(workgroup_size), &workgroup_size,
nullptr);
195 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_IMAGE3D_MAX_WIDTH:\t" << workgroup_size;
197 clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_HEIGHT,
sizeof(workgroup_size), &workgroup_size,
nullptr);
198 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_IMAGE3D_MAX_HEIGHT:\t" << workgroup_size;
200 clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_DEPTH,
sizeof(workgroup_size), &workgroup_size,
nullptr);
201 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_IMAGE3D_MAX_DEPTH:\t" << workgroup_size;
205 cl_command_queue_properties queue_properties;
206 clGetDeviceInfo(device, CL_DEVICE_QUEUE_PROPERTIES,
sizeof(queue_properties), &queue_properties,
nullptr);
207 if( queue_properties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE )
208 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_QUEUE_PROPERTIES:\t\t"<<
"CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE";
209 if( queue_properties & CL_QUEUE_PROFILING_ENABLE )
210 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_QUEUE_PROPERTIES:\t\t"<<
"CL_QUEUE_PROFILING_ENABLE";
217 clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE,
sizeof(mem_size), &mem_size,
nullptr);
223 std::string returnString(
"unkown error number: "+std::to_string(_clErr)+
" \n");
228 returnString =
"CL_SUCCESS\n";
230 case CL_DEVICE_NOT_FOUND:
231 returnString =
"CL_DEVICE_NOT_FOUND\n";
233 case CL_DEVICE_NOT_AVAILABLE:
234 returnString =
"CL_DEVICE_NOT_AVAILABLE\n";
239 case CL_MEM_OBJECT_ALLOCATION_FAILURE :
240 returnString =
"CL_MEM_OBJECT_ALLOCATION_FAILURE\n";
242 case CL_OUT_OF_RESOURCES:
243 returnString =
"CL_OUT_OF_RESOURCES\n";
245 case CL_OUT_OF_HOST_MEMORY:
246 returnString =
"CL_OUT_OF_HOST_MEMORY\n";
248 case CL_PROFILING_INFO_NOT_AVAILABLE:
249 returnString =
"CL_PROFILING_INFO_NOT_AVAILABLE\n";
251 case CL_MEM_COPY_OVERLAP:
252 returnString =
"CL_MEM_COPY_OVERLAP\n";
254 case CL_IMAGE_FORMAT_MISMATCH:
255 returnString =
"CL_IMAGE_FORMAT_MISMATCH\n";
257 case CL_IMAGE_FORMAT_NOT_SUPPORTED:
258 returnString =
"CL_IMAGE_FORMAT_NOT_SUPPORTED\n";
260 case CL_BUILD_PROGRAM_FAILURE:
261 returnString =
"CL_BUILD_PROGRAM_FAILURE\n";
264 returnString =
"CL_MAP_FAILURE\n";
266 case CL_INVALID_VALUE:
267 returnString =
"CL_INVALID_VALUE\n";
269 case CL_INVALID_DEVICE_TYPE:
270 returnString =
"CL_INVALID_DEVICE_TYPE\n";
272 case CL_INVALID_PLATFORM:
273 returnString =
"CL_INVALID_PLATFORM\n";
275 case CL_INVALID_DEVICE:
276 returnString =
"CL_INVALID_DEVICE\n";
278 case CL_INVALID_CONTEXT :
279 returnString =
"CL_INVALID_CONTEXT\n";
281 case CL_INVALID_QUEUE_PROPERTIES:
282 returnString =
"CL_INVALID_QUEUE_PROPERTIES\n";
284 case CL_INVALID_COMMAND_QUEUE:
285 returnString =
"CL_INVALID_COMMAND_QUEUE\n";
287 case CL_INVALID_HOST_PTR:
288 returnString =
"CL_INVALID_HOST_PTR\n";
290 case CL_INVALID_MEM_OBJECT:
291 returnString =
"CL_INVALID_MEM_OBJECT\n";
293 case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
294 returnString =
"CL_INVALID_IMAGE_FORMAT_DESCRIPTOR\n";
296 case CL_INVALID_IMAGE_SIZE:
297 returnString =
"CL_INVALID_IMAGE_SIZE\n";
299 case CL_INVALID_SAMPLER :
300 returnString =
"CL_INVALID_SAMPLER\n";
302 case CL_INVALID_BINARY:
303 returnString =
"CL_INVALID_BINARY\n";
305 case CL_INVALID_BUILD_OPTIONS:
306 returnString =
"CL_INVALID_BUILD_OPTIONS\n";
308 case CL_INVALID_PROGRAM:
309 returnString =
"CL_INVALID_PROGRAM\n";
311 case CL_INVALID_PROGRAM_EXECUTABLE:
312 returnString =
"CL_INVALID_PROGRAM_EXECUTABLE\n";
314 case CL_INVALID_KERNEL_NAME:
315 returnString =
"CL_INVALID_KERNEL_NAME\n";
317 case CL_INVALID_KERNEL_DEFINITION:
318 returnString =
"CL_INVALID_KERNEL_DEFINITION\n";
320 case CL_INVALID_KERNEL :
321 returnString =
"CL_INVALID_KERNEL\n";
323 case CL_INVALID_ARG_INDEX :
324 returnString =
"CL_INVALID_ARG_INDEX\n";
326 case CL_INVALID_ARG_VALUE :
327 returnString =
"CL_INVALID_ARG_VALUE\n";
329 case CL_INVALID_ARG_SIZE :
330 returnString =
"CL_INVALID_ARG_SIZE\n";
332 case CL_INVALID_KERNEL_ARGS :
333 returnString =
"CL_INVALID_KERNEL_ARGS\n";
335 case CL_INVALID_WORK_DIMENSION:
336 returnString =
"CL_INVALID_WORK_DIMENSION\n";
338 case CL_INVALID_WORK_GROUP_SIZE:
339 returnString =
"CL_INVALID_WORK_GROUP_SIZE\n";
341 case CL_INVALID_WORK_ITEM_SIZE:
342 returnString =
"CL_INVALID_WORK_ITEM_SIZE\n";
344 case CL_INVALID_GLOBAL_OFFSET:
345 returnString =
"CL_INVALID_GLOBAL_OFFSET\n";
347 case CL_INVALID_EVENT_WAIT_LIST:
348 returnString =
"CL_INVALID_EVENT_WAIT_LIST\n";
350 case CL_INVALID_EVENT:
351 returnString =
"CL_INVALID_EVENT\n";
353 case CL_INVALID_OPERATION:
354 returnString =
"CL_INVALID_OPERATION\n";
356 case CL_INVALID_GL_OBJECT:
357 returnString =
"CL_INVALID_GL_OBJECT\n";
359 case CL_INVALID_BUFFER_SIZE :
360 returnString =
"CL_INVALID_BUFFER_SIZE\n";
362 case CL_INVALID_MIP_LEVEL :
363 returnString =
"CL_INVALID_MIP_LEVEL\n";
374 if(_clErr == CL_SUCCESS)
375 MITK_WARN <<
"Called GetOclErr() with no error value: [CL_SUCCESS]";
384 MITK_ERROR<<
"OpenCL Error at " << filepath <<
":"<< lineno;
395 const unsigned int entries = 500;
396 cl_image_format* formats =
new cl_image_format[entries];
398 cl_uint _written = 0;
403 ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_READ_ONLY, _type, entries, formats, &_written);
406 MITK_INFO <<
"Supported Image Formats, Image: CL_MEM_READ_ONLY \n";
408 for (
unsigned int i=0; i<_written; i++)
416 ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_READ_WRITE, _type, entries, formats, &_written);
419 MITK_INFO <<
"Supported Image Formats, Image: CL_MEM_READ_WRITE (found: " << _written <<
") \n";
421 for (
unsigned int i=0; i<_written; i++)
429 ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_WRITE_ONLY, _type, entries, formats, &_written);
432 MITK_INFO <<
"Supported Image Formats, Image: CL_MEM_WRITE_ONLY (found: " << _written <<
") \n";
434 for (
unsigned int i=0; i<_written; i++)
469 return "CL_INTENSITY ";
472 return "CL_LUMINANCE ";
475 return "CL_SNORM_INT8 ";
478 return "CL_SNORM_INT16 ";
481 return "CL_UNORM_INT8 ";
484 return "CL_UNORM_INT16 ";
486 case CL_UNORM_SHORT_565:
487 return "CL_UNORM_SHORT_565 ";
489 case CL_UNORM_SHORT_555:
490 return "CL_UNORM_SHORT_555 ";
492 case CL_UNORM_INT_101010:
493 return "CL_UNORM_INT_101010 ";
496 return "CL_SIGNED_INT8 ";
498 case CL_SIGNED_INT16:
499 return "CL_SIGNED_INT16 ";
501 case CL_SIGNED_INT32:
502 return "CL_SIGNED_INT32 ";
504 case CL_UNSIGNED_INT8:
505 return "CL_UNSIGNED_INT8 ";
507 case CL_UNSIGNED_INT16:
508 return "CL_UNSIGNED_INT16 ";
510 case CL_UNSIGNED_INT32:
511 return "CL_UNSIGNED_INT32 ";
514 return "CL_HALF_FLOAT ";
531 clGetProgramInfo(clProg, CL_PROGRAM_NUM_DEVICES,
sizeof(cl_uint), &num_devices,
nullptr);
534 cl_device_id* devices = (cl_device_id*) malloc(num_devices *
sizeof(cl_device_id));
535 clGetProgramInfo(clProg, CL_PROGRAM_DEVICES, num_devices *
sizeof(cl_device_id), devices, 0);
538 size_t* binary_sizes = (
size_t*)malloc(num_devices *
sizeof(
size_t));
539 clGetProgramInfo(clProg, CL_PROGRAM_BINARY_SIZES, num_devices *
sizeof(
size_t), binary_sizes,
nullptr);
542 char** ptx_code = (
char**)malloc(num_devices *
sizeof(
char*));
543 for(
unsigned int i=0; i<num_devices; ++i)
545 ptx_code[i] = (
char*)malloc(binary_sizes[i]);
547 clGetProgramInfo(clProg, CL_PROGRAM_BINARIES, 0, ptx_code,
nullptr);
550 unsigned int idx = 0;
551 while((idx < num_devices) && (devices[idx] != clDev))
557 if( idx < num_devices )
559 MITK_INFO<<
"\n ---------------- \n Program Binary: \n -----------------------\n";
564 free( binary_sizes );
565 for(
unsigned int i=0; i<num_devices; ++i)
574 char cBuildLog[10240];
576 clGetProgramBuildInfo(clProg, clDev, CL_PROGRAM_BUILD_LOG,
sizeof(cBuildLog), cBuildLog,
nullptr);
577 MITK_INFO<<
"\n Program Build Log: \n -----------------------\n";
#define CHECK_OCL_ERR(_er)
unsigned int iDivUp(unsigned int dividend, unsigned int divisor)
Method to estimate an integer quotient C from given dividend and divisor higher or equal to the corre...
void GetOclError(int _clErr)
Checks whether the given value corresponds to an OpenCL Error value and prints this message out as MI...
void GetSupportedImageFormats(cl_context _context, cl_mem_object_type _type)
Print out all supported image formats for given image type.
std::string GetOclErrorAsString(int _clErr)
Returns the name of an OpenCL Error as a string.
void oclLogBinary(cl_program clProg, cl_device_id clDev)
Logs the GPU Program binary code.
std::string GetImageTypeAsString(const unsigned int _in)
Translates the internal image type identifier to a human readable description string.
void oclLogBuildInfo(cl_program clProg, cl_device_id clDev)
Shows the OpenCL-Program build info, called if clBuildProgram != CL_SUCCES.
void oclPrintDeviceInfo(cl_device_id device)
Prints out the essential support information about current device.
cl_ulong oclGetGlobalMemSize(cl_device_id device)
Returns the Global memory size of the current device.
bool oclCheckError(int _err, const char *filepath, int lineno)
Checks the given code for errors and produces a std::cout output if the _err does not equal CL_SUCCES...
void oclPrintMemObjectInfo(cl_mem memobj)
Prints the available memory info about the given object to std::cout.
cl_int oclGetPlatformID(cl_platform_id *selectedPlatform)
Returns a platform ID of an OpenCL-capable GPU, or throws an exception.