There are two APIs which enable coarse-grained synchronization, they are clFlush
and clFinish
. The reason why we call coarse grained is that both lack control over the individual tasks queued on the command queue. These two functions have control only at the queue level.
cl_int clFlush (cl_command_queue command_queue);
This function ensures that all the commands, which are queued on the command_queue
object will be submitted to the corresponding device. This does not guarantee that all the commands in the command_queue
will be completed after clFlush
returns.
First question which would arise is that what would happen if there is any blocking command queued to the device. Blocking commands do an implicit flush of the command_queue and on return from the blocking commands it will result in an implicit finish for the command_queue
. This means that these functions will not return until this command gets completed. All the clEnqueueRead*
and clEnqueueWrite*
commands...