Modernization of semaphores_negative_create_invalid_device related to creating sub-devices (#2307)

Due to the improvements developed during work on #2237 with @bashbaug
This commit is contained in:
Marcin Hajder
2025-04-01 17:47:59 +02:00
committed by GitHub
parent 88953edf6c
commit 4e00778b93

View File

@@ -251,38 +251,77 @@ struct CreateInvalidDevice : public SemaphoreTestBase
cl_int Run() override cl_int Run() override
{ {
// create sub devices if possible // create sub devices if possible
cl_uint maxComputeUnits = 0; size_t size = 0;
int err =
clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(maxComputeUnits), &maxComputeUnits, NULL);
test_error(err, "Unable to get maximal number of compute units");
cl_device_partition_property partitionProp[] = { // query multi-device context and perform objects comparability test
CL_DEVICE_PARTITION_EQUALLY, cl_int err = clGetDeviceInfo(device, CL_DEVICE_PARTITION_PROPERTIES, 0,
static_cast<cl_device_partition_property>(maxComputeUnits / 2), 0 nullptr, &size);
}; test_error_fail(err, "clGetDeviceInfo failed");
cl_uint deviceCount = 0; if ((size / sizeof(cl_device_partition_property)) == 0)
// how many sub-devices can we create?
err =
clCreateSubDevices(device, partitionProp, 0, nullptr, &deviceCount);
if (err != CL_SUCCESS)
{ {
log_info("Can't partition device, test not supported\n"); log_info("Can't partition device, test not supported\n");
return TEST_SKIPPED_ITSELF; return TEST_SKIPPED_ITSELF;
} }
if (deviceCount < 2) std::vector<cl_device_partition_property> supported_props(
test_error_ret( size / sizeof(cl_device_partition_property), 0);
CL_INVALID_VALUE, err = clGetDeviceInfo(device, CL_DEVICE_PARTITION_PROPERTIES,
"Multi context test for CL_INVALID_PROPERTY not supported", supported_props.size()
TEST_SKIPPED_ITSELF); * sizeof(cl_device_partition_property),
supported_props.data(), nullptr);
test_error_fail(err, "clGetDeviceInfo failed");
// get the list of subDevices if (supported_props.front() == 0)
SubDevicesScopeGuarded scope_guard(deviceCount); {
err = clCreateSubDevices(device, partitionProp, deviceCount, log_info("Can't partition device, test not supported\n");
scope_guard.sub_devices.data(), &deviceCount); return TEST_SKIPPED_ITSELF;
if (err != CL_SUCCESS) }
cl_uint maxComputeUnits = 0;
err =
clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(maxComputeUnits), &maxComputeUnits, nullptr);
test_error_ret(err, "Unable to get maximal number of compute units",
TEST_FAIL);
std::vector<std::array<cl_device_partition_property, 5>>
partition_props = {
{ CL_DEVICE_PARTITION_EQUALLY, (cl_int)maxComputeUnits / 2, 0,
0, 0 },
{ CL_DEVICE_PARTITION_BY_COUNTS, 1, (cl_int)maxComputeUnits - 1,
CL_DEVICE_PARTITION_BY_COUNTS_LIST_END, 0 },
{ CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN,
CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE, 0, 0, 0 }
};
std::unique_ptr<SubDevicesScopeGuarded> scope_guard;
cl_uint num_devices = 0;
for (auto &sup_prop : supported_props)
{
for (auto &prop : partition_props)
{
if (sup_prop == prop[0])
{
// how many sub-devices can we create?
err = clCreateSubDevices(device, prop.data(), 0, nullptr,
&num_devices);
test_error_fail(err, "clCreateSubDevices failed");
if (num_devices < 2) continue;
// get the list of subDevices
scope_guard.reset(new SubDevicesScopeGuarded(num_devices));
err = clCreateSubDevices(device, prop.data(), num_devices,
scope_guard->sub_devices.data(),
&num_devices);
test_error_fail(err, "clCreateSubDevices failed");
break;
}
}
if (scope_guard.get() != nullptr) break;
}
if (scope_guard.get() == nullptr)
{ {
log_info("Can't partition device, test not supported\n"); log_info("Can't partition device, test not supported\n");
return TEST_SKIPPED_ITSELF; return TEST_SKIPPED_ITSELF;
@@ -297,7 +336,7 @@ struct CreateInvalidDevice : public SemaphoreTestBase
(cl_semaphore_properties_khr) (cl_semaphore_properties_khr)
CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR, CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR,
(cl_semaphore_properties_khr)device, (cl_semaphore_properties_khr)device,
(cl_semaphore_properties_khr)scope_guard.sub_devices.front(), (cl_semaphore_properties_khr)scope_guard->sub_devices.front(),
(cl_semaphore_properties_khr) (cl_semaphore_properties_khr)
CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR, CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR,
0 0
@@ -317,7 +356,7 @@ struct CreateInvalidDevice : public SemaphoreTestBase
{ {
/* Create new context with sub-device */ /* Create new context with sub-device */
clContextWrapper new_context = clCreateContext( clContextWrapper new_context = clCreateContext(
NULL, (cl_uint)1, scope_guard.sub_devices.data(), nullptr, NULL, (cl_uint)1, scope_guard->sub_devices.data(), nullptr,
nullptr, &err); nullptr, &err);
test_error_ret(err, "Unable to create testing context", CL_SUCCESS); test_error_ret(err, "Unable to create testing context", CL_SUCCESS);