-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1072,19 +1072,15 @@ 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) { | ||
cargo::array_view<const cl_mutable_dispatch_config_khr *> | ||
&mutable_dispatch_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 config_ptr : mutable_dispatch_configs) { | ||
OCL_CHECK(config_ptr == nullptr, return CL_INVALID_VALUE); | ||
const cl_mutable_dispatch_config_khr config = *config_ptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made this |
||
OCL_CHECK(!config.command, return CL_INVALID_MUTABLE_COMMAND_KHR); | ||
OCL_CHECK(config.command->command_buffer != this, | ||
return CL_INVALID_MUTABLE_COMMAND_KHR); | ||
|
@@ -1100,7 +1096,7 @@ cargo::expected<mux_descriptor_info_s, cl_int> createArgumentDescriptor( | |
|
||
for (auto config : mutable_dispatch_configs) { | ||
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; | ||
|
@@ -1110,16 +1106,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 = | ||
|
@@ -1135,9 +1131,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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:: | ||
|
@@ -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); | ||
|
@@ -102,20 +103,24 @@ 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; | ||
} | ||
} | ||
|
||
const cl_mutable_dispatch_config_khr **casted_configs = | ||
reinterpret_cast<const cl_mutable_dispatch_config_khr **>(configs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this (when dereferencing the result) is well-defined in standard C++, and I do not recall whether current compilers optimize on the assumption that we do not do this. Do you know? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we're looking at the same thing, do you have a reference to where this is UB? I'm looking at https://en.cppreference.com/w/cpp/language/reinterpret_cast and guessing it's point 5) then "Type Accessibility" doesn't seem to cover this case as well defined. I'm not sure how type based alias analysis works with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's the type accessibility thing. There is no need to |
||
cargo::array_view<const cl_mutable_dispatch_config_khr *> | ||
mutable_dispatch_configs(casted_configs, num_configs); | ||
|
||
return command_buffer->updateCommandBuffer(*mutable_config); | ||
return command_buffer->updateCommandBuffer(mutable_dispatch_configs); | ||
} | ||
|
||
CL_API_ENTRY cl_int CL_API_CALL clGetMutableCommandInfoKHR( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the
clang-tidy
reports on the earlier version for variables that could beconst
, I am surprised that none are raised here. Could you check whether this really needs to be non-const
, or whether the source file was skipped in the check?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy
was being run (I manually run thetidy-clMutableDispathcKHR
target to check) but the tool didn't seem to mandateconst
on these, but I went through and addedconst
anyway