Skip to content

(OpenCL) device.type is incorrect #84

Closed

Description

@takinutani

Get Device Type result is incorrect

At tests/main.d, I tried printing the device information,

    auto devices  = platform.getDevices(theAllocator);
    writeln("Devices:");
    foreach (i, ref d; devices)
    {
        writefln("\t[%d] %s", i, d.name);
        writefln("\t\t%s", d.vendor);
        writefln("\t\t(%d)%s", d.type, d.type);
        writefln("\t\t(%d)%s", d.queueProperties, d.queueProperties);
        writefln("\t\t(%d)%s", d.floatFPConfig, d.floatFPConfig);
        writefln("\t\t(%d)%s", d.GLobalMemoryCacheType, d.GLobalMemoryCacheType);
        writefln("\t\t(%d)%s", d.executionCapabilities, d.executionCapabilities);

    }

Outputs

Devices:
        [0] AMD Ryzen 7 8700G w/ Radeon 780M Graphics
                Intel(R) Corporation
                (1)default_
                (1)outOfOrderExecution
                (1)denorm
                (2)readWrite
                (0)kernel

The device type was expected to be a CPU (0x2).

The cause was a difference in the size of the enum type.

WIP: modify device.d/queue.d

Activity

  1. takinutani commented on Dec 15, 2025

    @takinutani
    ContributorAuthor

    Output expansion code by -mixin,

    // expansion at source\dcompute\driver\ocl\device.d(173,5)
    @property Device.Type type()
    {
        import std.typecons; typeof(return) ret;clGetDeviceInfo(raw,AliasSeq!(4096)[0], ret.sizeof, &ret, null);return ret; }
    

    from OpenCL API

    cl_int clGetDeviceInfo(
        cl_device_id device,
        cl_device_info param_name,
        size_t param_value_size,
        void* param_value,
        size_t* param_value_size_ret);

    and,
    from CL/cl.h

    typedef cl_ulong            cl_bitfield;
    
    typedef cl_bitfield         cl_device_type;
    typedef cl_bitfield         cl_device_fp_config;
    typedef cl_bitfield         cl_device_exec_capabilities;
    typedef cl_bitfield         cl_device_svm_capabilities;
    typedef cl_bitfield         cl_command_queue_properties;
    typedef cl_bitfield         cl_device_affinity_domain;
    
    typedef intptr_t            cl_device_partition_property;
    
    typedef cl_uint             cl_device_mem_cache_type;
    typedef cl_uint             cl_device_local_mem_type;

    The size of Device.Type should be the same as that of cl_device_type.

    from source/dcompute/driver/ocl/device.d

    struct Device
    {
        enum Type : int
        {
            default_     = 0x1,
            CPU         = 0x2,
            GPU         = 0x4,
            accelerator = 0x8,
            custom      = 0x10,
            all         = 0xFFFFFFFF
        }

    But enum base type is int, It was a size mismatch.

  2. takinutani commented on Dec 15, 2025

    @takinutani
    ContributorAuthor

    So correct device.d/queue.d enum base type, output become

    Devices:
            [0] AMD Ryzen 7 8700G w/ Radeon 780M Graphics
                    Intel(R) Corporation
                    (2)CPU
                    (3)cast(Properties)3
                    (7)cast(FPConfig)7
                    (2)readWrite
                    (3)cast(ExecutionCapabilities)3
    

    by

        enum Type : cl_bitfield
        {
            default_     = 0x1,
            CPU         = 0x2,
            GPU         = 0x4,
            accelerator = 0x8,
            custom      = 0x10,
            all         = 0xFFFFFFFF
        }
    
    ...and others
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions