microsoft / OpenCLOn12

The OpenCL-on-D3D12 mapping layer
MIT License
104 stars 13 forks source link

Incorrect number of bytes returned from clGetDeviceInfo #36

Closed MathiasMagnus closed 1 year ago

MathiasMagnus commented 2 years ago

While writing a report on using OpenCL-Layers as part of the CTS, I found that when querying CL_DEVICE_PARTITION_PROPERTIES, which ought to return a cl_device_partition_property[] (aka. intptr_t[]) OpenCLOn12 wishes to communicate it supports no device partitioning by returning the integral constant 0 as per the specs:

If the device cannot be partitioned (i.e. there is no partitioning scheme supported by the device that will return at least two subdevices), a value of 0 will be returned.

The function in question reads:

CL_API_ENTRY cl_int CL_API_CALL 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 the spec says:

param_value_size_ret returns the actual size in bytes of data being queried by param_name. If param_value_size_ret is NULL, it is ignored.

however OpenCLOn12 sets this value to 4 in an x64 application. This is less number of bytes then the single literal constant 0 written into a cl_device_partition_property instance. This renders code such as the following to malfunction:

size_t size;
EXPECT_SUCCESS(clGetDeviceInfo(device, CL_DEVICE_PARTITION_PROPERTIES, 0, nullptr, &size));
std::vector<cl_device_partition_property> properties(size / sizeof(cl_device_partition_property));
EXPECT_SUCCESS(clGetDeviceInfo(device, CL_DEVICE_PARTITION_PROPERTIES, size, properties.data(), nullptr));
jenatali commented 2 years ago

Yep, looks like I misread that one.