Summary
In the OpenCL device info wrapper, Device.Info.addressBits is annotated with the wrong cl_device_info value, so device.addressBits does not query address width.
Location
source/dcompute/driver/ocl/device.d (current master):
@(0x100C) uint maxClockFrequency;
@(0x1000) uint addressBits; // <-- wrong
@(0x100E) uint maxReadImageArgs;
type already correctly uses @(0x1000) a few lines above:
So addressBits reuses CL_DEVICE_TYPE and skips the constant that belongs between 0x100C and 0x100E.
Reference
From the OpenCL C headers (Khronos OpenCL-Headers CL/cl.h):
| Constant |
Value |
Meaning |
CL_DEVICE_TYPE |
0x1000 |
device type bitfield |
CL_DEVICE_MAX_CLOCK_FREQUENCY |
0x100C |
clock frequency |
CL_DEVICE_ADDRESS_BITS |
0x100D |
address bits (cl_uint) |
CL_DEVICE_MAX_READ_IMAGE_ARGS |
0x100E |
max read image args |
addressBits should use 0x100D, not 0x1000.
The generated getter (via generateGetInfo / clGetDeviceInfo) passes that UDA value as param_name, so the wrong query is what runs at runtime.
How this was found
While reviewing Device.Info UDA values against cl.h (after looking at the related size fix in #84 , #85, which corrected enum base types but did not change this attribute), the sequence 0x100C -> 0x1000 -> 0x100E stood out: 0x100D is missing and 0x1000 is already used for type.
Expected
device.addressBits should call clGetDeviceInfo(..., CL_DEVICE_ADDRESS_BITS, ...) and return the device address width (commonly 32 or 64).
Actual
device.addressBits calls clGetDeviceInfo(..., CL_DEVICE_TYPE, ...) with a uint-sized buffer. That is not the address-bits query; the returned value is not meaningful as address width.
How to reproduce
On any machine with a working OpenCL ICD and dcompute’s OCL driver:
import std.stdio;
import std.experimental.allocator;
import dcompute.driver.ocl;
void main()
{
Platform.initialise();
auto platforms = Platform.getPlatforms(theAllocator);
auto devices = platforms[0].getDevices(theAllocator);
auto d = devices[0];
writefln("name: %s", d.name);
writefln("type: %s (%s)", d.type, cast(ulong)d.type);
writefln("addressBits: %s", d.addressBits);
}
Compare addressBits with a direct query (or clinfo):
cl_uint bits;
clGetDeviceInfo(device, CL_DEVICE_ADDRESS_BITS, sizeof(bits), &bits, NULL);
You should see a mismatch: dcompute’s addressBits does not match CL_DEVICE_ADDRESS_BITS from clinfo / the direct call. (Exact wrong numeric value depends on the device and how the truncated CL_DEVICE_TYPE read lands in a uint.)
Proposed fix
Change the attribute only:
@(0x100D) uint addressBits;
Note on related work
#84 / #85 fixed OpenCL enum base type sizes so fields like type are read with the correct sizeof. That is separate from this bug, which is a wrong param_name constant on addressBits.
Summary
In the OpenCL device info wrapper,
Device.Info.addressBitsis annotated with the wrongcl_device_infovalue, sodevice.addressBitsdoes not query address width.Location
source/dcompute/driver/ocl/device.d(currentmaster):typealready correctly uses@(0x1000)a few lines above:@(0x1000) Type type;So
addressBitsreusesCL_DEVICE_TYPEand skips the constant that belongs between0x100Cand0x100E.Reference
From the OpenCL C headers (Khronos OpenCL-Headers
CL/cl.h):CL_DEVICE_TYPE0x1000CL_DEVICE_MAX_CLOCK_FREQUENCY0x100CCL_DEVICE_ADDRESS_BITS0x100Dcl_uint)CL_DEVICE_MAX_READ_IMAGE_ARGS0x100EaddressBitsshould use0x100D, not0x1000.The generated getter (via
generateGetInfo/clGetDeviceInfo) passes that UDA value asparam_name, so the wrong query is what runs at runtime.How this was found
While reviewing
Device.InfoUDA values againstcl.h(after looking at the related size fix in #84 , #85, which corrected enum base types but did not change this attribute), the sequence0x100C->0x1000->0x100Estood out:0x100Dis missing and0x1000is already used fortype.Expected
device.addressBitsshould callclGetDeviceInfo(..., CL_DEVICE_ADDRESS_BITS, ...)and return the device address width (commonly 32 or 64).Actual
device.addressBitscallsclGetDeviceInfo(..., CL_DEVICE_TYPE, ...)with auint-sized buffer. That is not the address-bits query; the returned value is not meaningful as address width.How to reproduce
On any machine with a working OpenCL ICD and dcompute’s OCL driver:
Compare
addressBitswith a direct query (orclinfo):You should see a mismatch: dcompute’s
addressBitsdoes not matchCL_DEVICE_ADDRESS_BITSfromclinfo/ the direct call. (Exact wrong numeric value depends on the device and how the truncatedCL_DEVICE_TYPEread lands in auint.)Proposed fix
Change the attribute only:
Note on related work
#84 / #85 fixed OpenCL enum base type sizes so fields like
typeare read with the correctsizeof. That is separate from this bug, which is a wrongparam_nameconstant onaddressBits.