OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1719 Discussions

Clarification on working of asynchronous calls in OpenCL

nikey1
Beginner
692 Views
Hello,
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?
0 Kudos
5 Replies
zhaopeng
Beginner
692 Views
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
0 Kudos
nikey1
Beginner
692 Views
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)
0 Kudos
Raghupathi_M_Intel
692 Views

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.

Thanks,
Raghu

0 Kudos
Maxim_S_Intel
Employee
692 Views

Hi,
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.

0 Kudos
nikey1
Beginner
692 Views
Thanks a lot. I am able to understand it clearly now :)
0 Kudos
Reply