Skip to content

Commit d9c24e9

Browse files
authored
out-of-order command buffer support and sample (#60)
* merge improvements and reduce code deltas * add support for out-of-order command buffers * actually create an out-of-order command buffer * fix README * add more command line options * update README, add command buffer picture
1 parent 77d4c88 commit d9c24e9

10 files changed

Lines changed: 896 additions & 149 deletions

File tree

include/layer_util.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <CL/cl_layer.h>
99

1010
#include <cstring>
11+
#include <cctype>
1112
#include <vector>
1213

1314
template<class T>
@@ -76,6 +77,37 @@ static inline cl_int writeStringToMemory(
7677
return CL_SUCCESS;
7778
}
7879

80+
static cl_uint getOpenCLVersionFromString(
81+
const char* str)
82+
{
83+
cl_uint major = 0;
84+
cl_uint minor = 0;
85+
86+
// The device version string has the form:
87+
// OpenCL <Major>.<Minor> <Vendor Specific Info>
88+
const char* prefix = "OpenCL ";
89+
size_t sz = strlen(prefix);
90+
if (strlen(str) > sz &&
91+
strncmp(str, prefix, sz) == 0) {
92+
const char* check = str + sz;
93+
while (isdigit(check[0])) {
94+
major *= 10;
95+
major += check[0] - '0';
96+
++check;
97+
}
98+
if (check[0] == '.') {
99+
++check;
100+
}
101+
while (isdigit(check[0])) {
102+
minor *= 10;
103+
minor += check[0] - '0';
104+
++check;
105+
}
106+
}
107+
108+
return (major << 16) | minor;
109+
}
110+
79111
static inline bool checkStringForExtension(
80112
const char* str,
81113
const char* extensionName )

layers/10_cmdbufemu/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ The functionality in this emulation layer is sufficient to run the command buffe
1212

1313
Please note that the emulated command buffers are intended to be functional, but unlike a native implementation of `cl_khr_command_buffer`, they may not provide any performance benefit over similar code without using command buffers.
1414

15+
## Layer Requirement
16+
17+
Because this layer calls `clCloneKernel` when recording a command buffer it requires an OpenCL 2.1 or newer device.
18+
If an older device is detected then the layer will not advertise support for the `cl_khr_command_buffer` extension.
19+
1520
## Key APIs and Concepts
1621

1722
The most important concepts to understand from this sample are how to intercept `clGetExtensionFunctionAddressForPlatform` to return emulated functions for an extension.
@@ -27,3 +32,4 @@ This section describes some of the limitations of the emulated `cl_khr_command_b
2732

2833
* The event associated with `clEnqueueCommandBufferKHR` will not have the proper event command type `CL_COMMAND_COMMAND_BUFFER_KHR`.
2934
* Event profiling for `clEnqueueCommandBufferKHR` will not be correct for the `QUEUED`, `SUBMITTED`, and `START` times.
35+
* Many error conditions are not properly checked for and returned.

0 commit comments

Comments
 (0)