vendredi 29 septembre 2017

If statement issue with Char * when trying to get OpenCL gpu device types

Ive been trying to verify which OpenCL platform amd gpu`s are located in, and at the same time count if there are more than one amd gpu on the system. I can get all visible outputs but im having a hard time using if statements to check if the displayed card actually are a advanced micro devices unit, i hope anyone can help me out a little here. Here is the current code:

if (listdevices)
{
    int i, j;
    char* value;
    char* ellesmere = "Ellesmere";
    char* valuemodel;
    char* amdman1 = "Advanced Micro Devices, Inc.";
    char* amdman2 = "Advanced Micro Devices, Inc";
    char* amdman3 = "AMD";
    char* amdman4 = "Advanced Micro Devices, Inc. ";
    char* value2;
    size_t valueSize;
    cl_uint platformCount;
    cl_platform_id* platforms;
    cl_device_type device_type;
    cl_uint deviceCount;
    cl_device_id* devices;
    cl_uint maxComputeUnits;
    cl_uint globalMemsize;
    uint64_t gpus = 0;
    bool amdplatformlocated = false;
    uint64_t amdplatform;
    uint64_t currentplatform;
    uint64_t countamd;

    // get all platforms
    clGetPlatformIDs(0, NULL, &platformCount);
    platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * platformCount);
    clGetPlatformIDs(platformCount, platforms, NULL);

    for (i = 0; i < platformCount; i++) {
        printf("\n\nPlatform-index: %d: \n\n", i);
        currentplatform = i;

        // get all devices
        clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU, 0, NULL, &deviceCount);
        devices = (cl_device_id*)malloc(sizeof(cl_device_id) * deviceCount);
        clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU, deviceCount, devices, NULL);

        // for each device print critical attributes
        for (j = 0; j < deviceCount; j++) {

            gpus++;

            // print device info & check if AMD model
            clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize);
            value = (char*)malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL);
            printf(" %d. Device: %s.\n", j + 1, value);
            if (value == ellesmere) {
                amdplatformlocated = true;
                amdplatform = currentplatform;
                printf(" %d.%d Located AMD Device: %s\n", j + 1, 2, amdplatformlocated);
            }
            free(value);

            // print manufacturer info & check if AMD
            clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, 0, NULL, &valueSize);
            value = (char*)malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, valueSize, value, NULL);
            clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, valueSize, value2, NULL);
            printf(" %d.%d Vendor: %s\n", j + 1, 1, value);
            if (value2 == amdman1 || value2 == amdman2 || value2 == amdman3 || value2 == amdman4) {
                amdplatformlocated = 1;
                amdplatform = currentplatform;
                printf(" %d.%d Located AMD Device: %s\n", j + 1, 2, amdplatformlocated);
                countamd++;
            }
            free(value);

            // print hardware device version
            clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, 0, NULL, &valueSize);
            value = (char*)malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, valueSize, value, NULL);
            printf(" %d.%d Hardware version: %s\n", j + 1, 2, value);
            free(value);

            // print software driver version
            clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &valueSize);
            value = (char*)malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, valueSize, value, NULL);
            printf(" %d.%d Software version: %s\n", j + 1, 3, value);
            free(value);

            // print c version supported by compiler for device
            clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize);
            value = (char*)malloc(valueSize);
            clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, valueSize, value, NULL);
            printf(" %d.%d OpenCL C version: %s\n", j + 1, 4, value);
            free(value);

            // print parallel compute units
            clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS,
                sizeof(maxComputeUnits), &maxComputeUnits, NULL);
            printf(" %d.%d Parallel compute units: %d\n", j + 1, 5, maxComputeUnits);
        }

        free(devices);

    }

    printf("\nWe have registered %d GPU`s on your System\n", gpus);
    if (amdplatformlocated == 1) {
        printf("It seems that platform %d contains AMD GPU`s., amdplatform);
    }
    else {
        printf("\nDid you find your AMD Card on this list?\n");
    }

    free(platforms);
    win_exit();
    return 0;
}

Which currently on a AMD RX570 Card gives this output:

> Platform-index: 0:
> 
> 
> 
> Platform-index: 1:
> 
>  1. Device: Ellesmere.
>  1.1 Vendor: Advanced Micro Devices, Inc.
>  1.2 Hardware version: OpenCL 2.0 AMD-APP (2442.12)
>  1.3 Software version: 2442.12
>  1.4 OpenCL C version: OpenCL C 2.0
>  1.5 Parallel compute units: 32
>  1.6 Maximum Memory Size:

We have registered 1 GPU`s on your System

Did you find your AMD Card on this list?

if (value == ellesmere) does not work neither do those in vendor section. Why is this? Both are current char * and if i make a simple code to compare those two it works, what am i not seeing?

Thanks

Aucun commentaire:

Enregistrer un commentaire