0

If somebody tries to use clEnquyeReadBuiffer immediately after Enqueuing kernel , will not this be a bad since, the copying operation will start immediately after the kernel just is enqueued, and not executed?

clEnqueueNDRangeKernel(
queue,
kernel,
1,
NULL,
globalws,
localws,
0,
NULL,
NULL);


//this will start immediately, since above call is async
clEnqueueReadBuffer(
queue,
bufferOut,
CL_FALSE,
0,
10 * sizeof(int),
out,
0,
0,
0);
clFinish(queue);

In the above although because of clFinish(queue), it is guaranteed that host will see the data only after the complete data is copied, but how is that guaranteeing that data it self is correct, (since the data copying was started immediately after enqueuing of kernel). Is there anything wrong in my understanding?

1 Answer 1

2

If your command queue is in order then it works fine. The read operation will not commence until the kernel has finished execution.

In an Out of Order command queue the results are undefined.

How do you know if your command queue is in order or out of order? It's out of order only if you specify the flag CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE while calling clCreateCommandQueue. If you use that you must manually set sync points.

You don't also have to put the clFinish there. You can simply specify CL_TRUE as the third argument to clEnqueueReadBuffer so it becomes a blocking read. That means the implementation will wait until all commands enqueued before the readbuffer are finished, reads and then returns only when the data is valid and the read is finished.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.