Guest User

Untitled

a guest
Sep 16th, 2015
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // clang -framework OpenCL dumpcl.c -o dumpcl && ./dumpcl
  2.  
  3. // https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html
  4. // https://www.khronos.org/message_boards/showthread.php/5803-Error-propagation-from-devices-to-application-level?p=18570&viewfull=1#post18570
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #ifdef __APPLE__
  9. #include <OpenCL/opencl.h>
  10. #else
  11. #include <CL/cl.h>
  12. #endif
  13.  
  14. void printCLInfo();
  15.  
  16.  
  17. int main(int argc, char* const argv[]) {
  18.  
  19. printCLInfo();
  20.  
  21. return 0;
  22. }
  23.  
  24.  
  25. void printCLInfo()
  26. {
  27. size_t p_size;
  28. size_t arr_tsize[3];
  29. size_t ret_size;
  30. char param[100];
  31. cl_uint entries;
  32. cl_ulong long_entries;
  33. cl_bool bool_entries;
  34.  
  35. cl_device_local_mem_type mem_type;
  36. cl_device_type dev_type;
  37. cl_device_fp_config fp_conf;
  38. cl_device_exec_capabilities exec_cap;
  39.  
  40. cl_uint num_devices;
  41. clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
  42. printf("Found Devices:\t\t%d\n",num_devices);
  43.  
  44. cl_device_id* devices = calloc(sizeof(cl_device_id), num_devices);
  45. clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
  46.  
  47. for(int i=0; i<num_devices; i++)
  48. {
  49. printf("\nDevice: %d\n\n",i);
  50.  
  51. clGetDeviceInfo(devices[i],CL_DEVICE_TYPE,sizeof(dev_type),&dev_type,&ret_size);
  52. printf("\tDevice Type:\t\t");
  53. if(dev_type & CL_DEVICE_TYPE_GPU)
  54. printf("CL_DEVICE_TYPE_GPU ");
  55. if(dev_type & CL_DEVICE_TYPE_CPU)
  56. printf("CL_DEVICE_TYPE_CPU ");
  57. if(dev_type & CL_DEVICE_TYPE_ACCELERATOR)
  58. printf("CL_DEVICE_TYPE_ACCELERATOR ");
  59. if(dev_type & CL_DEVICE_TYPE_DEFAULT)
  60. printf("CL_DEVICE_TYPE_DEFAULT ");
  61. printf("\n");
  62.  
  63.  
  64. clGetDeviceInfo(devices[i],CL_DEVICE_NAME,sizeof(param),param,&ret_size);
  65. printf("\tName: \t\t\t%s\n",param);
  66.  
  67. clGetDeviceInfo(devices[i],CL_DEVICE_VENDOR,sizeof(param),param,&ret_size);
  68. printf("\tVendor: \t\t%s\n",param);
  69.  
  70. clGetDeviceInfo(devices[i],CL_DEVICE_VENDOR_ID,sizeof(cl_uint),&entries,&ret_size);
  71. printf("\tVendor ID:\t\t%d\n",entries);
  72.  
  73. clGetDeviceInfo(devices[i],CL_DEVICE_VERSION,sizeof(param),param,&ret_size);
  74. printf("\tVersion:\t\t%s\n",param);
  75.  
  76. clGetDeviceInfo(devices[i],CL_DEVICE_PROFILE,sizeof(param),param,&ret_size);
  77. printf("\tProfile:\t\t%s\n",param);
  78.  
  79. clGetDeviceInfo(devices[i],CL_DRIVER_VERSION,sizeof(param),param,&ret_size);
  80. printf("\tDriver: \t\t%s\n",param);
  81.  
  82. size_t extensions_size;
  83. clGetDeviceInfo(devices[i],CL_DEVICE_EXTENSIONS,0,NULL,&extensions_size);
  84. char *extensions = (char*)malloc(extensions_size);
  85. clGetDeviceInfo(devices[i],CL_DEVICE_EXTENSIONS,extensions_size,extensions,NULL);
  86. printf("\tExtensions:\t\t%s\n",extensions);
  87. free(extensions);
  88.  
  89. printf("\tExtensions:\t\t%s\n",param);
  90.  
  91. clGetDeviceInfo(devices[i],CL_DEVICE_MAX_WORK_ITEM_SIZES,3*sizeof(size_t),arr_tsize,&ret_size);
  92. printf("\tMax Work-Item Sizes:\t(%zd,%zd,%zd)\n",arr_tsize[0],arr_tsize[1],arr_tsize[2]);
  93.  
  94. clGetDeviceInfo(devices[i],CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t),&p_size,&ret_size);
  95. printf("\tMax Work Group Size:\t%zd\n",p_size);
  96.  
  97. clGetDeviceInfo(devices[i],CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(cl_uint),&entries,&ret_size);
  98. printf("\tMax Compute Units:\t%d\n",entries);
  99.  
  100. clGetDeviceInfo(devices[i],CL_DEVICE_MAX_CLOCK_FREQUENCY,sizeof(cl_uint),&entries,&ret_size);
  101. printf("\tMax Frequency (Mhz):\t%d\n",entries);
  102.  
  103. clGetDeviceInfo(devices[i],CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE,sizeof(cl_uint),&entries,&ret_size);
  104. printf("\tCache Line (bytes):\t%d\n",entries);
  105.  
  106. clGetDeviceInfo(devices[i],CL_DEVICE_GLOBAL_MEM_SIZE,sizeof(cl_ulong),&long_entries,&ret_size);
  107. printf("\tGlobal Memory (MB):\t%llu\n",long_entries/1024/1024);
  108.  
  109. clGetDeviceInfo(devices[i],CL_DEVICE_LOCAL_MEM_SIZE,sizeof(cl_ulong),&long_entries,&ret_size);
  110. printf("\tLocal Memory (MB):\t%llu\n",long_entries/1024/1024);
  111.  
  112. clGetDeviceInfo(devices[i],CL_DEVICE_LOCAL_MEM_TYPE,sizeof(cl_device_local_mem_type),&mem_type,&ret_size);
  113. if(mem_type & CL_LOCAL)
  114. printf("\tLocal Memory Type:\tCL_LOCAL\n");
  115. else if(mem_type & CL_GLOBAL)
  116. printf("\tLocal Memory Type:\tCL_GLOBAL\n");
  117. else
  118. printf("\tLocal Memory Type:\tUNKNOWN\n");
  119.  
  120.  
  121. clGetDeviceInfo(devices[i],CL_DEVICE_MAX_MEM_ALLOC_SIZE,sizeof(cl_ulong),&long_entries,&ret_size);
  122. printf("\tMax Mem Alloc (MB):\t%llu\n",long_entries/1024/1024);
  123.  
  124. clGetDeviceInfo(devices[i],CL_DEVICE_MAX_PARAMETER_SIZE,sizeof(size_t),&p_size,&ret_size);
  125. printf("\tMax Param Size (MB):\t%zd\n",p_size);
  126.  
  127. clGetDeviceInfo(devices[i],CL_DEVICE_MEM_BASE_ADDR_ALIGN,sizeof(cl_uint),&entries,&ret_size);
  128. printf("\tBase Mem Align (bits):\t%d\n",entries);
  129.  
  130. clGetDeviceInfo(devices[i],CL_DEVICE_ADDRESS_BITS,sizeof(cl_uint),&entries,&ret_size);
  131. printf("\tAddress Space (bits):\t%d\n",entries);
  132.  
  133. clGetDeviceInfo(devices[i],CL_DEVICE_IMAGE_SUPPORT,sizeof(cl_bool),&bool_entries,&ret_size);
  134. printf("\tImage Support:\t\t%d\n",bool_entries);
  135.  
  136. clGetDeviceInfo(devices[i],CL_DEVICE_TYPE,sizeof(fp_conf),&fp_conf,&ret_size);
  137. printf("\tFloat Functionality:\t");
  138. if(fp_conf & CL_FP_DENORM)
  139. printf("DENORM support ");
  140. if(fp_conf & CL_FP_ROUND_TO_NEAREST)
  141. printf("Round to nearest support ");
  142. if(fp_conf & CL_FP_ROUND_TO_ZERO)
  143. printf("Round to zero support ");
  144. if(fp_conf & CL_FP_ROUND_TO_INF)
  145. printf("Round to +ve/-ve infinity support ");
  146. if(fp_conf & CL_FP_FMA)
  147. printf("IEEE754 fused-multiply-add support ");
  148. if(fp_conf & CL_FP_INF_NAN)
  149. printf("INF and NaN support ");
  150. printf("\n");
  151.  
  152.  
  153. clGetDeviceInfo(devices[i],CL_DEVICE_ERROR_CORRECTION_SUPPORT,sizeof(cl_bool),&bool_entries,&ret_size);
  154. printf("\tECC Support:\t\t%d\n",bool_entries);
  155.  
  156. clGetDeviceInfo(devices[i],CL_DEVICE_EXECUTION_CAPABILITIES,sizeof(cl_device_exec_capabilities),&exec_cap,&ret_size);
  157. printf("\tExec Functionality:\t");
  158. if(exec_cap & CL_EXEC_KERNEL)
  159. printf("CL_EXEC_KERNEL ");
  160. if(exec_cap & CL_EXEC_NATIVE_KERNEL)
  161. printf("CL_EXEC_NATIVE_KERNEL ");
  162. printf("\n");
  163.  
  164. clGetDeviceInfo(devices[i],CL_DEVICE_ENDIAN_LITTLE,sizeof(cl_bool),&bool_entries,&ret_size);
  165. printf("\tLittle Endian Device:\t%d\n",bool_entries);
  166.  
  167. clGetDeviceInfo(devices[i],CL_DEVICE_PROFILING_TIMER_RESOLUTION,sizeof(size_t),&p_size,&ret_size);
  168. printf("\tProfiling Res (ns):\t%zd\n",p_size);
  169.  
  170. clGetDeviceInfo(devices[i],CL_DEVICE_AVAILABLE,sizeof(cl_bool),&bool_entries,&ret_size);
  171. printf("\tDevice Available:\t%d\n",bool_entries);
  172.  
  173. }
  174.  
  175. free(devices);
  176. }
RAW Paste Data