Skip to content

Commit

Permalink
Fix bug in mutable_command_full_dispatch (#2082)
Browse files Browse the repository at this point in the history
This test did not pass the `-cl-std=` flag when building the program. As
a result, for an OpenCL 3.0 device, the program will be "compiled using
the highest OpenCL C 1.x language version supported" by the device.
However this will force uniform work-group sizes which leads to a
`CL_INVALID_WORK_GROUP_SIZE` error.

To fix this, use the `create_single_kernel_helper()` helper function
which will automatically get the device version and pass that to
`-cl-std=` when building the program.

---------

Signed-off-by: Gorazd Sumkovski <[email protected]>
  • Loading branch information
gorazd-sumkovski-arm authored Oct 22, 2024
1 parent 1a17853 commit 6a2c0b1
Showing 1 changed file with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,18 @@ struct MutableCommandFullDispatch : InfoMutableCommandBufferTest

if ((available_caps & CL_MUTABLE_DISPATCH_EXEC_INFO_KHR) == 0)
{
error = create_single_kernel_helper_create_program(
context, &program, 1, &kernel_str_no_svm);
error = create_single_kernel_helper(context, &program, &kernel, 1,
&kernel_str_no_svm,
"full_dispatch");
}
else
{
error = create_single_kernel_helper_create_program(
context, &program, 1, &kernel_str_svm);
error =
create_single_kernel_helper(context, &program, &kernel, 1,
&kernel_str_svm, "full_dispatch");
}
test_error(error, "Failed to create program with source");

error = clBuildProgram(program, 1, &device, nullptr, nullptr, nullptr);
test_error(error, "Failed to build program");

kernel = clCreateKernel(program, "full_dispatch", &error);
test_error(error, "Failed to create copy kernel");

return CL_SUCCESS;
}

Expand Down Expand Up @@ -303,6 +299,11 @@ struct MutableCommandFullDispatch : InfoMutableCommandBufferTest
};

size_t work_offset = 0;
/* Round the global work size up to nearest multiple of the local work
* size to ensure work group uniformity. */
num_elements =
((num_elements + group_size - 1) / group_size) * group_size;

cl_int error = clCommandNDRangeKernelKHR(
command_buffer, nullptr, props, kernel, 1, &work_offset,
&num_elements, &group_size, 0, nullptr, nullptr, &command);
Expand Down Expand Up @@ -384,18 +385,23 @@ struct MutableCommandFullDispatch : InfoMutableCommandBufferTest
dispatch_config.global_work_offset = &work_offset;
}

if ((available_caps & CL_MUTABLE_DISPATCH_GLOBAL_SIZE_KHR) != 0)
{
num_elements /= 2;
dispatch_config.global_work_size = &num_elements;
}

if ((available_caps & CL_MUTABLE_DISPATCH_LOCAL_SIZE_KHR) != 0)
{
group_size /= 2;
dispatch_config.local_work_size = &group_size;
}

if ((available_caps & CL_MUTABLE_DISPATCH_GLOBAL_SIZE_KHR) != 0)
{
num_elements /= 2;
/* Round the global work size up to nearest multiple of the local
* work size to ensure work group uniformity. */
num_elements =
((num_elements + group_size - 1) / group_size) * group_size;

dispatch_config.global_work_size = &num_elements;
}

cl_uint num_configs = 1;
cl_command_buffer_update_type_khr config_types[1] = {
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR
Expand Down

0 comments on commit 6a2c0b1

Please sign in to comment.