Clarification on working of asynchronous calls in OpenCL

Clarification on working of asynchronous calls in OpenCL

Can someone explain the working of the asynchronous calls in OpenCL..? Say I have clEnqueueWriteBuffer() with no wait for events, so this is an asynch call. If I havean NDRangeKernel() after this.. How will the kernel know that the buffer has been written by clEnqueueWriteBuffer and that it can start execution..?

Also after the kernel execution if there is clEnqueueReadBuffer, how will the host come to know that the kernel has finished execution and that it can read the results?

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,If you set the third parameter of clEnqueueWriteBuffer as true, the host thread will be blocked and wait for its finish. Or it isasynchronous call. You can add the event generated byclEnqueueWriteBuffer to events waiting list ofNDRangeKernel. So it will wait for the finish ofclEnqueueWriteBuffer. So isclEnqueueReadBuffer.ZHAO Peng

Hey thanks for the reply. I am still not completely clear. So what if I give the 3rd parameter as CL_FALSE in clEnqueueWriteBuffer, in that case does it become necessary to specify events ?

Again if there isclEnqueueReadBuffer after the NDRangeKernel, How does the clEnqueueReadBuffer come to know that the NDRangeKernel has completed? (Assume that I have not generated any event in the NDRangeKernel so as to specify inclEnqueueReadBuffer to wait for)

If you make a non-blocking clEnqueueWriteBuffer() call and do not specify the event, it won't be possible for your application to query the status of the command. You will not know when or if the command was executed.

You have to understand that the enque calls put the commands in the queue and not necessarily execute when you call the API.You canmake sure you have the buffer ready to be read bymaking a blocking call or using an event to query the status. Or your commands in the command queue will be submitted when you call clFlush() or clFinish(). Hope that's clear.


if your queue is in-order (which is default), commands submited to the queue will be executed one by one.
But in order to wait for the results (e.g. for some final clEnqueueRead) you would need to wait for completition of the submitted sequence: remember that func call (without explicit blocking) means just placing the call in the queue. So if you don't have some event to wait on, the only option would be clFinish.

Thanks a lot. I am able to understand it clearly now :)

Leave a Comment

Please sign in to add a comment. Not a member? Join today