Skip to content

Commit cf7ca27

Browse files
authored
update command buffer emulation layer to latest spec version (#151)
* update command buffer emulation layer to latest spec version The command buffer emulation layer will support setting deferred kernel arguments, but will not properly handle the new FINALIZED state. * add a note about updating the README when updating versions
1 parent d583736 commit cf7ca27

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

layers/10_cmdbufemu/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It works by intercepting calls to `clGetExtensionFunctionAddressForPlatform` to
77
If a query succeeds by default then the layer does nothing and simply returns the queried function pointer as-is.
88
If the query is unsuccessful however, then the layer returns its own function pointer, which will record the contents of the command buffer for later playback.
99

10-
This command buffer emulation layer currently implements v0.9.4 of the `cl_khr_command_buffer` extension and v0.9.0 of the `cl_khr_command_buffer_mutable_dispatch` extension.
10+
This command buffer emulation layer currently implements v0.9.8 of the `cl_khr_command_buffer` extension and v0.9.5 of the `cl_khr_command_buffer_mutable_dispatch` extension.
1111
The functionality in this emulation layer is sufficient to run the command buffer samples in this repository.
1212

1313
Please note that the emulated command buffers are intended to be functional, but unlike a native implementation, they may not provide any performance benefit over similar code without using command buffers.
@@ -40,4 +40,5 @@ The following environment variables can modify the behavior of the command buffe
4040
This section describes some of the limitations of the emulated `cl_khr_command_buffer` functionality:
4141

4242
* Some error conditions are not properly checked for and returned.
43+
* Deferred kernel arguments are supported, but `CL_COMMAND_BUFFER_STATE_FINALIZED_KHR` is not properly handled.
4344
* Many functions are not thread safe.

layers/10_cmdbufemu/emulate.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
#include "emulate.h"
2121

22+
// Reminder: When updating these versions, update the README also!
2223
static constexpr cl_version version_cl_khr_command_buffer =
23-
CL_MAKE_VERSION(0, 9, 7);
24+
CL_MAKE_VERSION(0, 9, 8);
2425
static constexpr cl_version version_cl_khr_command_buffer_mutable_dispatch =
25-
CL_MAKE_VERSION(0, 9, 3);
26+
CL_MAKE_VERSION(0, 9, 5);
2627

2728
SLayerContext& getLayerContext(void)
2829
{
@@ -2113,6 +2114,13 @@ cl_int CL_API_CALL clEnqueueCommandBufferKHR_EMU(
21132114
}
21142115
}
21152116

2117+
// If the error code is CL_INVALID_KERNEL_ARGS, then there are probably
2118+
// deferred kernel arguments and the command buffer is not yet in the
2119+
// executable state, therefore we should return CL_INVALID_OPERATION.
2120+
if( errorCode == CL_INVALID_KERNEL_ARGS )
2121+
{
2122+
errorCode = CL_INVALID_OPERATION;
2123+
}
21162124
return errorCode;
21172125
}
21182126

@@ -2821,7 +2829,12 @@ cl_int CL_API_CALL clCommandNDRangeKernelKHR_EMU(
28212829
nullptr,
28222830
nullptr ) )
28232831
{
2824-
return errorCode;
2832+
// Ignore CL_INVALID_KERNEL_ARGS errors if this is a mutable
2833+
// command in order to handle deferred kernel arguments.
2834+
if( !( errorCode == CL_INVALID_KERNEL_ARGS && mutable_handle ) )
2835+
{
2836+
return errorCode;
2837+
}
28252838
}
28262839
}
28272840

0 commit comments

Comments
 (0)