Skip to content

Commit

Permalink
Remove reinterpret_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
EwanC committed Sep 27, 2024
1 parent 84be0bf commit abac7ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +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(
cargo::array_view<const cl_mutable_dispatch_config_khr *>
&mutable_configs);
const cargo::array_view<const void *> &mutable_configs);

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

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

// Verify struct configures kernel arguments and return error if malformed
for (const auto &config_ptr : mutable_dispatch_configs) {
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);
Expand All @@ -1094,7 +1096,10 @@ 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;
UpdateInfo update_info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,8 @@ CL_API_ENTRY cl_int CL_API_CALL clUpdateMutableCommandsKHR(
}
}

const cl_mutable_dispatch_config_khr **casted_configs =
reinterpret_cast<const cl_mutable_dispatch_config_khr **>(configs);
cargo::array_view<const cl_mutable_dispatch_config_khr *>
mutable_dispatch_configs(casted_configs, num_configs);

return command_buffer->updateCommandBuffer(mutable_dispatch_configs);
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

0 comments on commit abac7ad

Please sign in to comment.