Skip to content

Commit

Permalink
Remove #ifdef and check runtime version
Browse files Browse the repository at this point in the history
  • Loading branch information
EwanC committed Sep 5, 2024
1 parent a42ff55 commit ec8193c
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 488 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,32 +164,6 @@ struct MutableDispatchGlobalArguments : public MutableDispatchArgumentsTest

cl_mutable_dispatch_arg_khr arg{ 1, sizeof(dst_buf_1), &dst_buf_1 };

#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION \
< CL_MAKE_VERSION(0, 9, 2)
cl_mutable_dispatch_config_khr dispatch_config{
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
nullptr,
command,
1 /* num_args */,
0 /* num_svm_arg */,
0 /* num_exec_infos */,
0 /* work_dim - 0 means no change to dimensions */,
&arg /* arg_list */,
nullptr /* arg_svm_list - nullptr means no change*/,
nullptr /* exec_info_list */,
nullptr /* global_work_offset */,
nullptr /* global_work_size */,
nullptr /* local_work_size */
};

cl_mutable_base_config_khr mutable_config{
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1,
&dispatch_config
};

error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
test_error(error, "clUpdateMutableCommandsKHR failed");
#else
cl_mutable_dispatch_config_khr dispatch_config{
command,
1 /* num_args */,
Expand All @@ -209,11 +183,9 @@ struct MutableDispatchGlobalArguments : public MutableDispatchArgumentsTest
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR
};
const void *configs[1] = { &dispatch_config };

error = clUpdateMutableCommandsKHR(command_buffer, num_configs,
config_types, configs);
test_error(error, "clUpdateMutableCommandsKHR failed");
#endif // CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION

error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
Expand Down Expand Up @@ -315,17 +287,10 @@ struct MutableDispatchLocalArguments : public MutableDispatchArgumentsTest
nullptr, nullptr);
test_error(error, "clEnqueueCommandBufferKHR failed");

error = clFinish(queue);
test_error(error, "clFinish failed.");

cl_mutable_dispatch_arg_khr arg_1{ 1, sizeof(cl_mem), nullptr };
cl_mutable_dispatch_arg_khr args[] = { arg_1 };

#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION \
< CL_MAKE_VERSION(0, 9, 2)
cl_mutable_dispatch_config_khr dispatch_config{
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
nullptr,
command,
1 /* num_args */,
0 /* num_svm_arg */,
Expand All @@ -338,38 +303,18 @@ struct MutableDispatchLocalArguments : public MutableDispatchArgumentsTest
nullptr /* global_work_size */,
nullptr /* local_work_size */
};
cl_mutable_base_config_khr mutable_config{
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1,
&dispatch_config
};

error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
test_error(error, "clUpdateMutableCommandsKHR failed");
#else
cl_mutable_dispatch_config_khr dispatch_config{
command,
1 /* num_args */,
0 /* num_svm_arg */,
0 /* num_exec_infos */,
0 /* work_dim - 0 means no change to dimensions */,
args /* arg_list */,
nullptr /* arg_svm_list - nullptr means no change*/,
nullptr /* exec_info_list */,
nullptr /* global_work_offset */,
nullptr /* global_work_size */,
nullptr /* local_work_size */
};
error = clFinish(queue);
test_error(error, "clFinish failed.");

cl_uint num_configs = 1;
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);
test_error(error, "clUpdateMutableCommandsKHR failed");
#endif // CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION

error =
clEnqueueReadBuffer(queue, streams[1], CL_TRUE, 0, size_to_allocate,
Expand Down Expand Up @@ -475,18 +420,11 @@ struct MutableDispatchPODArguments : public MutableDispatchArgumentsTest
nullptr, nullptr);
test_error(error, "clEnqueueCommandBufferKHR failed");

error = clFinish(queue);
test_error(error, "clFinish failed.");

int_arg = 20;
cl_mutable_dispatch_arg_khr arg_1{ 1, sizeof(cl_int), &int_arg };
cl_mutable_dispatch_arg_khr args[] = { arg_1 };

#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION \
< CL_MAKE_VERSION(0, 9, 2)
cl_mutable_dispatch_config_khr dispatch_config{
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
nullptr,
command,
1 /* num_args */,
0 /* num_svm_arg */,
Expand All @@ -499,38 +437,18 @@ struct MutableDispatchPODArguments : public MutableDispatchArgumentsTest
nullptr /* global_work_size */,
nullptr /* local_work_size */
};
cl_mutable_base_config_khr mutable_config{
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1,
&dispatch_config
};

error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
test_error(error, "clUpdateMutableCommandsKHR failed");
#else
cl_mutable_dispatch_config_khr dispatch_config{
command,
1 /* num_args */,
0 /* num_svm_arg */,
0 /* num_exec_infos */,
0 /* work_dim - 0 means no change to dimensions */,
args /* arg_list */,
nullptr /* arg_svm_list - nullptr means no change*/,
nullptr /* exec_info_list */,
nullptr /* global_work_offset */,
nullptr /* global_work_size */,
nullptr /* local_work_size */
};
error = clFinish(queue);
test_error(error, "clFinish failed.");

cl_uint num_configs = 1;
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);
test_error(error, "clUpdateMutableCommandsKHR failed");
#endif // CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION

error = clEnqueueReadBuffer(queue, stream, CL_TRUE, 0, size_to_allocate,
result_data.data(), 0, nullptr, nullptr);
Expand Down Expand Up @@ -652,33 +570,6 @@ struct MutableDispatchNullArguments : public MutableDispatchArgumentsTest

// Modify and execute the command buffer
cl_mutable_dispatch_arg_khr arg{ 0, sizeof(cl_mem), nullptr };

#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION \
< CL_MAKE_VERSION(0, 9, 2)
cl_mutable_dispatch_config_khr dispatch_config{
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
nullptr,
command,
1 /* num_args */,
0 /* num_svm_arg */,
0 /* num_exec_infos */,
0 /* work_dim - 0 means no change to dimensions */,
&arg /* arg_list */,
nullptr /* arg_svm_list - nullptr means no change*/,
nullptr /* exec_info_list */,
nullptr /* global_work_offset */,
nullptr /* global_work_size */,
nullptr /* local_work_size */
};

cl_mutable_base_config_khr mutable_config{
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1,
&dispatch_config
};

error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
test_error(error, "clUpdateMutableCommandsKHR failed");
#else
cl_mutable_dispatch_config_khr dispatch_config{
command,
1 /* num_args */,
Expand All @@ -698,11 +589,9 @@ struct MutableDispatchNullArguments : public MutableDispatchArgumentsTest
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR
};
const void *configs[1] = { &dispatch_config };

error = clUpdateMutableCommandsKHR(command_buffer, num_configs,
config_types, configs);
test_error(error, "clUpdateMutableCommandsKHR failed");
#endif // CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION

error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
Expand Down Expand Up @@ -881,25 +770,6 @@ struct MutableDispatchSVMArguments : public MutableDispatchArgumentsTest
exec_info.param_value_size = sizeof(new_buffer);
exec_info.param_value = &new_buffer;

#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION \
< CL_MAKE_VERSION(0, 9, 2)

cl_mutable_dispatch_config_khr dispatch_config{};
dispatch_config.type = CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR;
dispatch_config.command = command;
dispatch_config.num_svm_args = 1;
dispatch_config.arg_svm_list = &arg_svm;
dispatch_config.num_exec_infos = 1;
dispatch_config.exec_info_list = &exec_info;

cl_mutable_base_config_khr mutable_config{};
mutable_config.type = CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR;
mutable_config.num_mutable_dispatch = 1;
mutable_config.mutable_dispatch_list = &dispatch_config;

error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
test_error(error, "clUpdateMutableCommandsKHR failed");
#else
cl_mutable_dispatch_config_khr dispatch_config{};
dispatch_config.num_svm_args = 1;
dispatch_config.arg_svm_list = &arg_svm;
Expand All @@ -911,11 +781,9 @@ struct MutableDispatchSVMArguments : public MutableDispatchArgumentsTest
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR
};
const void *configs[1] = { &dispatch_config };

error = clUpdateMutableCommandsKHR(command_buffer, num_configs,
config_types, configs);
test_error(error, "clUpdateMutableCommandsKHR failed");
#endif // CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION

error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ struct BasicMutableCommandBufferTest : BasicCommandBufferTest
"cl_khr_command_buffer_mutable_dispatch")
== true;

if (extension_avaliable) {
// API breaking changes occur at revision 0.9.2, check implementation
// matches tested API
Version device_version = get_device_cl_version(device);
if ((device_version >= Version(3, 0))
|| is_extension_available(device, "cl_khr_extended_versioning")) {

cl_version extension_version =
get_extension_version(device, "cl_khr_command_buffer_mutable_dispatch");

if (extension_version < CL_MAKE_VERSION(0, 9, 2)) {
extension_avaliable = false;
}
}
}

cl_mutable_dispatch_fields_khr mutable_capabilities;

bool mutable_support =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct MutableCommandFullDispatch : InfoMutableCommandBufferTest
available_caps &= ~CL_MUTABLE_DISPATCH_EXEC_INFO_KHR;

// require at least one mutable capabillity
return (available_caps == 0) && InfoMutableCommandBufferTest::Skip();
return (available_caps == 0) || InfoMutableCommandBufferTest::Skip();
}

// setup kernel program specific for command buffer with full mutable
Expand Down Expand Up @@ -334,12 +334,8 @@ struct MutableCommandFullDispatch : InfoMutableCommandBufferTest
test_error(error, "clEnqueueFillBuffer failed");
}

#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION \
< CL_MAKE_VERSION(0, 9, 2)
// Modify and execute the command buffer
cl_mutable_dispatch_config_khr dispatch_config{
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
nullptr,
command,
0 /* num_args */,
0 /* num_svm_arg */,
Expand All @@ -352,22 +348,6 @@ struct MutableCommandFullDispatch : InfoMutableCommandBufferTest
nullptr /* global_work_size */,
nullptr /* local_work_size */
};
#else
// Modify and execute the command buffer
cl_mutable_dispatch_config_khr dispatch_config{
command,
0 /* num_args */,
0 /* num_svm_arg */,
0 /* num_exec_infos */,
0 /* work_dim - 0 means no change to dimensions */,
nullptr /* arg_list */,
nullptr /* arg_svm_list - nullptr means no change*/,
nullptr /* exec_info_list */,
nullptr /* global_work_offset */,
nullptr /* global_work_size */,
nullptr /* local_work_size */
};
#endif // CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION

cl_mutable_dispatch_arg_khr arg0{ 0 };
cl_mutable_dispatch_arg_khr arg1{ 0 };
Expand Down Expand Up @@ -413,26 +393,14 @@ struct MutableCommandFullDispatch : InfoMutableCommandBufferTest
dispatch_config.local_work_size = &group_size;
}

#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION \
< CL_MAKE_VERSION(0, 9, 2)
cl_mutable_base_config_khr mutable_config{
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1,
&dispatch_config
};

error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
test_error(error, "clUpdateMutableCommandsKHR failed");
#else
cl_uint num_configs = 1;
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);
test_error(error, "clUpdateMutableCommandsKHR failed");
#endif // CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION

error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,6 @@ struct MutableDispatchGlobalOffset : InfoMutableCommandBufferTest
error = clFinish(queue);
test_error(error, "clFinish failed.");

#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION \
< CL_MAKE_VERSION(0, 9, 2)
cl_mutable_dispatch_config_khr dispatch_config{
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
nullptr,
command,
0 /* num_args */,
0 /* num_svm_arg */,
0 /* num_exec_infos */,
0 /* work_dim - 0 means no change to dimensions */,
nullptr /* arg_list */,
nullptr /* arg_svm_list - nullptr means no change*/,
nullptr /* exec_info_list */,
&update_global_offset /* global_work_offset */,
nullptr /* global_work_size */,
nullptr /* local_work_size */
};
cl_mutable_base_config_khr mutable_config{
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1,
&dispatch_config
};

error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
test_error(error, "clUpdateMutableCommandsKHR failed");
#else
cl_mutable_dispatch_config_khr dispatch_config{
command,
0 /* num_args */,
Expand All @@ -131,12 +106,9 @@ struct MutableDispatchGlobalOffset : InfoMutableCommandBufferTest
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR
};
const void *configs[1] = { &dispatch_config };

error = clUpdateMutableCommandsKHR(command_buffer, num_configs,
config_types, configs);
test_error(error, "clUpdateMutableCommandsKHR failed");
#endif // CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION


error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
Expand Down
Loading

0 comments on commit ec8193c

Please sign in to comment.