/* https://www.sharcnet.ca/help/index.php/OpenCL
Compile: gcc -Wall -I/usr/include -o deviceQuery -lOpenCL deviceQuery.c
*/
#include <stdio.h>
#include <CL/cl.h>
int main(int argc, char** argv) {
char dname[500];
//cl_device_id devices[10];
cl_uint num_devices,entries,available;
cl_uint i,nplat=2;
cl_ulong long_entries;
int d;
cl_int err;
//cl_platform_id platform_id = NULL;
size_t maxDevices = 2;
cl_device_id* devices = (cl_device_id*)malloc(maxDevices*sizeof(cl_device_id));
cl_platform_id* platform_id = (cl_platform_id*)malloc(sizeof(cl_platform_id));
size_t p_size;
/* obtain list of platforms available */
err = clGetPlatformIDs(nplat, platform_id, &available);
if (err != CL_SUCCESS)
{
printf("Error: Failure in clGetPlatformIDs,error code=%d \n",err);
return 0;
}
for (i = 0; i < nplat; i++) {
/* obtain information about platform */
clGetPlatformInfo(platform_id[i],CL_PLATFORM_NAME,500,dname,NULL);
printf("CL_PLATFORM_NAME = %s\n", dname);
clGetPlatformInfo(platform_id[i],CL_PLATFORM_VERSION,500,dname,NULL);
printf("CL_PLATFORM_VERSION = %s\n", dname);
/* obtain list of devices available on platform */
clGetDeviceIDs(platform_id[i], CL_DEVICE_TYPE_ALL, 10, devices, &num_devices);
printf("%d devices found\n", num_devices);
/* query devices for information */
for (d = 0; d < num_devices; ++d) {
clGetDeviceInfo(devices[d], CL_DEVICE_NAME, 500, dname,NULL);
printf("Device #%d name = %s\n", d, dname);
clGetDeviceInfo(devices[d],CL_DRIVER_VERSION, 500, dname,NULL);
printf("\tDriver version = %s\n", dname);
clGetDeviceInfo(devices[d],CL_DEVICE_GLOBAL_MEM_SIZE,sizeof(cl_ulong),&long_entries,NULL);
printf("\tGlobal Memory (MB):\t%llu\n",long_entries/1024/1024);
clGetDeviceInfo(devices[d],CL_DEVICE_GLOBAL_MEM_CACHE_SIZE,sizeof(cl_ulong),&long_entries,NULL);
printf("\tGlobal Memory Cache (MB):\t%llu\n",long_entries/1024/1024);
clGetDeviceInfo(devices[d],CL_DEVICE_LOCAL_MEM_SIZE,sizeof(cl_ulong),&long_entries,NULL);
printf("\tLocal Memory (KB):\t%llu\n",long_entries/1024);
clGetDeviceInfo(devices[d],CL_DEVICE_MAX_CLOCK_FREQUENCY,sizeof(cl_ulong),&long_entries,NULL);
printf("\tMax clock (MHz) :\t%llu\n",long_entries);
clGetDeviceInfo(devices[d],CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t),&p_size,NULL);
printf("\tMax Work Group Size:\t%d\n",p_size);
clGetDeviceInfo(devices[d],CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(cl_uint),&entries,NULL);
printf("\tNumber of parallel compute cores:\t%d\n",entries);
}
}
return 0;
}
$ ./ocl_query.exe
CL_PLATFORM_NAME = NVIDIA CUDA
CL_PLATFORM_VERSION = OpenCL 1.1 CUDA 4.2.1
1 devices found
Device #0 name = GeForce 9500 GT
Driver version = 306.97
Global Memory (MB): 1024
Global Memory Cache (MB): 0
Local Memory (KB): 16
Max clock (MHz) : 1350
Max Work Group Size: 512
Number of parallel compute cores: 4
CL_PLATFORM_NAME = AMD Accelerated Parallel Processing
CL_PLATFORM_VERSION = OpenCL 1.2 AMD-APP (938.2)
2 devices found
Device #0 name = Cedar
Driver version = CAL 1.4.1741 (VM)
Global Memory (MB): 512
Global Memory Cache (MB): 0
Local Memory (KB): 32
Max clock (MHz) : 600
Max Work Group Size: 128
Number of parallel compute cores: 2
Device #1 name = Intel(R) Xeon(R) CPU E3-1225 V2 @ 3.20GHz
Driver version = 2.0 (sse2,avx)
Global Memory (MB): 8142
Global Memory Cache (MB): 0
Local Memory (KB): 32
Max clock (MHz) : 3192
Max Work Group Size: 1024
Number of parallel compute cores: 4
Comments