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