23 unsigned int iDivUp(
unsigned int dividend,
unsigned int divisor){
24 return (dividend % divisor == 0) ? (dividend / divisor) : (dividend / divisor + 1);
29 cl_uint num_platforms = 0;
30 cl_platform_id* clPlatformIDs;
33 ciErrNum = clGetPlatformIDs( 0, NULL, &num_platforms);
34 if ( ciErrNum != CL_SUCCESS)
36 MITK_ERROR<<
" Error " << ciErrNum <<
" in clGetPlatformIDs() \n";
37 throw std::bad_exception();
41 clPlatformIDs =
new cl_platform_id[num_platforms];
43 ciErrNum = clGetPlatformIDs( num_platforms, clPlatformIDs, NULL);
44 if(ciErrNum == CL_SUCCESS)
46 *selectedPlatform = clPlatformIDs[0];
58 MITK_INFO <<
"Examining cl_mem object: " << memobj
59 <<
"\n------------------\n";
62 cl_mem_object_type objtype;
63 clErr = clGetMemObjectInfo( memobj, CL_MEM_TYPE,
sizeof(cl_mem_object_type),&objtype, NULL);
68 case CL_MEM_OBJECT_BUFFER:
69 MITK_INFO <<
"CL_MEM_TYPE \t" <<
"BUFFER_OBJ" <<
"\n";
71 case CL_MEM_OBJECT_IMAGE2D:
72 MITK_INFO <<
"CL_MEM_TYPE \t" <<
"2D IMAGE" <<
"\n";
74 case CL_MEM_OBJECT_IMAGE3D:
75 MITK_INFO <<
"CL_MEM_TYPE \t" <<
"3D IMAGE" <<
"\n";
78 MITK_INFO <<
"CL_MEM_TYPE \t" <<
"[could not resolve]" <<
"\n";
84 clErr = clGetMemObjectInfo( memobj, CL_MEM_FLAGS,
sizeof(cl_mem_flags),&flags, NULL);
89 case CL_MEM_READ_ONLY:
90 MITK_INFO <<
"CL_MEM_FLAGS \t" <<
"CL_MEM_READ_ONLY" <<
"\n";
92 case CL_MEM_WRITE_ONLY:
93 MITK_INFO <<
"CL_MEM_FLAGS \t" <<
"CL_MEM_WRITE_ONLY" <<
"\n";
95 case CL_MEM_READ_WRITE:
96 MITK_INFO <<
"CL_MEM_FLAGS \t" <<
"CL_MEM_READ_WRITE" <<
"\n";
99 MITK_INFO <<
"CL_MEM_FLAGS \t" <<
"not resolved, " << flags <<
"\n";
105 clErr = clGetMemObjectInfo( memobj, CL_MEM_SIZE,
sizeof(memsize),&memsize, NULL);
108 MITK_INFO <<
"CL_MEM_SIZE \t" << memsize <<
"\n";
112 clErr = clGetMemObjectInfo( memobj, CL_MEM_HOST_PTR,
sizeof(
void*), (
void*) &hostptr, NULL);
115 MITK_INFO <<
"CL_MEM_HOST_PTR \t" << hostptr <<
"\n";
119 clErr = clGetMemObjectInfo( memobj, CL_MEM_CONTEXT,
sizeof(cl_context), &gpuctxt, NULL);
122 MITK_INFO <<
"CL_CONTEXT \t\t" << gpuctxt <<
"\n";
126 clErr = clGetMemObjectInfo( memobj, CL_MEM_REFERENCE_COUNT,
sizeof(cl_uint), &refs, NULL);
129 MITK_INFO <<
"CL_REF_COUNT \t" << refs <<
"\n";
131 MITK_INFO <<
"================== \n" << std::endl;
136 char device_string[1024];
138 clGetDeviceInfo(device, CL_DEVICE_NAME,
sizeof(device_string), &device_string, NULL);
139 MITK_INFO(
"ocl.log")<<
" Device : " << device_string;
143 clGetDeviceInfo(device, CL_DEVICE_TYPE,
sizeof(type), &type, NULL);
144 if( type & CL_DEVICE_TYPE_CPU )
145 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_TYPE: CL_DEVICE_TYPE_CPU";
146 if( type & CL_DEVICE_TYPE_GPU )
147 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_TYPE: CL_DEVICE_TYPE_GPU";
148 if( type & CL_DEVICE_TYPE_ACCELERATOR )
149 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_TYPE: CL_DEVICE_TYPE_ACCELERATOR";
150 if( type & CL_DEVICE_TYPE_DEFAULT )
151 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_TYPE: CL_DEVICE_TYPE_DEFAULT";
154 cl_uint compute_units;
155 clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(compute_units), &compute_units, NULL);
156 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_MAX_COMPUTE_UNITS:" << compute_units;
159 size_t workitem_size[3];
160 clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_SIZES,
sizeof(workitem_size), &workitem_size, NULL);
161 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_MAX_WORK_ITEM_SIZES:\t"<< workitem_size[0]<< workitem_size[1]<< workitem_size[2];
164 size_t workgroup_size;
165 clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE,
sizeof(workgroup_size), &workgroup_size, NULL);
166 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_MAX_WORK_GROUP_SIZE:" << workgroup_size;
169 cl_uint clock_frequency;
170 clGetDeviceInfo(device, CL_DEVICE_MAX_CLOCK_FREQUENCY,
sizeof(clock_frequency), &clock_frequency, NULL);
171 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_MAX_CLOCK_FREQUENCY:"<< clock_frequency / 1000;
174 cl_bool image_support;
175 clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT,
sizeof(image_support), &image_support, NULL);
176 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_IMAGE_SUPPORT:\t" << image_support;
180 clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE,
sizeof(mem_size), &mem_size, NULL);
181 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_GLOBAL_MEM_SIZE:\t\t"<<(
unsigned int)(mem_size / (1024 * 1024))<<
"Mbytes";
184 clGetDeviceInfo(device, CL_DEVICE_LOCAL_MEM_SIZE,
sizeof(mem_size), &mem_size, NULL);
185 MITK_INFO(
"ocl.log")<<
" CL_DEVICE_LOCAL_MEM_SIZE:\t\t"<< (
unsigned int)(mem_size / (1024)) <<
"KByte\n";
188 clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH,
sizeof(workgroup_size), &workgroup_size, NULL);
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, NULL);
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, NULL);
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, NULL);
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, NULL);
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, NULL);
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";
216 std::string returnString(
"CL_SUCCESS\n");
220 case CL_DEVICE_NOT_FOUND:
221 returnString =
"CL_DEVICE_NOT_FOUND\n";
223 case CL_DEVICE_NOT_AVAILABLE:
224 returnString =
"CL_DEVICE_NOT_AVAILABLE\n";
229 case CL_MEM_OBJECT_ALLOCATION_FAILURE :
230 returnString =
"CL_MEM_OBJECT_ALLOCATION_FAILURE\n";
232 case CL_OUT_OF_RESOURCES:
233 returnString =
"CL_OUT_OF_RESOURCES\n";
235 case CL_OUT_OF_HOST_MEMORY:
236 returnString =
"CL_OUT_OF_HOST_MEMORY\n";
238 case CL_PROFILING_INFO_NOT_AVAILABLE:
239 returnString =
"CL_PROFILING_INFO_NOT_AVAILABLE\n";
241 case CL_MEM_COPY_OVERLAP:
242 returnString =
"CL_MEM_COPY_OVERLAP\n";
244 case CL_IMAGE_FORMAT_MISMATCH:
245 returnString =
"CL_IMAGE_FORMAT_MISMATCH\n";
247 case CL_IMAGE_FORMAT_NOT_SUPPORTED:
248 returnString =
"CL_IMAGE_FORMAT_NOT_SUPPORTED\n";
250 case CL_BUILD_PROGRAM_FAILURE:
251 returnString =
"CL_BUILD_PROGRAM_FAILURE\n";
254 returnString =
"CL_MAP_FAILURE\n";
256 case CL_INVALID_VALUE:
257 returnString =
"CL_INVALID_VALUE\n";
259 case CL_INVALID_DEVICE_TYPE:
260 returnString =
"CL_INVALID_DEVICE_TYPE\n";
262 case CL_INVALID_PLATFORM:
263 returnString =
"CL_INVALID_PLATFORM\n";
265 case CL_INVALID_DEVICE:
266 returnString =
"CL_INVALID_DEVICE\n";
268 case CL_INVALID_CONTEXT :
269 returnString =
"CL_INVALID_CONTEXT\n";
271 case CL_INVALID_QUEUE_PROPERTIES:
272 returnString =
"CL_INVALID_QUEUE_PROPERTIES\n";
274 case CL_INVALID_COMMAND_QUEUE:
275 returnString =
"CL_INVALID_COMMAND_QUEUE\n";
277 case CL_INVALID_HOST_PTR:
278 returnString =
"CL_INVALID_HOST_PTR\n";
280 case CL_INVALID_MEM_OBJECT:
281 returnString =
"CL_INVALID_MEM_OBJECT\n";
283 case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
284 returnString =
"CL_INVALID_IMAGE_FORMAT_DESCRIPTOR\n";
286 case CL_INVALID_IMAGE_SIZE:
287 returnString =
"CL_INVALID_IMAGE_SIZE\n";
289 case CL_INVALID_SAMPLER :
290 returnString =
"CL_INVALID_SAMPLER\n";
292 case CL_INVALID_BINARY:
293 returnString =
"CL_INVALID_BINARY\n";
295 case CL_INVALID_BUILD_OPTIONS:
296 returnString =
"CL_INVALID_BUILD_OPTIONS\n";
298 case CL_INVALID_PROGRAM:
299 returnString =
"CL_INVALID_PROGRAM\n";
301 case CL_INVALID_PROGRAM_EXECUTABLE:
302 returnString =
"CL_INVALID_PROGRAM_EXECUTABLE\n";
304 case CL_INVALID_KERNEL_NAME:
305 returnString =
"CL_INVALID_KERNEL_NAME\n";
307 case CL_INVALID_KERNEL_DEFINITION:
308 returnString =
"CL_INVALID_KERNEL_DEFINITION\n";
310 case CL_INVALID_KERNEL :
311 returnString =
"CL_INVALID_KERNEL\n";
313 case CL_INVALID_ARG_INDEX :
314 returnString =
"CL_INVALID_ARG_INDEX\n";
316 case CL_INVALID_ARG_VALUE :
317 returnString =
"CL_INVALID_ARG_VALUE\n";
319 case CL_INVALID_ARG_SIZE :
320 returnString =
"CL_INVALID_ARG_SIZE\n";
322 case CL_INVALID_KERNEL_ARGS :
323 returnString =
"CL_INVALID_KERNEL_ARGS\n";
325 case CL_INVALID_WORK_DIMENSION:
326 returnString =
"CL_INVALID_WORK_DIMENSION\n";
328 case CL_INVALID_WORK_GROUP_SIZE:
329 returnString =
"CL_INVALID_WORK_GROUP_SIZE\n";
331 case CL_INVALID_WORK_ITEM_SIZE:
332 returnString =
"CL_INVALID_WORK_ITEM_SIZE\n";
334 case CL_INVALID_GLOBAL_OFFSET:
335 returnString =
"CL_INVALID_GLOBAL_OFFSET\n";
337 case CL_INVALID_EVENT_WAIT_LIST:
338 returnString =
"CL_INVALID_EVENT_WAIT_LIST\n";
340 case CL_INVALID_EVENT:
341 returnString =
"CL_INVALID_EVENT\n";
343 case CL_INVALID_OPERATION:
344 returnString =
"CL_INVALID_OPERATION\n";
346 case CL_INVALID_GL_OBJECT:
347 returnString =
"CL_INVALID_GL_OBJECT\n";
349 case CL_INVALID_BUFFER_SIZE :
350 returnString =
"CL_INVALID_BUFFER_SIZE\n";
352 case CL_INVALID_MIP_LEVEL :
353 returnString =
"CL_INVALID_MIP_LEVEL\n";
364 if(_clErr == CL_SUCCESS )
365 MITK_WARN <<
"Called GetOclErr() with no error value: [CL_SUCCESS]";
374 MITK_ERROR<<
"OpenCL Error at " << filepath <<
":"<< lineno;
385 const unsigned int entries = 500;
386 cl_image_format* formats =
new cl_image_format[entries];
388 cl_uint _written = 0;
393 ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_READ_ONLY, _type, entries, formats, &_written);
396 MITK_INFO <<
"Supported Image Formats, Image: CL_MEM_READ_ONLY \n";
398 for (
unsigned int i=0; i<_written; i++)
406 ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_READ_WRITE, _type, entries, formats, &_written);
409 MITK_INFO <<
"Supported Image Formats, Image: CL_MEM_READ_WRITE (found: " << _written <<
") \n";
411 for (
unsigned int i=0; i<_written; i++)
419 ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_WRITE_ONLY, _type, entries, formats, &_written);
422 MITK_INFO <<
"Supported Image Formats, Image: CL_MEM_WRITE_ONLY (found: " << _written <<
") \n";
424 for (
unsigned int i=0; i<_written; i++)
459 return "CL_INTENSITY ";
462 return "CL_LUMINANCE ";
465 return "CL_SNORM_INT8 ";
468 return "CL_SNORM_INT16 ";
471 return "CL_UNORM_INT8 ";
474 return "CL_UNORM_INT16 ";
476 case CL_UNORM_SHORT_565:
477 return "CL_UNORM_SHORT_565 ";
479 case CL_UNORM_SHORT_555:
480 return "CL_UNORM_SHORT_555 ";
482 case CL_UNORM_INT_101010:
483 return "CL_UNORM_INT_101010 ";
486 return "CL_SIGNED_INT8 ";
488 case CL_SIGNED_INT16:
489 return "CL_SIGNED_INT16 ";
491 case CL_SIGNED_INT32:
492 return "CL_SIGNED_INT32 ";
494 case CL_UNSIGNED_INT8:
495 return "CL_UNSIGNED_INT8 ";
497 case CL_UNSIGNED_INT16:
498 return "CL_UNSIGNED_INT16 ";
500 case CL_UNSIGNED_INT32:
501 return "CL_UNSIGNED_INT32 ";
504 return "CL_HALF_FLOAT ";
521 clGetProgramInfo(clProg, CL_PROGRAM_NUM_DEVICES,
sizeof(cl_uint), &num_devices, NULL);
524 cl_device_id* devices = (cl_device_id*) malloc(num_devices *
sizeof(cl_device_id));
525 clGetProgramInfo(clProg, CL_PROGRAM_DEVICES, num_devices *
sizeof(cl_device_id), devices, 0);
528 size_t* binary_sizes = (
size_t*)malloc(num_devices *
sizeof(
size_t));
529 clGetProgramInfo(clProg, CL_PROGRAM_BINARY_SIZES, num_devices *
sizeof(
size_t), binary_sizes, NULL);
532 char** ptx_code = (
char**)malloc(num_devices *
sizeof(
char*));
533 for(
unsigned int i=0; i<num_devices; ++i)
535 ptx_code[i] = (
char*)malloc(binary_sizes[i]);
537 clGetProgramInfo(clProg, CL_PROGRAM_BINARIES, 0, ptx_code, NULL);
540 unsigned int idx = 0;
541 while((idx < num_devices) && (devices[idx] != clDev))
547 if( idx < num_devices )
549 MITK_INFO<<
"\n ---------------- \n Program Binary: \n -----------------------\n";
554 free( binary_sizes );
555 for(
unsigned int i=0; i<num_devices; ++i)
564 char cBuildLog[10240];
566 clGetProgramBuildInfo(clProg, clDev, CL_PROGRAM_BUILD_LOG,
sizeof(cBuildLog), cBuildLog, NULL);
567 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.
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.