Skip to content

Commit 10d8f8f

Browse files
authored
document command buffer APIs that are not thread-safe (KhronosGroup#1345)
1 parent 0e7dd9c commit 10d8f8f

4 files changed

Lines changed: 37 additions & 15 deletions

File tree

api/appendix_a.asciidoc

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,44 @@ how to correctly order operations that change the state of a shared object.
3030

3131
== Multiple Host Threads
3232

33-
All OpenCL API calls are thread-safe footnote:[{fn-thread-safe}] except those
34-
that modify the state of {cl_kernel_TYPE} objects: {clSetKernelArg},
33+
OpenCL calls that modify the state of {cl_kernel_TYPE} objects are not
34+
thread-safe footnote:[{fn-thread-safe}]: {clSetKernelArg},
3535
{clSetKernelArgSVMPointer}, {clSetKernelExecInfo} and {clCloneKernel}.
36-
{clSetKernelArg}, {clSetKernelArgSVMPointer}, {clSetKernelExecInfo} and
37-
{clCloneKernel} are safe to call from any host thread, and safe to call
38-
re-entrantly so long as concurrent calls to any combination of these API
39-
calls operate on different {cl_kernel_TYPE} objects.
40-
The state of the {cl_kernel_TYPE} object is undefined if {clSetKernelArg},
41-
{clSetKernelArgSVMPointer}, {clSetKernelExecInfo} or {clCloneKernel} are
42-
called from multiple host threads on the same {cl_kernel_TYPE} object at the same
43-
time footnote:[{fn-race-condition}].
36+
These APIs are safe to call from any host thread so long as concurrent calls
37+
operate on different {cl_kernel_TYPE} objects.
38+
The state of a {cl_kernel_TYPE} object is undefined if {clSetKernelArg},
39+
{clSetKernelArgSVMPointer}, {clSetKernelExecInfo} or {clCloneKernel} are called
40+
from multiple host threads on the same {cl_kernel_TYPE} object at the same time
41+
footnote:[{fn-race-condition}].
42+
43+
ifdef::cl_khr_command_buffer[]
44+
Additionally, OpenCL calls that modify the state of {cl_command_buffer_khr_TYPE}
45+
objects are not thread-safe:
46+
ifdef::cl_khr_command_buffer_mutable_dispatch[]
47+
{clFinalizeCommandBufferKHR} and {clUpdateMutableCommandsKHR}.
48+
endif::cl_khr_command_buffer_mutable_dispatch[]
49+
ifndef::cl_khr_command_buffer_mutable_dispatch[]
50+
{clFinalizeCommandBufferKHR}.
51+
endif::cl_khr_command_buffer_mutable_dispatch[]
52+
These APIs are safe to call from any host thread so long as concurrent calls
53+
operate on different {cl_command_buffer_khr_TYPE} objects.
54+
The state of the {cl_command_buffer_khr_TYPE} object is undefined if
55+
ifdef::cl_khr_command_buffer_mutable_dispatch[]
56+
{clFinalizeCommandBufferKHR} or {clUpdateMutableCommandsKHR} are
57+
endif::cl_khr_command_buffer_mutable_dispatch[]
58+
ifndef::cl_khr_command_buffer_mutable_dispatch[]
59+
{clFinalizeCommandBufferKHR} is
60+
endif::cl_khr_command_buffer_mutable_dispatch[]
61+
called from multiple host threads on the same {cl_command_buffer_khr_TYPE}
62+
object at the same time.
63+
endif::cl_khr_command_buffer[]
64+
65+
All other OpenCL API calls are thread-safe.
4466
Please note that there are additional limitations as to which OpenCL APIs
45-
may be called from <<event-objects,OpenCL callback functions>>.
67+
may be called from <<callback-functions,OpenCL callback functions>>.
4668

4769
The behavior of OpenCL APIs called from an interrupt or signal handler is
48-
implementation-defined
70+
implementation-defined.
4971

5072
The OpenCL implementation should be able to create multiple command-queues
5173
for a given OpenCL context and multiple OpenCL contexts in an application

api/footnotes.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ If the platform profile returned is EMBEDDED_PROFILE, then devices that are only
103103
:fn-race-condition: pass:n[ \
104104
There is an inherent race condition in the design of OpenCL that occurs between setting a kernel argument and using the kernel with {clEnqueueNDRangeKernel}. \
105105
Another host thread might change the kernel arguments between when a host thread sets the kernel arguments and then enqueues the kernel, causing the wrong kernel arguments to be enqueued. \
106-
Rather than attempt to share {cl_kernel_TYPE} objects among multiple host threads, applications are strongly encouraged to make additional {cl_kernel_TYPE} objects for kernel functions for each host thread. \
106+
Rather than attempt to share {cl_kernel_TYPE} objects among multiple host threads, applications are strongly encouraged to make additional {cl_kernel_TYPE} objects for each host thread. \
107107
]
108108

109109
:fn-readimageh: pass:n[ \

api/glossary.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,7 @@ Thread-safe ::
793793
by multiple _host_ threads.
794794
OpenCL API calls that are _thread-safe_ allow an application to call
795795
these functions in multiple _host_ threads without having to implement
796-
mutual exclusion across these _host_ threads i.e. they are also
797-
re-entrant-safe.
796+
mutual exclusion across these _host_ threads.
798797

799798
Undefined ::
800799
The behavior of an OpenCL API call, built-in function used inside a

api/opencl_runtime_layer.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5863,6 +5863,7 @@ Otherwise, it returns one of the following errors:
58635863
* {CL_OUT_OF_HOST_MEMORY} if there is a failure to allocate resources
58645864
required by the OpenCL implementation on the host.
58655865

5866+
[[callback-functions]]
58665867
[NOTE]
58675868
====
58685869
When the user callback function is called by the implementation, the

0 commit comments

Comments
 (0)