|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#ifdef __APPLE__ |
| 4 | +#include <OpenCL/opencl.h> |
| 5 | +#else |
| 6 | +#include <CL/cl.h> |
| 7 | +#endif |
| 8 | + |
| 9 | +int main() { |
| 10 | + |
| 11 | + int i, j; |
| 12 | + char* value; |
| 13 | + size_t valueSize; |
| 14 | + cl_uint platformCount; |
| 15 | + cl_platform_id* platforms; |
| 16 | + cl_uint deviceCount; |
| 17 | + cl_device_id* devices; |
| 18 | + cl_uint maxComputeUnits; |
| 19 | + |
| 20 | + // get all platforms |
| 21 | + clGetPlatformIDs(0, NULL, &platformCount); |
| 22 | + platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount); |
| 23 | + clGetPlatformIDs(platformCount, platforms, NULL); |
| 24 | + |
| 25 | + for (i = 0; i < platformCount; i++) { |
| 26 | + |
| 27 | + // get all devices |
| 28 | + clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount); |
| 29 | + devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount); |
| 30 | + clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL); |
| 31 | + |
| 32 | + // for each device print critical attributes |
| 33 | + for (j = 0; j < deviceCount; j++) { |
| 34 | + |
| 35 | + // print device name |
| 36 | + clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize); |
| 37 | + value = (char*) malloc(valueSize); |
| 38 | + clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL); |
| 39 | + printf("%d. Device: %s\n", j+1, value); |
| 40 | + free(value); |
| 41 | + |
| 42 | + // print hardware device version |
| 43 | + clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, 0, NULL, &valueSize); |
| 44 | + value = (char*) malloc(valueSize); |
| 45 | + clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, valueSize, value, NULL); |
| 46 | + printf(" %d.%d Hardware version: %s\n", j+1, 1, value); |
| 47 | + free(value); |
| 48 | + |
| 49 | + // print software driver version |
| 50 | + clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &valueSize); |
| 51 | + value = (char*) malloc(valueSize); |
| 52 | + clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, valueSize, value, NULL); |
| 53 | + printf(" %d.%d Software version: %s\n", j+1, 2, value); |
| 54 | + free(value); |
| 55 | + |
| 56 | + // print c version supported by compiler for device |
| 57 | + clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize); |
| 58 | + value = (char*) malloc(valueSize); |
| 59 | + clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, valueSize, value, NULL); |
| 60 | + printf(" %d.%d OpenCL C version: %s\n", j+1, 3, value); |
| 61 | + free(value); |
| 62 | + |
| 63 | + // print parallel compute units |
| 64 | + clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, |
| 65 | + sizeof(maxComputeUnits), &maxComputeUnits, NULL); |
| 66 | + printf(" %d.%d Parallel compute units: %d\n", j+1, 4, maxComputeUnits); |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + free(devices); |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + free(platforms); |
| 75 | + return 0; |
| 76 | + |
| 77 | +} |
0 commit comments