intel / intel/compute-runtime

[GSD-11964] clEnqueueReadBuffer fails on IGPUs for mapped host-buffer desinations

Open
#866 12 comments 0 reactions 0 assignees View on GitHub
OS: Linux Status: Marked as Stale Status: Needs Feedback
Dominant language
C++
Stars
1.4k
Forks
300
PR merge metrics
No merged PRs in 30d

Description

Consider the following snippet which I believe to be a valid use of the OpenCL API:
```c
#include
#include
#include
#include

#define CHECK(err, msg) \
if (err != CL_SUCCESS) { \
fprintf(stderr, "%s failed (%d)\n", msg, err); \
exit(1); \
}

int main(void) {
cl_int err;

cl_platform_id platform;
CHECK(clGetPlatformIDs(1, &platform, NULL), "clGetPlatformIDs");

cl_device_id device;
CHECK(clGetDeviceIDs(platform, CL_DEVICE_TYPE_DEFAULT, 1, &device, NULL),
"clGetDeviceIDs");

cl_context context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
CHECK(err, "clCreateContext");

cl_command_queue queue = clCreateCommandQueueWithProperties(context, device, 0, &err);
CHECK(err, "clCreateCommandQueue");

const size_t N = 16;
const size_t bytes = N * sizeof(float);
cl_mem dev_buf = clCreateBuffer(context, CL_MEM_READ_WRITE, bytes, NULL, &err);
CHECK(err, "clCreateBuffer dev_buf");

float pattern = 42.0f; // fill value
CHECK(clEnqueueFillBuffer(queue, dev_buf, &pattern, sizeof(float),
0, bytes, 0, NULL, NULL),
"clEnqueueFillBuffer");

cl_mem host_buf = clCreateBuffer(context,
CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR,
bytes, NULL, &err);
CHECK(err, "clCreateBuffer host_buf");

void *host_ptr = clEnqueueMapBuffer(queue, host_buf, CL_TRUE,
CL_MAP_WRITE, 0, bytes,
0, NULL, NULL, &err);
CHECK(err, "clEnqueueMapBuffer");

err = clEnqueueReadBuffer(queue, dev_buf, CL_FALSE, 0, bytes, host_ptr,
0, NULL, NULL);
CHECK(err, "clEnqueueReadBuffer (non-blocking)");

CHECK(clFinish(queue), "clFinish");

CHECK(clEnqueueUnmapMemObject(queue, host_buf, host_ptr, 0, NULL, NULL),
"clEnqueueUnmapMemObject");
clFinish(queue);

clReleaseMemObject(dev_buf);
clReleaseMemObject(host_buf);
clReleaseCommandQueue(queue);
clReleaseContext(context);

return 0;
}
```

Running this on an NVIDIA GPU or an Intel A770m works as expected. However, on my IGPU (TigerLake-H GT1) it fails with:

clEnqueueReadBuffer (non-blocking) failed (-5)

Changing to an ordinary buffer (from malloc) appears to work, as does changing to blocking reads. My runtime version is 25.40.35563.4 and I am on a 6.17.5 kernel with the i915 module.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.