I’m using OpenCL 1.2, and I’m trying to figure out if there is an implicit clFlush() whenever calling clFinish(). Reading through the specs, they’re a little vague on the issue (from 5.13):
clFlush (cl_command_queue command_queue)
issues all previously queued OpenCL commands in command_queue to the device associated with command_queue.
clFinish (cl_command_queue command_queue)
blocks until all previously queued OpenCL commands in command_queue are issued to the associated device and have completed. clFinish does not return until all previously queued commands in command_queue have been processed and completed.
While it does state it will block until everything is completed, nowhere does it state that it will actually initiate a clFlush() on the queue. However, this is in contrast to the behavior I’m seeing currently in my application, which does the following in order (keep in mind I am using a single command queue and single device, but with CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE):
[li]Queues data on two different kernels using clEnqueueNDRangeKernel(), and stores the cl_event for each.[/li][li]Calls clFlush() on the queue: “To use event objects that refer to commands enqueued in a command-queue as event objects to wait on by commands enqueued in a different command-queue, the application must call a clFlush or any blocking commands that perform an implicit flush of the command-queue where the commands that refer to these event objects are enqueued.” (section 5.13)[/li][li]Queues up reading back the buffer either via clEnqueueReadBuffer() (for GPU buffers where I use CL_MEM_COPY_HOST_PTR) or clEnqueueMapBuffer() (for CPUs where I use CL_MEM_USE_HOST_PTR) that each wait on the respective kernel event. In both cases the blocking_* parameter is set to CL_FALSE.[/li][li]Calls clFinish() to block until both buffers have been read.[/li][/ol]
Note that I never call clFlush() between reading/mapping the buffer and calling clFinish(). If there isn’t an implicit clFlush() with clFinish(), my program should hang indefinitely as it’s blocking waiting for a command to finish that was never flushed from the queue. But, this is not the case, and my app works flawlessly on the platforms I’ve tested it on. That leaves two possibilities:
[li]I’m running into platform specific behavior, and my code may hang on other platforms that don’t feature this behavior.[/li][li]There is an implicit clFlush() from clFinish().[/li][/ul]
If I can’t count on the latter, is there any harm in calling clFlush() on a command queue and then having another clFlush() called implicitly by clFinish()?