m0n0lithic

OpenCL deviceQuery (2nd version) with multi platform GPU

Dec 11th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* https://www.sharcnet.ca/help/index.php/OpenCL
  2. Compile: gcc -Wall -I/usr/include -o deviceQuery -lOpenCL deviceQuery.c
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <CL/cl.h>
  7.  
  8. int main(int argc, char** argv) {
  9.    char dname[500];
  10.    //cl_device_id devices[10];
  11.    cl_uint num_devices,entries,available;
  12.    cl_uint i,nplat=2;
  13.    cl_ulong long_entries;
  14.    int d;
  15.    cl_int err;
  16.    //cl_platform_id platform_id = NULL;
  17.    size_t              maxDevices = 2;
  18.    cl_device_id*       devices = (cl_device_id*)malloc(maxDevices*sizeof(cl_device_id));
  19.    cl_platform_id* platform_id = (cl_platform_id*)malloc(sizeof(cl_platform_id));
  20.    size_t p_size;
  21.  
  22. /* obtain list of platforms available */
  23.    err = clGetPlatformIDs(nplat, platform_id, &available);
  24.    if (err != CL_SUCCESS)
  25.    {
  26.        printf("Error: Failure in clGetPlatformIDs,error code=%d \n",err);
  27.        return 0;
  28.    }
  29. for (i = 0; i < nplat; i++) {
  30. /* obtain information about platform */
  31.    clGetPlatformInfo(platform_id[i],CL_PLATFORM_NAME,500,dname,NULL);
  32.    printf("CL_PLATFORM_NAME = %s\n", dname);
  33.    clGetPlatformInfo(platform_id[i],CL_PLATFORM_VERSION,500,dname,NULL);
  34.    printf("CL_PLATFORM_VERSION = %s\n", dname);
  35.  
  36. /* obtain list of devices available on platform */
  37.    clGetDeviceIDs(platform_id[i], CL_DEVICE_TYPE_ALL, 10, devices, &num_devices);
  38.    printf("%d devices found\n", num_devices);
  39.  
  40. /* query devices for information */
  41.    for (d = 0; d < num_devices; ++d) {
  42.        clGetDeviceInfo(devices[d], CL_DEVICE_NAME, 500, dname,NULL);
  43.        printf("Device #%d name = %s\n", d, dname);
  44.        clGetDeviceInfo(devices[d],CL_DRIVER_VERSION, 500, dname,NULL);
  45.        printf("\tDriver version = %s\n", dname);
  46.        clGetDeviceInfo(devices[d],CL_DEVICE_GLOBAL_MEM_SIZE,sizeof(cl_ulong),&long_entries,NULL);
  47.        printf("\tGlobal Memory (MB):\t%llu\n",long_entries/1024/1024);
  48.        clGetDeviceInfo(devices[d],CL_DEVICE_GLOBAL_MEM_CACHE_SIZE,sizeof(cl_ulong),&long_entries,NULL);
  49.        printf("\tGlobal Memory Cache (MB):\t%llu\n",long_entries/1024/1024);
  50.        clGetDeviceInfo(devices[d],CL_DEVICE_LOCAL_MEM_SIZE,sizeof(cl_ulong),&long_entries,NULL);
  51.        printf("\tLocal Memory (KB):\t%llu\n",long_entries/1024);
  52.        clGetDeviceInfo(devices[d],CL_DEVICE_MAX_CLOCK_FREQUENCY,sizeof(cl_ulong),&long_entries,NULL);
  53.        printf("\tMax clock (MHz) :\t%llu\n",long_entries);
  54.        clGetDeviceInfo(devices[d],CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t),&p_size,NULL);
  55.        printf("\tMax Work Group Size:\t%d\n",p_size);
  56.        clGetDeviceInfo(devices[d],CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(cl_uint),&entries,NULL);
  57.        printf("\tNumber of parallel compute cores:\t%d\n",entries);
  58.    }
  59. }
  60. return 0;
  61. }
  62.  
  63. $ ./ocl_query.exe
  64. CL_PLATFORM_NAME = NVIDIA CUDA
  65. CL_PLATFORM_VERSION = OpenCL 1.1 CUDA 4.2.1
  66. 1 devices found
  67. Device #0 name = GeForce 9500 GT
  68.         Driver version = 306.97
  69.         Global Memory (MB):     1024
  70.         Global Memory Cache (MB):       0
  71.         Local Memory (KB):      16
  72.         Max clock (MHz) :       1350
  73.         Max Work Group Size:    512
  74.         Number of parallel compute cores:       4
  75. CL_PLATFORM_NAME = AMD Accelerated Parallel Processing
  76. CL_PLATFORM_VERSION = OpenCL 1.2 AMD-APP (938.2)
  77. 2 devices found
  78. Device #0 name = Cedar
  79.         Driver version = CAL 1.4.1741 (VM)
  80.         Global Memory (MB):     512
  81.         Global Memory Cache (MB):       0
  82.         Local Memory (KB):      32
  83.         Max clock (MHz) :       600
  84.         Max Work Group Size:    128
  85.         Number of parallel compute cores:       2
  86. Device #1 name =       Intel(R) Xeon(R) CPU E3-1225 V2 @ 3.20GHz
  87.         Driver version = 2.0 (sse2,avx)
  88.         Global Memory (MB):     8142
  89.         Global Memory Cache (MB):       0
  90.         Local Memory (KB):      32
  91.         Max clock (MHz) :       3192
  92.         Max Work Group Size:    1024
  93.         Number of parallel compute cores:       4
Advertisement
Add Comment
Please, Sign In to add comment