KhronosGroup / KhronosGroup/OpenCL-Docs

Waiting for Events in the Command Buffers Extension

Open
#793 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cl_khr_command_buffer
Dominant language
Python
Stars
421
Forks
132
Avg merge
5d 13h
Merged PRs (30d)
11

Description

I've been going through the proposed command buffer extension, to see if our application, PyFR, might benefit from it.

However, while attempting to port the OpenCL backend of our application over, I encountered an issue around events. Specifically, that it does not appear to be possible to wait on any of the kernels inside of a command buffer. This functionality is extremely useful in the context of HPC where it is necessary to interact with external libraries such as MPI. The idea is to have kernels which pack buffers and copy them to the host and then, as they complete, have the host-side kick off the relevant MPI_Isend calls. This is easy with regular OpenCL using events, and with CUDA/HIP's graph APIs using their event record nodes.

One solution here might be to add a

cl_int clCreateCommandSyncEventKHR(
   cl_command_buffer_khr command_buffer,
   cl_sync_point_khr* sync_point,
   cl_uint *ix
);

method to convert a sync point to an index and then a:

cl_int clEnqueueCommandBufferWithSyncEventsKHR(
     cl_uint num_queues,
     cl_command_queue* queues,
     cl_command_buffer_khr command_buffer,
     cl_uint num_sync_events,
     cl_event* sync_event_list,
     cl_uint num_events_in_wait_list,
     const cl_event* event_wait_list,
     cl_event* event);

which will mint a set of cl_events with the number of events being equal to the number of times clCreateCommandSyncEventKHR was called during recording. On platforms without any kind of native or preferred support for host side waiting, the functionality can be emulated internally without too much hassle (by cracking apart the command buffer into multiple smaller command buffers in an implementation defined manner).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the proposed command buffer extension and tracing its existing sync-point and event semantics. Evaluate the proposed clCreateCommandSyncEventKHR and clEnqueueCommandBufferWithSyncEventsKHR interfaces, including host-side waiting and emulation, then document a decided design and its completion semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
api, documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.