Medical Imaging Interaction Toolkit  2018.4.99-6aa36ba9
Medical Imaging Interaction Toolkit
mitkOclUtils.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkOclUtils.h"
14 #include "mitkLogMacros.h"
15 #include <cstdio>
16 #include <cstring>
17 
18 
19 unsigned int iDivUp(unsigned int dividend, unsigned int divisor){
20  return (dividend % divisor == 0) ? (dividend / divisor) : (dividend / divisor + 1);
21 }
22 
23 cl_int oclGetPlatformID(cl_platform_id* selectedPlatform)
24 {
25  cl_uint num_platforms = 0;
26  cl_platform_id* clPlatformIDs;
27  cl_int ciErrNum = 0;
28 
29  ciErrNum = clGetPlatformIDs( 0, nullptr, &num_platforms);
30  if ( ciErrNum != CL_SUCCESS)
31  {
32  MITK_ERROR<<" Error " << ciErrNum << " in clGetPlatformIDs() \n";
33  throw std::bad_exception();
34  }
35  else
36  {
37  clPlatformIDs = new cl_platform_id[num_platforms];
38 
39  ciErrNum = clGetPlatformIDs( num_platforms, clPlatformIDs, nullptr);
40  if(ciErrNum == CL_SUCCESS)
41  {
42  *selectedPlatform = clPlatformIDs[0];
43  }
44  }
45 
46  return CL_SUCCESS;
47 
48 }
49 
50 void oclPrintMemObjectInfo(cl_mem memobj)
51 {
52  cl_int clErr = 0;
53 
54  MITK_INFO << "Examining cl_mem object: " << memobj
55  << "\n------------------\n";
56 
57  // CL_MEM_TYPE
58  cl_mem_object_type objtype;
59  clErr = clGetMemObjectInfo( memobj, CL_MEM_TYPE, sizeof(cl_mem_object_type),&objtype, nullptr);
60  CHECK_OCL_ERR( clErr );
61 
62  switch(objtype)
63  {
64  case CL_MEM_OBJECT_BUFFER:
65  MITK_INFO << "CL_MEM_TYPE \t" << "BUFFER_OBJ" << "\n";
66  break;
67  case CL_MEM_OBJECT_IMAGE2D:
68  MITK_INFO << "CL_MEM_TYPE \t" << "2D IMAGE" << "\n";
69  break;
70  case CL_MEM_OBJECT_IMAGE3D:
71  MITK_INFO << "CL_MEM_TYPE \t" << "3D IMAGE" << "\n";
72  break;
73  default:
74  MITK_INFO << "CL_MEM_TYPE \t" << "[could not resolve]" << "\n";
75  break;
76  }
77 
78  // CL_MEM_FLAGS
79  cl_mem_flags flags;
80  clErr = clGetMemObjectInfo( memobj, CL_MEM_FLAGS, sizeof(cl_mem_flags),&flags, nullptr);
81  CHECK_OCL_ERR( clErr );
82 
83  switch(flags)
84  {
85  case CL_MEM_READ_ONLY:
86  MITK_INFO << "CL_MEM_FLAGS \t" << "CL_MEM_READ_ONLY" << "\n";
87  break;
88  case CL_MEM_WRITE_ONLY:
89  MITK_INFO << "CL_MEM_FLAGS \t" << "CL_MEM_WRITE_ONLY" << "\n";
90  break;
91  case CL_MEM_READ_WRITE:
92  MITK_INFO << "CL_MEM_FLAGS \t" << "CL_MEM_READ_WRITE" << "\n";
93  break;
94  default:
95  MITK_INFO << "CL_MEM_FLAGS \t" << "not resolved, " << flags << "\n";
96  break;
97  }
98 
99  // get CL_MEM_SIZE
100  size_t memsize;
101  clErr = clGetMemObjectInfo( memobj, CL_MEM_SIZE, sizeof(memsize),&memsize, nullptr);
102  CHECK_OCL_ERR( clErr );
103 
104  MITK_INFO << "CL_MEM_SIZE \t" << memsize << "\n";
105 
106  // get CL_MEM_HOST_PTR
107  float *hostptr;
108  clErr = clGetMemObjectInfo( memobj, CL_MEM_HOST_PTR, sizeof(void*), (void*) &hostptr, nullptr);
109  CHECK_OCL_ERR( clErr );
110 
111  MITK_INFO << "CL_MEM_HOST_PTR \t" << hostptr << "\n";
112 
113  // get CL_CONTEXT
114  cl_context gpuctxt;
115  clErr = clGetMemObjectInfo( memobj, CL_MEM_CONTEXT, sizeof(cl_context), &gpuctxt, nullptr);
116  CHECK_OCL_ERR( clErr );
117 
118  MITK_INFO << "CL_CONTEXT \t\t" << gpuctxt << "\n";
119 
120  // get CL_MEM_REFERENCE_COUNT
121  cl_uint refs;
122  clErr = clGetMemObjectInfo( memobj, CL_MEM_REFERENCE_COUNT, sizeof(cl_uint), &refs, nullptr);
123  CHECK_OCL_ERR(clErr);
124 
125  MITK_INFO << "CL_REF_COUNT \t" << refs << "\n";
126 
127  MITK_INFO << "================== \n" << std::endl;
128 }
129 
130 void oclPrintDeviceInfo(cl_device_id device)
131 {
132  char device_string[1024];
133 
134  clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_string), &device_string, nullptr);
135  MITK_INFO("ocl.log")<< " Device : " << device_string;
136 
137  // CL_DEVICE_INFO
138  cl_device_type type;
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";
148 
149  // CL_DEVICE_MAX_COMPUTE_UNITS
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;
153 
154  // CL_DEVICE_MAX_WORK_GROUP_SIZE
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];
158 
159  // CL_DEVICE_MAX_WORK_GROUP_SIZE
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;
163 
164  // CL_DEVICE_MAX_CLOCK_FREQUENCY
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;
168 
169  // CL_DEVICE_IMAGE_SUPPORT
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;
173 
174  // CL_DEVICE_GLOBAL_MEM_SIZE
175  cl_ulong mem_size;
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";
178 
179  // CL_DEVICE_LOCAL_MEM_SIZE
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";
182 
183  // CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
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";
186 
187  //check for image support properties
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;
190 
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;
193 
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;
196 
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;
199 
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;
202 
203 
204  // CL_DEVICE_QUEUE_PROPERTIES
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";
211 
212 }
213 
214 cl_ulong oclGetGlobalMemSize(cl_device_id device)
215 {
216  cl_ulong mem_size;
217  clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(mem_size), &mem_size, nullptr);
218  return mem_size;
219 }
220 
221 std::string GetOclErrorAsString( int _clErr )
222 {
223  std::string returnString("unkown error number: "+std::to_string(_clErr)+" \n");
224 
225  switch(_clErr)
226  {
227  case CL_SUCCESS:
228  returnString = "CL_SUCCESS\n";
229  break;
230  case CL_DEVICE_NOT_FOUND:
231  returnString = "CL_DEVICE_NOT_FOUND\n";
232  break;
233  case CL_DEVICE_NOT_AVAILABLE:
234  returnString = "CL_DEVICE_NOT_AVAILABLE\n";
235  break;
236  /*case CL_DEVICE_COMPILER_NOT_AVAILABLE:
237  returnString = "CL_DEVICE_COMPILER_NOT_AVAILABLE\n";
238  break; */
239  case CL_MEM_OBJECT_ALLOCATION_FAILURE :
240  returnString = "CL_MEM_OBJECT_ALLOCATION_FAILURE\n";
241  break;
242  case CL_OUT_OF_RESOURCES:
243  returnString = "CL_OUT_OF_RESOURCES\n";
244  break;
245  case CL_OUT_OF_HOST_MEMORY:
246  returnString = "CL_OUT_OF_HOST_MEMORY\n";
247  break;
248  case CL_PROFILING_INFO_NOT_AVAILABLE:
249  returnString = "CL_PROFILING_INFO_NOT_AVAILABLE\n";
250  break;
251  case CL_MEM_COPY_OVERLAP:
252  returnString = "CL_MEM_COPY_OVERLAP\n";
253  break;
254  case CL_IMAGE_FORMAT_MISMATCH:
255  returnString = "CL_IMAGE_FORMAT_MISMATCH\n";
256  break;
257  case CL_IMAGE_FORMAT_NOT_SUPPORTED:
258  returnString = "CL_IMAGE_FORMAT_NOT_SUPPORTED\n";
259  break;
260  case CL_BUILD_PROGRAM_FAILURE:
261  returnString = "CL_BUILD_PROGRAM_FAILURE\n";
262  break;
263  case CL_MAP_FAILURE:
264  returnString = "CL_MAP_FAILURE\n";
265  break;
266  case CL_INVALID_VALUE:
267  returnString = "CL_INVALID_VALUE\n";
268  break;
269  case CL_INVALID_DEVICE_TYPE:
270  returnString = "CL_INVALID_DEVICE_TYPE\n";
271  break;
272  case CL_INVALID_PLATFORM:
273  returnString = "CL_INVALID_PLATFORM\n";
274  break;
275  case CL_INVALID_DEVICE:
276  returnString = "CL_INVALID_DEVICE\n";
277  break;
278  case CL_INVALID_CONTEXT :
279  returnString = "CL_INVALID_CONTEXT\n";
280  break;
281  case CL_INVALID_QUEUE_PROPERTIES:
282  returnString = "CL_INVALID_QUEUE_PROPERTIES\n";
283  break;
284  case CL_INVALID_COMMAND_QUEUE:
285  returnString = "CL_INVALID_COMMAND_QUEUE\n";
286  break;
287  case CL_INVALID_HOST_PTR:
288  returnString = "CL_INVALID_HOST_PTR\n";
289  break;
290  case CL_INVALID_MEM_OBJECT:
291  returnString = "CL_INVALID_MEM_OBJECT\n";
292  break;
293  case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
294  returnString = "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR\n";
295  break;
296  case CL_INVALID_IMAGE_SIZE:
297  returnString = "CL_INVALID_IMAGE_SIZE\n";
298  break;
299  case CL_INVALID_SAMPLER :
300  returnString = "CL_INVALID_SAMPLER\n";
301  break;
302  case CL_INVALID_BINARY:
303  returnString = "CL_INVALID_BINARY\n";
304  break;
305  case CL_INVALID_BUILD_OPTIONS:
306  returnString = "CL_INVALID_BUILD_OPTIONS\n";
307  break;
308  case CL_INVALID_PROGRAM:
309  returnString = "CL_INVALID_PROGRAM\n";
310  break;
311  case CL_INVALID_PROGRAM_EXECUTABLE:
312  returnString = "CL_INVALID_PROGRAM_EXECUTABLE\n";
313  break;
314  case CL_INVALID_KERNEL_NAME:
315  returnString = "CL_INVALID_KERNEL_NAME\n";
316  break;
317  case CL_INVALID_KERNEL_DEFINITION:
318  returnString = "CL_INVALID_KERNEL_DEFINITION\n";
319  break;
320  case CL_INVALID_KERNEL :
321  returnString = "CL_INVALID_KERNEL\n";
322  break;
323  case CL_INVALID_ARG_INDEX :
324  returnString = "CL_INVALID_ARG_INDEX\n";
325  break;
326  case CL_INVALID_ARG_VALUE :
327  returnString = "CL_INVALID_ARG_VALUE\n";
328  break;
329  case CL_INVALID_ARG_SIZE :
330  returnString = "CL_INVALID_ARG_SIZE\n";
331  break;
332  case CL_INVALID_KERNEL_ARGS :
333  returnString = "CL_INVALID_KERNEL_ARGS\n";
334  break;
335  case CL_INVALID_WORK_DIMENSION:
336  returnString = "CL_INVALID_WORK_DIMENSION\n";
337  break;
338  case CL_INVALID_WORK_GROUP_SIZE:
339  returnString = "CL_INVALID_WORK_GROUP_SIZE\n";
340  break;
341  case CL_INVALID_WORK_ITEM_SIZE:
342  returnString = "CL_INVALID_WORK_ITEM_SIZE\n";
343  break;
344  case CL_INVALID_GLOBAL_OFFSET:
345  returnString = "CL_INVALID_GLOBAL_OFFSET\n";
346  break;
347  case CL_INVALID_EVENT_WAIT_LIST:
348  returnString = "CL_INVALID_EVENT_WAIT_LIST\n";
349  break;
350  case CL_INVALID_EVENT:
351  returnString = "CL_INVALID_EVENT\n";
352  break;
353  case CL_INVALID_OPERATION:
354  returnString = "CL_INVALID_OPERATION\n";
355  break;
356  case CL_INVALID_GL_OBJECT:
357  returnString = "CL_INVALID_GL_OBJECT\n";
358  break;
359  case CL_INVALID_BUFFER_SIZE :
360  returnString = "CL_INVALID_BUFFER_SIZE\n";
361  break;
362  case CL_INVALID_MIP_LEVEL :
363  returnString = "CL_INVALID_MIP_LEVEL\n";
364  break;
365  default:
366  break;
367  }
368 
369  return returnString;
370 }
371 
372 void GetOclError(int _clErr)
373 {
374  if(_clErr == CL_SUCCESS)
375  MITK_WARN << "Called GetOclErr() with no error value: [CL_SUCCESS]";
376  else
377  MITK_ERROR << GetOclErrorAsString(_clErr);
378 }
379 
380 bool oclCheckError(int _err, const char* filepath, int lineno)
381 {
382  if (_err)
383  {
384  MITK_ERROR<< "OpenCL Error at " << filepath <<":"<< lineno;
385  GetOclError(_err);
386 
387  return 0;
388  }
389 
390  return 1;
391 }
392 
393 void GetSupportedImageFormats(cl_context _context, cl_mem_object_type _type)
394 {
395  const unsigned int entries = 500;
396  cl_image_format* formats = new cl_image_format[entries];
397 
398  cl_uint _written = 0;
399 
400  // OpenCL constant to catch error IDs
401  cl_int ciErr1;
402  // Get list of supported image formats for READ_ONLY access
403  ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_READ_ONLY, _type, entries, formats, &_written);
404  CHECK_OCL_ERR(ciErr1);
405 
406  MITK_INFO << "Supported Image Formats, Image: CL_MEM_READ_ONLY \n";
407 
408  for (unsigned int i=0; i<_written; i++)
409  {
410  MITK_INFO<< "ChannelType: " << GetImageTypeAsString(formats[i].image_channel_data_type) << "| ChannelOrder: "<< GetImageTypeAsString(formats[i].image_channel_order) <<"\n";
411  }
412 
413  _written = 0;
414 
415  // Get list of supported image formats for READ_WRITE access
416  ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_READ_WRITE, _type, entries, formats, &_written);
417  CHECK_OCL_ERR(ciErr1);
418 
419  MITK_INFO << "Supported Image Formats, Image: CL_MEM_READ_WRITE (found: " << _written <<") \n";
420 
421  for (unsigned int i=0; i<_written; i++)
422  {
423  MITK_INFO<< "ChannelType: " << GetImageTypeAsString(formats[i].image_channel_data_type) << "| ChannelOrder: "<< GetImageTypeAsString(formats[i].image_channel_order) <<"\n";
424  }
425 
426  _written = 0;
427 
428  // Get list of supported image formats for WRITE_ONLY access
429  ciErr1 = clGetSupportedImageFormats( _context, CL_MEM_WRITE_ONLY, _type, entries, formats, &_written);
430  CHECK_OCL_ERR(ciErr1);
431 
432  MITK_INFO << "Supported Image Formats, Image: CL_MEM_WRITE_ONLY (found: " << _written <<") \n";
433 
434  for (unsigned int i=0; i<_written; i++)
435  {
436  MITK_INFO<< "ChannelType: " << GetImageTypeAsString(formats[i].image_channel_data_type) << "| ChannelOrder: "<< GetImageTypeAsString(formats[i].image_channel_order) <<"\n";
437  }
438 }
439 
440 std::string GetImageTypeAsString( const unsigned int _in)
441 {
442  switch(_in)
443  {
444  case CL_R:
445  return "CL_R ";
446  break;
447  case CL_A:
448  return "CL_A ";
449  break;
450  case CL_RG:
451  return "CL_RG ";
452  break;
453  case CL_RA:
454  return "CL_RA ";
455  break;
456  case CL_RGB:
457  return "CL_RGB ";
458  break;
459  case CL_RGBA:
460  return "CL_RGBA ";
461  break;
462  case CL_BGRA:
463  return "CL_BGRA ";
464  break;
465  case CL_ARGB:
466  return "CL_ARGB ";
467  break;
468  case CL_INTENSITY:
469  return "CL_INTENSITY ";
470  break;
471  case CL_LUMINANCE:
472  return "CL_LUMINANCE ";
473  break;
474  case CL_SNORM_INT8:
475  return "CL_SNORM_INT8 ";
476  break;
477  case CL_SNORM_INT16:
478  return "CL_SNORM_INT16 ";
479  break;
480  case CL_UNORM_INT8:
481  return "CL_UNORM_INT8 ";
482  break;
483  case CL_UNORM_INT16:
484  return "CL_UNORM_INT16 ";
485  break;
486  case CL_UNORM_SHORT_565:
487  return "CL_UNORM_SHORT_565 ";
488  break;
489  case CL_UNORM_SHORT_555:
490  return "CL_UNORM_SHORT_555 ";
491  break;
492  case CL_UNORM_INT_101010:
493  return "CL_UNORM_INT_101010 ";
494  break;
495  case CL_SIGNED_INT8:
496  return "CL_SIGNED_INT8 ";
497  break;
498  case CL_SIGNED_INT16:
499  return "CL_SIGNED_INT16 ";
500  break;
501  case CL_SIGNED_INT32:
502  return "CL_SIGNED_INT32 ";
503  break;
504  case CL_UNSIGNED_INT8:
505  return "CL_UNSIGNED_INT8 ";
506  break;
507  case CL_UNSIGNED_INT16:
508  return "CL_UNSIGNED_INT16 ";
509  break;
510  case CL_UNSIGNED_INT32:
511  return "CL_UNSIGNED_INT32 ";
512  break;
513  case CL_HALF_FLOAT:
514  return "CL_HALF_FLOAT ";
515  break;
516  case CL_FLOAT:
517  return "CL_FLOAT ";
518  break;
519  default:
520  return "--";
521  break;
522  }
523 }
524 
525 
526 
527 void oclLogBinary(cl_program clProg, cl_device_id clDev)
528 {
529  // Grab the number of devices associated with the program
530  cl_uint num_devices;
531  clGetProgramInfo(clProg, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &num_devices, nullptr);
532 
533  // Grab the device ids
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);
536 
537  // Grab the sizes of the binaries
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);
540 
541  // Now get the binaries
542  char** ptx_code = (char**)malloc(num_devices * sizeof(char*));
543  for( unsigned int i=0; i<num_devices; ++i)
544  {
545  ptx_code[i] = (char*)malloc(binary_sizes[i]);
546  }
547  clGetProgramInfo(clProg, CL_PROGRAM_BINARIES, 0, ptx_code, nullptr);
548 
549  // Find the index of the device of interest
550  unsigned int idx = 0;
551  while((idx < num_devices) && (devices[idx] != clDev))
552  {
553  ++idx;
554  }
555 
556  // If the index is associated, log the result
557  if( idx < num_devices )
558  {
559  MITK_INFO<< "\n ---------------- \n Program Binary: \n -----------------------\n";
560  MITK_INFO<< ptx_code[idx];
561  }
562 
563  free( devices );
564  free( binary_sizes );
565  for(unsigned int i=0; i<num_devices; ++i)
566  {
567  free(ptx_code[i]);
568  }
569  free( ptx_code );
570 }
571 
572 void oclLogBuildInfo(cl_program clProg, cl_device_id clDev)
573 {
574  char cBuildLog[10240];
575 
576  clGetProgramBuildInfo(clProg, clDev, CL_PROGRAM_BUILD_LOG, sizeof(cBuildLog), cBuildLog, nullptr);
577  MITK_INFO<< "\n Program Build Log: \n -----------------------\n";
578  MITK_INFO<< cBuildLog;
579 }
#define CHECK_OCL_ERR(_er)
Definition: mitkOclUtils.h:21
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...
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_ERROR
Definition: mitkLogMacros.h:20
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.
#define MITK_WARN
Definition: mitkLogMacros.h:19
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.