m0n0lithic

OpenCL deviceQuery Sample

Dec 10th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.37 KB | None | 0 0
  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;
  12.    cl_ulong long_entries;
  13.    int d;
  14.    cl_int err;
  15.    cl_platform_id platform_id = NULL;
  16.    size_t p_size;
  17.  
  18. /* obtain list of platforms available */
  19.    err = clGetPlatformIDs(1, &platform_id,NULL);
  20.    if (err != CL_SUCCESS)
  21.    {
  22.        printf("Error: Failure in clGetPlatformIDs,error code=%d \n",err);
  23.        return 0;
  24.    }
  25.  
  26. /* obtain information about platform */
  27.    clGetPlatformInfo(platform_id,CL_PLATFORM_NAME,500,dname,NULL);
  28.    printf("CL_PLATFORM_NAME = %s\n", dname);
  29.    clGetPlatformInfo(platform_id,CL_PLATFORM_VERSION,500,dname,NULL);
  30.    printf("CL_PLATFORM_VERSION = %s\n", dname);
  31.  
  32. /* obtain list of devices available on platform */
  33.    clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, 10, devices, &num_devices);
  34.    printf("%d devices found\n", num_devices);
  35.  
  36. /* query devices for information */
  37.    for (d = 0; d < num_devices; ++d) {
  38.        clGetDeviceInfo(devices[d], CL_DEVICE_NAME, 500, dname,NULL);
  39.        printf("Device #%d name = %s\n", d, dname);
  40.        clGetDeviceInfo(devices[d],CL_DRIVER_VERSION, 500, dname,NULL);
  41.        printf("\tDriver version = %s\n", dname);
  42.        clGetDeviceInfo(devices[d],CL_DEVICE_GLOBAL_MEM_SIZE,sizeof(cl_ulong),&long_entries,NULL);
  43.        printf("\tGlobal Memory (MB):\t%llu\n",long_entries/1024/1024);
  44.        clGetDeviceInfo(devices[d],CL_DEVICE_GLOBAL_MEM_CACHE_SIZE,sizeof(cl_ulong),&long_entries,NULL);
  45.        printf("\tGlobal Memory Cache (MB):\t%llu\n",long_entries/1024/1024);
  46.        clGetDeviceInfo(devices[d],CL_DEVICE_LOCAL_MEM_SIZE,sizeof(cl_ulong),&long_entries,NULL);
  47.        printf("\tLocal Memory (KB):\t%llu\n",long_entries/1024);
  48.        clGetDeviceInfo(devices[d],CL_DEVICE_MAX_CLOCK_FREQUENCY,sizeof(cl_ulong),&long_entries,NULL);
  49.        printf("\tMax clock (MHz) :\t%llu\n",long_entries);
  50.        clGetDeviceInfo(devices[d],CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t),&p_size,NULL);
  51.        printf("\tMax Work Group Size:\t%d\n",p_size);
  52.        clGetDeviceInfo(devices[d],CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(cl_uint),&entries,NULL);
  53.        printf("\tNumber of parallel compute cores:\t%d\n",entries);
  54.    }
  55.  
  56.    return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment