Robin
Robin

Reputation: 45

OpenCL: Why using clEnqueueMapBuffer Crash without return error?

I have problem when I use the clEnqueueMapBuffer to get the calculation result from kernel, it will crash without any error back. My process is under:

.
.
// Create a buffer in Host, and use CL_MEM_USE_HOST_PTR in device
int out_data;
cl_mem cl_dst = clCreateBuffer(context_CL, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, sizeof(int), &out_data, &err);
.
.
//Do something in a kernel(ignore the detail of kernel and other input data, because there is no wrong there. the output is cl_dst(INT))
err = clEnqueueNDRangeKernel(....)
.
.
//Mapping the result back to the host
clEnqueueMapBuffer(queue_CL, cl_dst, CL_TRUE, CL_MAP_READ, 0, sizeof(cl_dst), 0, NULL, NULL, &err);
//And then my graphic card shut down here at this command...
.
.
.

My graphic card is Intel HD 5500 (support OpenCL 2.0) Do I have a wrong flags somewhere or missing some important concepts?

Upvotes: 0

Views: 529

Answers (1)

Bartosz Sochacki
Bartosz Sochacki

Reputation: 66

I think the size of mapped region is not correct:

clEnqueueMapBuffer(queue_CL, cl_dst, CL_TRUE, CL_MAP_READ, 0, sizeof(cl_dst), 0, NULL, NULL, &err);

It should be:

clEnqueueMapBuffer(queue_CL, cl_dst, CL_TRUE, CL_MAP_READ, 0, sizeof(int), 0, NULL, NULL, &err);

Per OpenCL 2.0 spec:

"offset and size are the offset in bytes and the size of the region in the buffer object that is being mapped."

Upvotes: 1

Related Questions