OpenCL-Docs icon indicating copy to clipboard operation
OpenCL-Docs copied to clipboard

cl_khr_command_buffer: clarify thread safety

Open jansol opened this issue 3 years ago • 2 comments

The command buffer extension specification, as presented in this repo at the time of writing does not make any mention of the thread safety of command buffer operations. Only the simultaneous use property for submitting the same command buffer multiple times without waiting for its completion between submissions is given. Appendix A of the unified API specification mentions that all commands except those that modify kernel object state are thread safe.

Should this be taken to imply that recording commands to a command buffer from multiple threads is meant to be allowed?

jansol avatar Jul 14 '22 12:07 jansol

Thanks very much for the question, the intention is that the new command-buffer entry-points inherit that appendix wording. So indeed recording commands to a command-buffer from multiple-threads is allowed by the spec. I can add a note to the spec to clarify this.

My recollection of when we discussed this in the working group was that we envisaged a typical usage model where building the command-buffer would be done by a single thread, but multiple threads may launch the command-buffer (for the simultaneous use case). However, all the entry-points were made thread safe to make things easier for the user. It was assumed this wouldn't be an unreasonable implementation overhead for the runtime, and if it turned out to be, then we could revisit this before the extension turned to final.

I'm curious if you have a use case you could share for multiple threads constructing the command-buffer?

EwanC avatar Jul 14 '22 12:07 EwanC

I don't have any specific use case in mind, just wanted to clarify the requirements for the API implementation side of things.

I suppose one case where this would be relevant is if there is substantial precomputation required and the application has a multi-threaded job system in place that can be used to perform the precomputation and command recording as one task. Compiling specialized kernels (perhaps even FPGA synthesis?) that can change at run time and thus necessitate re-recording the command buffer could be one such a task.

jansol avatar Jul 14 '22 13:07 jansol