Results 1 to 2 of 2

Thread: Implicit clFlush() when using clFinish()?

  1. #1
    Join Date
    Apr 2018

    Implicit clFlush() when using clFinish()?

    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):

    1. Queues data on two different kernels using clEnqueueNDRangeKernel(), and stores the cl_event for each.
    2. 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)
    3. 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.
    4. Calls clFinish() to block until both buffers have been read.

    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:

    • I'm running into platform specific behavior, and my code may hang on other platforms that don't feature this behavior.
    • There is an implicit clFlush() from clFinish().

    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()?
    Last edited by speccy; 04-21-2018 at 01:54 AM.

  2. #2
    Join Date
    Apr 2018
    I can no longer edit the original post, but I also wanted to note that clFinish() is missing from the list of commands that cause an implicit clFlush(). Again, from 5.13:
    Any blocking commands queued in a command-queue and clReleaseCommandQueue perform an implicit flush of the command-queue. These blocking commands are clEnqueueReadBuffer, clEnqueueReadBufferRect, clEnqueueReadImage, with blocking_read set to CL_TRUE; clEnqueueWriteBuffer, clEnqueueWriteBufferRect, clEnqueueWriteImage with blocking_write set to CL_TRUE ; clEnqueueMapBuffer, clEnqueueMapImage with blocking_map set to CL_TRUE ; or clWaitForEvents.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean