Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update clUpdateMutableCommandsKHR to match new API #501

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/source/cl/extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,20 @@ before the extension can be turned on by default in the oneAPI Construction Kit:
* Event profiling is not implemented (see CA-3322).

.. _cl_khr_command_buffer:
https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#cl_khr_command_buffer
https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_API.html#cl_khr_command_buffer

Command Buffers: Mutable Dispatch - ``cl_khr_command_buffer_mutable_dispatch``
------------------------------------------------------------------------------

oneAPI Construction Kit implements version 0.9.0 of the provisional
oneAPI Construction Kit implements version 0.9.2 of the provisional
`cl_khr_command_buffer_mutable_dispatch`_ extension.

`cl_khr_command_buffer_mutable_dispatch`_ builds upon `cl_khr_command_buffer`_
to allow users to modify kernel execution commands between enqueues of a
command-buffer.

.. _cl_khr_command_buffer_mutable_dispatch:
https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#cl_khr_command_buffer_mutable_dispatch
https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#cl_khr_command_buffer_mutable_dispatch

Extended Async Copies - ``cl_khr_extended_async_copies``
---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set(CMAKE_CXX_EXTENSIONS ON)
FetchContent_Declare(
OpenCLHeaders
GIT_REPOSITORY https://github.com/KhronosGroup/OpenCL-Headers.git
GIT_TAG v2024.05.08
GIT_TAG 7258b9e0137474c988142fd35777b59dcdff167e
)
FetchContent_MakeAvailable(OpenCLHeaders)

Expand Down
12 changes: 6 additions & 6 deletions source/cl/examples/MutableDispatchKHR/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ int main(const int argc, const char **argv) {
&output_buffer};
const cl_mutable_dispatch_arg_khr args[] = {arg_0, arg_1, arg_2};
const cl_mutable_dispatch_config_khr dispatch_config{
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
nullptr,
command_handle,
3 /* num_args */,
0 /* num_svm_arg */,
Expand All @@ -230,12 +228,14 @@ int main(const int argc, const char **argv) {
nullptr /* global_work_offset */,
nullptr /* global_work_size */,
nullptr /* local_work_size */};
const cl_mutable_base_config_khr mutable_config{
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1,
&dispatch_config};

// Update the command buffer with the mutable configuration
error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
const cl_uint num_configs = 1;
const cl_command_buffer_update_type_khr config_types[1] = {
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR};
const void *configs[1] = {&dispatch_config};
error = clUpdateMutableCommandsKHR(command_buffer, num_configs,
config_types, configs);
CL_CHECK(error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,13 @@ struct _cl_command_buffer_khr final : public cl::base<_cl_command_buffer_khr> {

/// @brief Modify commands in command-buffer
///
/// @param[in] mutable_config New configuration for one or more commands
/// @param[in] mutable_configs List of new configuration for one or more
/// commands. It is only valid to pass pointers to
/// cl_mutable_dispatch_config_khr structs in this list.
///
/// @return CL_SUCCESS or appropriate OpenCL error code.
cl_int updateCommandBuffer(const cl_mutable_base_config_khr &mutable_config);
cl_int updateCommandBuffer(
const cargo::array_view<const void *> &mutable_configs);

/// @brief Verifies whether a queue is compatible with the command-buffer.
///
Expand Down
35 changes: 18 additions & 17 deletions source/cl/source/extension/source/khr_command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,19 +1072,17 @@ cargo::expected<mux_descriptor_info_s, cl_int> createArgumentDescriptor(
} // anonymous namespace

[[nodiscard]] cl_int _cl_command_buffer_khr::updateCommandBuffer(
const cl_mutable_base_config_khr &mutable_config) {
const cargo::array_view<const void *> &mutable_configs) {
const std::lock_guard<std::mutex> guard(mutex);
const cl_device_id device = command_queue->device;

const cargo::array_view<const cl_mutable_dispatch_config_khr>
mutable_dispatch_configs(mutable_config.mutable_dispatch_list,
mutable_config.num_mutable_dispatch);

// Verify struct configures kernel arguments and return error if malformed
for (const auto &config : mutable_dispatch_configs) {
OCL_CHECK(config.type != CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
return CL_INVALID_VALUE);
for (const auto &mutable_config : mutable_configs) {
auto config_ptr =
static_cast<const cl_mutable_dispatch_config_khr *>(mutable_config);

OCL_CHECK(config_ptr == nullptr, return CL_INVALID_VALUE);
const cl_mutable_dispatch_config_khr &config = *config_ptr;
OCL_CHECK(!config.command, return CL_INVALID_MUTABLE_COMMAND_KHR);
OCL_CHECK(config.command->command_buffer != this,
return CL_INVALID_MUTABLE_COMMAND_KHR);
Expand All @@ -1098,9 +1096,12 @@ cargo::expected<mux_descriptor_info_s, cl_int> createArgumentDescriptor(
return CL_INVALID_OPERATION);
}

for (auto config : mutable_dispatch_configs) {
for (const auto &mutable_config : mutable_configs) {
auto config =
static_cast<const cl_mutable_dispatch_config_khr *>(mutable_config);

unsigned update_index = 0;
const unsigned num_args = config.num_args + config.num_svm_args;
const unsigned num_args = config->num_args + config->num_svm_args;
UpdateInfo update_info;
if (update_info.descriptors.alloc(num_args)) {
return CL_OUT_OF_HOST_MEMORY;
Expand All @@ -1110,16 +1111,16 @@ cargo::expected<mux_descriptor_info_s, cl_int> createArgumentDescriptor(
return CL_OUT_OF_HOST_MEMORY;
}

if (update_info.pointers.alloc(config.num_svm_args)) {
if (update_info.pointers.alloc(config->num_svm_args)) {
return CL_OUT_OF_HOST_MEMORY;
}

const auto mutable_command = config.command;
const auto mutable_command = config->command;
update_info.id = mutable_command->id;
cargo::array_view<const cl_mutable_dispatch_arg_khr> args(config.arg_list,
config.num_args);
cargo::array_view<const cl_mutable_dispatch_arg_khr> args(config->arg_list,
config->num_args);

for (unsigned i = 0; i < config.num_args; ++i) {
for (unsigned i = 0; i < config->num_args; ++i) {
auto arg = args[i];
update_info.indices[update_index] = arg.arg_index;
auto descriptor =
Expand All @@ -1135,9 +1136,9 @@ cargo::expected<mux_descriptor_info_s, cl_int> createArgumentDescriptor(

#ifdef OCL_EXTENSION_cl_intel_unified_shared_memory
cargo::array_view<const cl_mutable_dispatch_arg_khr> svm_args(
config.arg_svm_list, config.num_svm_args);
config->arg_svm_list, config->num_svm_args);

for (unsigned i = 0; i < config.num_svm_args; ++i) {
for (unsigned i = 0; i < config->num_svm_args; ++i) {
// Unpack the argument.
const auto arg = svm_args[i];
const auto arg_index = arg.arg_index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension::khr_command_buffer_mutable_dispatch::
#else
usage_category::DISABLED
#endif
CA_CL_EXT_VERSION(0, 1, 0)) {
CA_CL_EXT_VERSION(0, 9, 2)) {
}

void *extension::khr_command_buffer_mutable_dispatch::
Expand Down Expand Up @@ -82,9 +82,10 @@ cl_int extension::khr_command_buffer_mutable_dispatch::GetDeviceInfo(
}

#ifdef OCL_EXTENSION_cl_khr_command_buffer_mutable_dispatch
CL_API_ENTRY cl_int CL_API_CALL
clUpdateMutableCommandsKHR(cl_command_buffer_khr command_buffer,
const cl_mutable_base_config_khr *mutable_config) {
CL_API_ENTRY cl_int CL_API_CALL clUpdateMutableCommandsKHR(
cl_command_buffer_khr command_buffer, cl_uint num_configs,
const cl_command_buffer_update_type_khr *config_types,
const void **configs) {
const tracer::TraceGuard<tracer::OpenCL> guard("clUpdateMutableCommandsKHR");
OCL_CHECK(!command_buffer, return CL_INVALID_COMMAND_BUFFER_KHR);
OCL_CHECK(!command_buffer->is_finalized, return CL_INVALID_OPERATION);
Expand All @@ -102,20 +103,20 @@ clUpdateMutableCommandsKHR(cl_command_buffer_khr command_buffer,
return CL_INVALID_OPERATION;
}

OCL_CHECK(!mutable_config, return CL_INVALID_VALUE);
OCL_CHECK(mutable_config->type != CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR,
return CL_INVALID_VALUE);
OCL_CHECK(config_types && 0 == num_configs, return CL_INVALID_VALUE);
OCL_CHECK(!config_types && num_configs, return CL_INVALID_VALUE);

// Values for next would be defined by implementation of mutable mem commands
// layered extension. Later checks assume next is NULL and so the
// mutable_dispatch_list field must be set.
OCL_CHECK(mutable_config->next, return CL_INVALID_VALUE);
OCL_CHECK(configs && 0 == num_configs, return CL_INVALID_VALUE);
OCL_CHECK(!configs && num_configs, return CL_INVALID_VALUE);

OCL_CHECK(!mutable_config->mutable_dispatch_list ||
!mutable_config->num_mutable_dispatch,
return CL_INVALID_VALUE);
for (size_t i = 0; i < num_configs; i++) {
if (config_types[i] != CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR) {
return CL_INVALID_VALUE;
}
}

return command_buffer->updateCommandBuffer(*mutable_config);
const cargo::array_view<const void *> config_array(configs, num_configs);
return command_buffer->updateCommandBuffer(config_array);
}

CL_API_ENTRY cl_int CL_API_CALL clGetMutableCommandInfoKHR(
Expand Down
Loading
Loading