Modernization of semaphores_negative_create_multi_device_property related to creating sub-devices (#2306)

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

View File

@@ -17,6 +17,7 @@
#include "semaphore_base.h" #include "semaphore_base.h"
#include "harness/errorHelpers.h" #include "harness/errorHelpers.h"
#include <array>
#include <chrono> #include <chrono>
#include <system_error> #include <system_error>
#include <thread> #include <thread>
@@ -137,38 +138,77 @@ struct CreateInvalidMultiDeviceProperty : public SemaphoreTestBase
cl_int Run() override cl_int Run() override
{ {
// partition device and create new context if possible // partition device and create new context if possible
cl_uint maxComputeUnits = 0; size_t size = 0;
cl_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;
@@ -176,9 +216,9 @@ struct CreateInvalidMultiDeviceProperty : public SemaphoreTestBase
/* Create a multi device context */ /* Create a multi device context */
clContextWrapper multi_device_context = clCreateContext( clContextWrapper multi_device_context = clCreateContext(
NULL, (cl_uint)deviceCount, scope_guard.sub_devices.data(), nullptr, NULL, (cl_uint)num_devices, scope_guard->sub_devices.data(),
nullptr, &err); nullptr, nullptr, &err);
test_error_ret(err, "Unable to create testing context", CL_SUCCESS); test_error_fail(err, "Unable to create testing context");
cl_semaphore_properties_khr sema_props[] = { cl_semaphore_properties_khr sema_props[] = {
(cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_KHR, (cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_KHR,