#include <CL/cl.h>
#include <stdio.h>
int main()
{
unsigned int i, j; //iterator variables for loops
cl_int err;
cl_platform_id platforms[32]; //an array to hold the IDs of all the platforms, hopefuly there won't be more than 32
cl_uint num_platforms; //this number will hold the number of platforms on this machine
char vendor[1024]; //this strirng will hold a platforms vendor
cl_device_id devices[16]; //this variable holds the number of devices for each platform, hopefully it won't be more than 32 per platform
//32 devices doesn't work with TDM-GCC 4.9.2 64bit
cl_uint num_devices; //this number will hold the number of devices on this machine
char deviceName[1024]; //this string will hold the devices name
cl_uint numberOfCores; //this variable holds the number of cores of on a device
cl_long amountOfMemory; //this variable holds the amount of memory on a device
cl_uint clockFreq; //this variable holds the clock frequency of a device
cl_ulong maxAlocatableMem; //this variable holds the maximum allocatable memory
cl_ulong localMem; //this variable holds local memory for a device
cl_bool available; //this variable holds if the device is available
char buildinkernels[1024];
//get the number of platforms
clGetPlatformIDs (32, platforms, &num_platforms);
printf("\nNumber of platforms:\t%u\n\n", num_platforms);
//this is a loop for platforms
for(i = 0; i < num_platforms; i++)
{
printf("Platform:\t\t%u\n\n", i);
err=clGetPlatformInfo (platforms[i], CL_PLATFORM_VENDOR, sizeof(vendor), vendor, NULL);
printf("\tPlatform Vendor:\t%s (err==%d,%d)\n", vendor, err, CL_SUCCESS);
err=clGetDeviceIDs (platforms[i], CL_DEVICE_TYPE_ALL, sizeof(devices), devices, &num_devices);
printf("\tNumber of devices:\t%u (err==%d,%d) \n\n", num_devices, err, CL_SUCCESS);
//this is a loop for devices
for(j = 0; j < num_devices; j++)
{
//scan in device information
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(deviceName), deviceName, NULL);
clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL);
clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(numberOfCores), &numberOfCores, NULL);
clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(amountOfMemory), &amountOfMemory, NULL);
clGetDeviceInfo(devices[j], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(clockFreq), &clockFreq, NULL);
clGetDeviceInfo(devices[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(maxAlocatableMem), &maxAlocatableMem, NULL);
clGetDeviceInfo(devices[j], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(localMem), &localMem, NULL);
clGetDeviceInfo(devices[j], CL_DEVICE_AVAILABLE, sizeof(available), &available, NULL);
clGetDeviceInfo(devices[j], CL_DEVICE_BUILT_IN_KERNELS, sizeof(buildinkernels), &buildinkernels, NULL);
//print out device information
printf("\tDevice: %u\n", j);
printf("\t\tName:\t\t\t\t%s\n", deviceName);
printf("\t\tVendor:\t\t\t\t%s\n", vendor);
printf("\t\tAvailable:\t\t\t%s\n", available ? "Yes" : "No");
printf("\t\tCompute Units:\t\t\t%u\n", numberOfCores);
printf("\t\tClock Frequency:\t\t%u mHz\n", clockFreq);
printf("\t\tGlobal Memory:\t\t\t%0.00f mb\n", (double)amountOfMemory/1048576);
printf("\t\tMax Allocateable Memory:\t%0.00f mb\n", (double)maxAlocatableMem/1048576);
printf("\t\tLocal Memory:\t\t\t%u kb\n", (unsigned int)localMem);
printf("\t\tBuild In Kernels:\t\t%s\n",buildinkernels);
clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, sizeof(buildinkernels), &buildinkernels, NULL);
printf("\t\tOpenCL Version:\t\t\t%s\n",buildinkernels);
clGetDeviceInfo(devices[j], CL_DEVICE_PROFILE, sizeof(buildinkernels), &buildinkernels, NULL);
printf("\t\tDevice profile:\t\t\t%s\n",buildinkernels);
clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, sizeof(buildinkernels), &buildinkernels, NULL);
printf("\t\tDevice version:\t\t\t%s\n",buildinkernels);
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION , sizeof(buildinkernels), &buildinkernels, NULL);
printf("\t\tDriver version:\t\t\t%s\n",buildinkernels);
printf("\n");
}
}
system("PAUSE");
return 0;
}