| 16 | #include "common.h" |
| 17 | |
| 18 | int openCLdevicepoll(void) |
| 19 | { |
| 20 | printf("\nOpenCL Platform Information:\n"); |
| 21 | |
| 22 | char* value; |
| 23 | size_t valueSize; |
| 24 | cl_uint platformCount; |
| 25 | cl_platform_id* platforms; |
| 26 | cl_uint deviceCount; |
| 27 | cl_device_id* devices; |
| 28 | cl_uint maxComputeUnits; |
| 29 | cl_uint maxWorkGroupSize; |
| 30 | cl_uint maxWorkItemDims; |
| 31 | //cl_device_partition_property *partition_properties; |
| 32 | |
| 33 | // get all platforms |
| 34 | clGetPlatformIDs(0, NULL, &platformCount); |
| 35 | |
| 36 | if(!platformCount) |
| 37 | { |
| 38 | printf("No OpenCL Compatible Platforms found\n"); |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount); |
| 43 | clGetPlatformIDs(platformCount, platforms, NULL); |
| 44 | |
| 45 | for (int i = 0; i < (int)platformCount; i++) { |
| 46 | |
| 47 | // get all devices |
| 48 | clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount); |
| 49 | devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount); |
| 50 | clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL); |
| 51 | |
| 52 | // for each device print critical attributes |
| 53 | for (int j = 0; j < (int)deviceCount; j++) { |
| 54 | |
| 55 | // print device name |
| 56 | clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize); |
| 57 | value = (char*) malloc(valueSize); |
| 58 | clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL); |
| 59 | printf("%d. Device: %s\n", j+1, value); |
| 60 | free(value); |
| 61 | |
| 62 | // print device type |
| 63 | clGetDeviceInfo(devices[j], CL_DEVICE_TYPE, 0, NULL, &valueSize); |
| 64 | value = (char*) malloc(valueSize); |
| 65 | clGetDeviceInfo(devices[j], CL_DEVICE_TYPE, valueSize, value, NULL); |
| 66 | if((int)*value == CL_DEVICE_TYPE_CPU) |
| 67 | printf(" %d.%d Device Type: %s\n", j+1, 0, "CPU"); |
| 68 | else if((int)*value == CL_DEVICE_TYPE_GPU) |
| 69 | printf(" %d.%d Device Type: %s\n", j+1, 0, "GPU"); |
| 70 | else if((int)*value == CL_DEVICE_TYPE_ACCELERATOR) |
| 71 | printf(" %d.%d Device Type: %s\n", j+1, 0, "ACCELERATOR"); |
| 72 | else |
| 73 | printf(" %d.%d Device Type: %s\n", j+1, 0, "DEFAULT/ALL"); |
| 74 | free(value); |
| 75 | |