Galarius/vscode-opencl

Possible error in double precision FP capability reporting

exastone opened this issue · 3 comments

Might be lack of understand how but in the devices view I noticed that the D-GPU seems to indicate that double floating points are supported despite a 32-bit address space?

Is this a bug?

Screenshot 2023-07-30 at 9 06 45 PM

Hi @exastone!

Double-precision floating point numbers can be processed regardless of the address space's size. The 32-bit address memory determines how much memory the GPU can address directly (4GB). It doesn't impact the type of data that the GPU can process. Many hardware systems provide support for 64-bit integers and 64-bit floating point numbers (doubles) even on 32-bit systems.

The caveat is that not all GPUs are optimized for double-precision calculations. The performance and efficiency of handling 64-bit numbers can be lower on a 32-bit system compared to a 64-bit system.

Here is the code to verify that there is no bug in vscode-opencl:

main.c
#include <OpenCL/OpenCL.h>
#include <stdio.h>

int main()
{
    cl_uint num_platforms = 0;
    cl_uint num_devices = 0;
    char device_name[1024];
    char extensions[2048];

    clGetPlatformIDs(0, NULL, &num_platforms);
    cl_platform_id *platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id) * num_platforms);
    clGetPlatformIDs(num_platforms, platforms, NULL);

    for (int p = 0; p < num_platforms; ++p)
    {
        clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
        cl_device_id *devices = (cl_device_id *)malloc(sizeof(cl_device_id) * num_devices);
        clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);

        for (int i = 0; i < num_devices; ++i)
        {
            clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(device_name), device_name, NULL);
            clGetDeviceInfo(devices[i], CL_DEVICE_EXTENSIONS, sizeof(extensions), extensions, NULL);

            if (strstr(extensions, "cl_khr_fp64"))
            {
                printf("Device '%s' supports double precision\n", device_name);
            }
            else if (strstr(extensions, "cl_amd_fp64"))
            {
                printf("Device '%s' supports double precision with AMD extension\n", device_name);
            }
            else
            {
                printf("Device '%s' does not support double precision\n", device_name);
            }
        }
        free(devices);
    }
    free(platforms);
    return 0;
}

Assuming you are using macOS, compile main.c using the following command:

clang -framework OpenCL main.c -o clinfo

Example output of clinfo:

Device 'Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz' supports double precision
Device 'Intel(R) UHD Graphics 630' does not support double precision
Device 'AMD Radeon Pro 5500M Compute Engine' supports double precision
Device 'Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz' supports double precision
Device 'Intel(R) UHD Graphics 630' does not support double precision
Device 'AMD Radeon Pro 5500M Compute Engine' supports double precision

Everything seems to check out. When working with a piece of device code there was an issue that was fixed by changing the doubles to floats which led me to think DFP wasn't supported, it may have been I foolishly didn't have the correct device selected. Nevertheless I don't think there's an issue here, thanks!

Also, note that this extension need to be explicitly enabled in the OpenCL kernel code, by adding #pragma OPENCL EXTENSION cl_khr_fp64 : enable at the beginning of the OpenCL source code. This will enable the usage of double precision floating point numbers.