#include <stdio.h>
#include <CL/cl.h>

int main() {
    cl_uint platformCount;
    clGetPlatformIDs(0, NULL, &platformCount);
    cl_platform_id *platforms = (cl_platform_id *)malloc(platformCount * sizeof(cl_platform_id));
    clGetPlatformIDs(platformCount, platforms, NULL);

    for (cl_uint i = 0; i < platformCount; i++) {
        char platformName[128];
        clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 128, platformName, NULL);
        printf("Platform %d: %s\n", i, platformName);

        cl_uint deviceCount;
        clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount);
        cl_device_id *devices = (cl_device_id *)malloc(deviceCount * sizeof(cl_device_id));
        clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL);

        for (cl_uint j = 0; j < deviceCount; j++) {
            char deviceName[128];
            clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 128, deviceName, NULL);
            printf("  Device %d: %s\n", j, deviceName);
        }
        free(devices);
    }
    free(platforms);
    return 0;
}