Skip to content

OpenCL error with CL_MISALIGNED_SUB_BUFFER_OFFSET #8235

@micragz

Description

@micragz

Hello, and thanks for this amazing project.

We are seeing Halide errors on some devices. They seem to originate from Halide's OpenCL call to clCreateSubBuffer:

mem = clCreateSubBuffer(mem, CL_MEM_READ_WRITE, CL_BUFFER_CREATE_TYPE_REGION, &region, &err);

With CL_MISALIGNED_SUB_BUFFER_OFFSET being returned from here. This error code is described as follows from clCreateSubBuffer:

CL_MISALIGNED_SUB_BUFFER_OFFSET if there are no devices in context associated with buffer for which the origin field of the cl_buffer_region structure passed in buffer_create_info is aligned to the CL_DEVICE_MEM_BASE_ADDR_ALIGN value.

With the mentioned origin field being set from the Halide buffer's own offset.

In particular, we have seen this error on the Intel OpenCL CPU runtime and on AMD GPUs. On the other hand, NVidia and Intel GPUs in particular do not seem to report the misalignment error, as far as we have seen.

We have observed that the call to clCreateSubBuffer from Halide does seem to violate this condition occasionally on all devices, even though only some of them report OpenCL errors as a result. As an example, we can see an offset of 321984 bytes (aligned to 64 bytes), with a required device alignment of 128 bytes. So it seems that the driver implementations diverge in how lenient they are on this condition, but Halide often violates it regardless.

Are there some steps that can be taken to prevent violating this alignment condition from the Halide side?

Metadata

Metadata

Assignees

No one assigned

    Labels

    dev_meetingTopic to be discussed at the next dev meeting

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions