#include <stdio.h>
#include <stdlib.h>
//#define CL_USE_DEPRECATED_OPENCL_2_0_APIS
#include "opencl.h"
//#include "CL/cl.h"
int main() {
// get all platforms
cl_uint totalPlatforms;
cl_platform_id* platforms = NULL;
clGetPlatformIDs(0, NULL, &totalPlatforms);
platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * totalPlatforms);
clGetPlatformIDs(totalPlatforms, platforms, NULL);
char* buf = NULL;
size_t bufSize;
cl_uint totalDevices;
cl_device_id* devices = NULL;;
cl_uint totalComputeUnits;
for (unsigned int i = 0; i < totalPlatforms; i++) {
// get all devices
clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &totalDevices);
devices = (cl_device_id*)malloc(sizeof(cl_device_id) * totalDevices);
clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, totalDevices, devices, NULL);
for (unsigned int j = 0; j < totalDevices; j++) {
// print device name
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &bufSize);
buf = (char*)malloc(bufSize);
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, bufSize, buf, NULL);
printf("Device: %s\n", buf);
free(buf);
// print device hardware version
clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, 0, NULL, &bufSize);
buf = (char*)malloc(bufSize);
clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, bufSize, buf, NULL);
printf("Device hardware version: %s\n", buf);
free(buf);
// print software driver version
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &bufSize);
buf = (char*)malloc(bufSize);
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, bufSize, buf, NULL);
printf("Software driver version: %s\n", buf);
free(buf);
// print device c version supported
clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &bufSize);
buf = (char*)malloc(bufSize);
clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, bufSize, buf, NULL);
printf("OpenCL C version supported: %s\n", buf);
free(buf);
// print parallel compute units
clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(totalComputeUnits),
&totalComputeUnits, NULL);
printf("Parallel compute units: %d\n", totalComputeUnits);
}
free(devices);
}
free(platforms);
char ch = getchar();
return 0;
}
/*
run:
Device: NVIDIA GeForce GTX 1050 Ti
Device hardware version: OpenCL 3.0 CUDA
Software driver version: 512.15
OpenCL C version supported: OpenCL C 1.2
Parallel compute units: 6
*/