|
| 1 | +// Copyright 2018-2024 The Khronos Group Inc. |
| 2 | +// SPDX-License-Identifier: CC-BY-4.0 |
| 3 | + |
| 4 | +include::{generated}/meta/{refprefix}cl_khr_command_buffer_mutable_memory_commands.txt[] |
| 5 | + |
| 6 | +=== Other Extension Metadata |
| 7 | + |
| 8 | +*Last Modified Date*:: |
| 9 | + 2024-03-28 |
| 10 | +*IP Status*:: |
| 11 | + No known IP claims. |
| 12 | +*Contributors*:: |
| 13 | + - Ewan Crawford, Codeplay Software Ltd. |
| 14 | + - Kenneth Benzie, Codeplay Software Ltd. |
| 15 | + - Jack Frankland, Codeplay Software Ltd. |
| 16 | + - Ben Ashbaugh, Intel. |
| 17 | + - Balaji Calidas, Qualcomm Technologies Inc. |
| 18 | + - Sreelakshmi Haridas Maruthur, Qualcomm Technologies Inc. |
| 19 | + - Kevin Petit, Arm Ltd. |
| 20 | + |
| 21 | +=== Description |
| 22 | + |
| 23 | +The <<cl_khr_command_buffer>> extension separates command construction from |
| 24 | +enqueue by providing a mechanism to record an immutable set of commands which |
| 25 | +can then be repeatedly enqueued. Another extension layered on top, |
| 26 | +<<cl_khr_command_buffer_mutable_dispatch>> allows ND-Range kernel execution |
| 27 | +commands recorded to a command-buffer to be modified between command-buffer |
| 28 | +enqueues by providing a command-buffer update API {clUpdateMutableCommandsKHR}. |
| 29 | + |
| 30 | +`cl_khr_command_buffer_mutable_memory_commands` builds on |
| 31 | +<<cl_khr_command_buffer_mutable_dispatch>> to use the {clUpdateMutableCommandsKHR} |
| 32 | +entry-point for enabling mutability of _memory-commands_ recorded to a |
| 33 | +command-buffer, those commands taking a {cl_mem_TYPE} or SVM pointer argument. |
| 34 | + |
| 35 | +=== New Structures |
| 36 | + |
| 37 | + * {cl_mutable_copy_buffer_command_config_khr_TYPE} |
| 38 | + * {cl_mutable_copy_buffer_rect_command_config_khr_TYPE} |
| 39 | + * {cl_mutable_copy_buffer_to_image_command_config_khr_TYPE} |
| 40 | + * {cl_mutable_copy_image_command_config_khr_TYPE} |
| 41 | + * {cl_mutable_copy_image_to_buffer_command_config_khr_TYPE} |
| 42 | + * {cl_mutable_fill_buffer_command_config_khr_TYPE} |
| 43 | + * {cl_mutable_fill_image_command_config_khr_TYPE} |
| 44 | + * {cl_mutable_svm_memcpy_command_config_khr_TYPE} |
| 45 | + * {cl_mutable_svm_memfill_command_config_khr_TYPE} |
| 46 | + |
| 47 | +=== New Enums |
| 48 | + |
| 49 | + * {cl_device_command_buffer_capabilities_khr_TYPE} |
| 50 | + ** {CL_COMMAND_BUFFER_CAPABILITY_MUTABLE_MEM_COMMANDS_KHR} |
| 51 | + * {cl_command_buffer_flags_khr_TYPE} |
| 52 | + ** {CL_MUTABLE_MEM_COMMANDS_ENABLE_KHR} |
| 53 | + * {cl_command_buffer_update_type_khr_TYPE} |
| 54 | + ** {CL_STRUCTURE_TYPE_MUTABLE_COPY_BUFFER_COMMAND_CONFIG_KHR} |
| 55 | + ** {CL_STRUCTURE_TYPE_MUTABLE_COPY_IMAGE_COMMAND_CONFIG_KHR} |
| 56 | + ** {CL_STRUCTURE_TYPE_MUTABLE_COPY_BUFFER_RECT_COMMAND_CONFIG_KHR} |
| 57 | + ** {CL_STRUCTURE_TYPE_MUTABLE_COPY_BUFFER_TO_IMAGE_COMMAND_CONFIG_KHR} |
| 58 | + ** {CL_STRUCTURE_TYPE_MUTABLE_COPY_BUFFER_TO_IMAGE_COMMAND_CONFIG_KHR} |
| 59 | + ** {CL_STRUCTURE_TYPE_MUTABLE_COPY_IMAGE_TO_BUFFER_COMMAND_CONFIG_KHR} |
| 60 | + ** {CL_STRUCTURE_TYPE_MUTABLE_FILL_BUFFER_COMMAND_CONFIG_KHR} |
| 61 | + ** {CL_STRUCTURE_TYPE_MUTABLE_FILL_IMAGE_COMMAND_CONFIG_KHR} |
| 62 | + ** {CL_STRUCTURE_TYPE_MUTABLE_SVM_MEMCPY_COMMAND_CONFIG_KHR} |
| 63 | + ** {CL_STRUCTURE_TYPE_MUTABLE_SVM_MEMFILL_COMMAND_CONFIG_KHR} |
| 64 | + |
| 65 | +=== Sample Code |
| 66 | + |
| 67 | +==== Sample Application Updating the Arguments to a Copy Buffer Command Between Command-buffer Submissions |
| 68 | + |
| 69 | +[source,cpp] |
| 70 | +---- |
| 71 | + #define CL_CHECK(ERROR) \ |
| 72 | + if (ERROR) { \ |
| 73 | + std::cerr << "OpenCL error: " << ERROR << "\n"; \ |
| 74 | + return ERROR; \ |
| 75 | + } |
| 76 | +
|
| 77 | + int main() { |
| 78 | + cl_platform_id platform; |
| 79 | + CL_CHECK(clGetPlatformIDs(1, &platform, nullptr)); |
| 80 | + cl_device_id device; |
| 81 | + CL_CHECK(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, &device, nullptr)); |
| 82 | +
|
| 83 | + cl_int error; |
| 84 | + cl_context context = |
| 85 | + clCreateContext(nullptr, 1, &device, nullptr, nullptr, &error); |
| 86 | + CL_CHECK(error); |
| 87 | +
|
| 88 | + cl_command_queue command_queue = |
| 89 | + clCreateCommandQueue(context, device, 0, &error); |
| 90 | + CL_CHECK(error); |
| 91 | +
|
| 92 | + size_t num_bytes = 128; |
| 93 | + cl_mem bufferA = |
| 94 | + clCreateBuffer(context, CL_MEM_READ_WRITE, num_bytes, nullptr, &error); |
| 95 | + CL_CHECK(error); |
| 96 | +
|
| 97 | + // Populate bufferA with data |
| 98 | +
|
| 99 | + cl_mem bufferB = |
| 100 | + clCreateBuffer(context, CL_MEM_READ_WRITE, num_bytes, nullptr, &error); |
| 101 | + CL_CHECK(error); |
| 102 | +
|
| 103 | + // Populate bufferB with data |
| 104 | +
|
| 105 | + cl_mem bufferC = |
| 106 | + clCreateBuffer(context, CL_MEM_READ_WRITE, num_bytes, nullptr, &error); |
| 107 | + CL_CHECK(eror); |
| 108 | +
|
| 109 | + cl_command_buffer_properties_khr properties[3] = { |
| 110 | + CL_COMMAND_BUFFER_FLAGS_KHR, |
| 111 | + CL_COMMAND_BUFFER_MUTABLE_KHR | CL_MUTABLE_MEM_COMMANDS_ENABLE_KHR, |
| 112 | + 0 |
| 113 | + }; |
| 114 | +
|
| 115 | + cl_command_buffer_khr command_buffer = |
| 116 | + clCreateCommandBufferKHR(1, &command_queue, properties, &error); |
| 117 | + CL_CHECK(error) |
| 118 | +
|
| 119 | + cl_mutable_command_khr copy_command_handle; |
| 120 | + CL_CHECK(clCommandCopyBufferKHR( |
| 121 | + command_buffer, |
| 122 | + command_queue, |
| 123 | + bufferA, |
| 124 | + bufferC, |
| 125 | + 0, |
| 126 | + 0, |
| 127 | + num_bytes, |
| 128 | + 0, |
| 129 | + nullptr, |
| 130 | + nullptr, |
| 131 | + ©_command_handle); |
| 132 | +
|
| 133 | + CL_CHECK(clFinalizeCommandBufferKHR(command_buffer)); |
| 134 | + CL_CHECK(clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0, nullptr, |
| 135 | + nullptr)); |
| 136 | +
|
| 137 | + cl_mutable_copy_buffer_command_config_khr buffer_copy_config = { |
| 138 | + copy_command_handle, // command |
| 139 | + bufferB, // src_buffer |
| 140 | + bufferC, // dst_buffer |
| 141 | + 0, // src_offset |
| 142 | + 0, // dst_offset |
| 143 | + num_bytes // size |
| 144 | + }; |
| 145 | +
|
| 146 | + cl_uint num_configs = 1; |
| 147 | + cl_update_config_type_khr config_types[1] = { |
| 148 | + CL_STRUCTURE_TYPE_MUTABLE_COPY_BUFFER_COMMAND_CONFIG_KHR |
| 149 | + }; |
| 150 | + void* configs[1] = {&buffer_copy_config}; |
| 151 | + CL_CHECK(clUpdateMutableCommandsKHR(command_buffer, num_configs, |
| 152 | + config_types, configs)); |
| 153 | + CL_CHECK(clEnqueueCommandBufferKHR(command_buffer, 0, nullptr, nullptr)); |
| 154 | + CL_CHECK(clFinish(command_queue)); |
| 155 | +
|
| 156 | + CL_CHECK(clReleaseCommandBufferKHR(command_buffer)); |
| 157 | + CL_CHECK(clReleaseCommandQueue(command_queue)); |
| 158 | + CL_CHECK(clReleaseContext(context)); |
| 159 | +
|
| 160 | + CL_CHECK(clReleaseMemObject(bufferA)); |
| 161 | + CL_CHECK(clReleaseMemObject(bufferB)); |
| 162 | + CL_CHECK(clReleaseMemObject(bufferC)); |
| 163 | +
|
| 164 | + return 0; |
| 165 | + } |
| 166 | +---- |
| 167 | + |
| 168 | +=== Conformance tests |
| 169 | + |
| 170 | +TODO - OpenCL-CTS Github issue with CTS plan once API design has been agreed. |
| 171 | + |
| 172 | +=== Modifications to Section 5.X - Command Buffers of OpenCL API specification |
| 173 | + |
| 174 | +==== Memory-Command Modifications |
| 175 | + |
| 176 | +The descriptions of command recording entry-points that operate on {cl_mem_TYPE} |
| 177 | +or SVM pointer arguments are modified as described in this section. These |
| 178 | +changes apply to all of {clCommandCopyBufferKHR}, {clCommandCopyBufferRectKHR}, |
| 179 | +{clCommandCopyBufferToImageKHR}, {clCommandCopyImageKHR}, |
| 180 | +{clCommandCopyImageToBufferKHR}, {clCommandFillBufferKHR}, |
| 181 | +{clCommandFillImageKHR}, {clCommandSVMMemcpyKHR}, and {clCommandSVMMemFillKHR}. |
| 182 | + |
| 183 | +===== Parameter Update |
| 184 | + |
| 185 | +Parameter description of _mutable_handle_ is changed to: |
| 186 | + |
| 187 | +_mutable_handle_ Returns a handle to the command that can be used to modify the |
| 188 | +command between enqueues of _command_buffer_. _mutable_handle_ may be `NULL`. The |
| 189 | +lifetime of this handle is tied to the parent command-buffer, such that freeing |
| 190 | +the command-buffer will also free this handle. |
| 191 | + |
| 192 | +===== Error Updates |
| 193 | + |
| 194 | +The error condition |
| 195 | + |
| 196 | +* {CL_INVALID_VALUE} if _mutable_handle_ is not `NULL`. |
| 197 | + |
| 198 | +Is replaced with |
| 199 | + |
| 200 | +* {CL_INVALID_VALUE} if _mutable_handle_ is not `NULL` and _command_buffer_ |
| 201 | + was not created with property {CL_MUTABLE_MEM_COMMANDS_ENABLE_KHR}. |
| 202 | + |
| 203 | + |
| 204 | +include::provisional_notice.asciidoc[] |
| 205 | + |
| 206 | +=== Version History |
| 207 | + |
| 208 | + * Revision 0.9.0, 2024-03-28 |
| 209 | + ** First assigned version (provisional). |
0 commit comments