Advertisement
Guest User

opencl detecter

a guest
Jul 13th, 2015
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "CL/cl.h"
  3.  
  4. int main() {
  5.         unsigned int i, j;      //iterator variables for loops
  6.  
  7.         cl_platform_id platforms[32];   //an array to hold the IDs of all the platforms, hopefuly there won't be more than 32
  8.         cl_uint num_platforms;  //this number will hold the number of platforms on this machine
  9.         char vendor[1024];      //this strirng will hold a platforms vendor
  10.  
  11.         cl_device_id devices[32];       //this variable holds the number of devices for each platform, hopefully it won't be more than 32 per platform
  12.         cl_uint num_devices;    //this number will hold the number of devices on this machine
  13.         char deviceName[1024];  //this string will hold the devices name
  14.         cl_uint numberOfCores;  //this variable holds the number of cores of on a device
  15.         cl_long amountOfMemory; //this variable holds the amount of memory on a device
  16.         cl_uint clockFreq;      //this variable holds the clock frequency of a device
  17.         cl_ulong maxAlocatableMem;      //this variable holds the maximum allocatable memory
  18.         cl_ulong localMem;      //this variable holds local memory for a device
  19.         cl_bool available;      //this variable holds if the device is available
  20.  
  21.         //get the number of platforms
  22.         clGetPlatformIDs (32, platforms, &num_platforms);
  23.                                                                                                                                                                                
  24.         printf("\nNumber of platforms:\t%u\n\n", num_platforms);                                                                                                              
  25.                                                                                                                                                                                
  26.         //this is a loop for platforms                                                                                                                                        
  27.         for(i = 0; i < num_platforms; i++) {                                                                                                                                  
  28.                 printf("Platform:\t\t%u\n\n", i);
  29.                 clGetPlatformInfo (platforms[i], CL_PLATFORM_VENDOR, sizeof(vendor), vendor, NULL);
  30.                 printf("\tPlatform Vendor:\t%s\n", vendor);
  31.  
  32.                 clGetDeviceIDs (platforms[i], CL_DEVICE_TYPE_ALL, sizeof(devices), devices, &num_devices);
  33.                 printf("\tNumber of devices:\t%u\n\n", num_devices);
  34.                 //this is a loop for devices
  35.                 for(j = 0; j < num_devices; j++) {
  36.                         //scan in device information
  37.                         clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(deviceName), deviceName, NULL);
  38.                         clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL);
  39.                         clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(numberOfCores), &numberOfCores, NULL);
  40.                         clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(amountOfMemory), &amountOfMemory, NULL);
  41.                         clGetDeviceInfo(devices[j], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(clockFreq), &clockFreq, NULL);
  42.                         clGetDeviceInfo(devices[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(maxAlocatableMem), &maxAlocatableMem, NULL);
  43.                         clGetDeviceInfo(devices[j], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(localMem), &localMem, NULL);
  44.                         clGetDeviceInfo(devices[j], CL_DEVICE_AVAILABLE, sizeof(available), &available, NULL);
  45.  
  46.                         //print out device information
  47.                         printf("\tDevice: %u\n", j);
  48.                         printf("\t\tName:\t\t\t\t%s\n", deviceName);
  49.                         printf("\t\tVendor:\t\t\t\t%s\n", vendor);
  50.                         printf("\t\tAvailable:\t\t\t%s\n", available ? "Yes" : "No");
  51.                         printf("\t\tCompute Units:\t\t\t%u\n", numberOfCores);
  52.                         printf("\t\tClock Frequency:\t\t%u mHz\n", clockFreq);
  53.                         printf("\t\tGlobal Memory:\t\t\t%0.00f mb\n", (double)amountOfMemory/1048576);
  54.                         printf("\t\tMax Allocateable Memory:\t%0.00f mb\n", (double)maxAlocatableMem/1048576);
  55.                         printf("\t\tLocal Memory:\t\t\t%u kb\n\n", (unsigned int)localMem);
  56.                 }
  57.         }
  58.         return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement