Added an in-order queue variant for the semaphores_import_export_fd test (#2542)

Fixes #2213 according to mentioned discussion
This commit is contained in:
Marcin Hajder
2025-11-18 17:53:42 +01:00
committed by GitHub
parent 6b59cae6e9
commit ec546b80c5

View File

@@ -18,39 +18,10 @@
#include "harness/extensionHelpers.h" #include "harness/extensionHelpers.h"
#include "harness/errorHelpers.h" #include "harness/errorHelpers.h"
// Test it is possible to export a semaphore to a sync fd and import the same cl_int doTest(cl_device_id device, cl_context context, cl_command_queue queue)
// sync fd to a new semaphore
REGISTER_TEST_VERSION(external_semaphores_import_export_fd, Version(1, 2))
{ {
cl_int err = CL_SUCCESS; cl_int err = CL_SUCCESS;
if (!is_extension_available(device, "cl_khr_external_semaphore"))
{
log_info(
"cl_khr_external_semaphore is not supported on this platoform. "
"Skipping test.\n");
return TEST_SKIPPED_ITSELF;
}
if (!is_extension_available(device, "cl_khr_external_semaphore_sync_fd"))
{
log_info("cl_khr_external_semaphore_sync_fd is not supported on this "
"platoform. Skipping test.\n");
return TEST_SKIPPED_ITSELF;
}
cl_command_queue_properties device_props = 0;
err = clGetDeviceInfo(device, CL_DEVICE_QUEUE_PROPERTIES,
sizeof(device_props), &device_props, NULL);
test_error(err, "clGetDeviceInfo for CL_DEVICE_QUEUE_PROPERTIES failed");
if ((device_props & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) == 0)
{
log_info("Queue property CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE not "
"supported. Skipping test.\n");
return TEST_SKIPPED_ITSELF;
}
// Obtain pointers to semaphore's API // Obtain pointers to semaphore's API
GET_PFN(device, clCreateSemaphoreWithPropertiesKHR); GET_PFN(device, clCreateSemaphoreWithPropertiesKHR);
GET_PFN(device, clEnqueueSignalSemaphoresKHR); GET_PFN(device, clEnqueueSignalSemaphoresKHR);
@@ -58,11 +29,6 @@ REGISTER_TEST_VERSION(external_semaphores_import_export_fd, Version(1, 2))
GET_PFN(device, clGetSemaphoreHandleForTypeKHR); GET_PFN(device, clGetSemaphoreHandleForTypeKHR);
GET_PFN(device, clReleaseSemaphoreKHR); GET_PFN(device, clReleaseSemaphoreKHR);
// Create ooo queue
clCommandQueueWrapper test_queue = clCreateCommandQueue(
context, device, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &err);
test_error(err, "Could not create command queue");
// Create semaphore // Create semaphore
cl_semaphore_properties_khr sema_1_props[] = { cl_semaphore_properties_khr sema_1_props[] = {
static_cast<cl_semaphore_properties_khr>(CL_SEMAPHORE_TYPE_KHR), static_cast<cl_semaphore_properties_khr>(CL_SEMAPHORE_TYPE_KHR),
@@ -81,8 +47,8 @@ REGISTER_TEST_VERSION(external_semaphores_import_export_fd, Version(1, 2))
// Signal semaphore // Signal semaphore
clEventWrapper signal_event; clEventWrapper signal_event;
err = clEnqueueSignalSemaphoresKHR(test_queue, 1, &sema_1, nullptr, 0, err = clEnqueueSignalSemaphoresKHR(queue, 1, &sema_1, nullptr, 0, nullptr,
nullptr, &signal_event); &signal_event);
test_error(err, "Could not signal semaphore"); test_error(err, "Could not signal semaphore");
// Extract sync fd // Extract sync fd
@@ -109,12 +75,12 @@ REGISTER_TEST_VERSION(external_semaphores_import_export_fd, Version(1, 2))
// Wait semaphore // Wait semaphore
clEventWrapper wait_event; clEventWrapper wait_event;
err = clEnqueueWaitSemaphoresKHR(test_queue, 1, &sema_2, nullptr, 0, err = clEnqueueWaitSemaphoresKHR(queue, 1, &sema_2, nullptr, 0, nullptr,
nullptr, &wait_event); &wait_event);
test_error(err, "Could not wait semaphore"); test_error(err, "Could not wait semaphore");
// Finish // Finish
err = clFinish(test_queue); err = clFinish(queue);
test_error(err, "Could not finish queue"); test_error(err, "Could not finish queue");
// Check all events are completed // Check all events are completed
@@ -129,3 +95,48 @@ REGISTER_TEST_VERSION(external_semaphores_import_export_fd, Version(1, 2))
test_error(err, "Could not release semaphore"); test_error(err, "Could not release semaphore");
return TEST_PASS; return TEST_PASS;
} }
// Test it is possible to export a semaphore to a sync fd and import the same
// sync fd to a new semaphore
REGISTER_TEST_VERSION(external_semaphores_import_export_fd, Version(1, 2))
{
REQUIRE_EXTENSION("cl_khr_external_semaphore");
REQUIRE_EXTENSION("cl_khr_external_semaphore_sync_fd");
cl_int err = CL_SUCCESS;
cl_int total_status = TEST_PASS;
// test external semaphore sync fd with out-of-order queue
{
cl_command_queue_properties device_props = 0;
err = clGetDeviceInfo(device, CL_DEVICE_QUEUE_PROPERTIES,
sizeof(device_props), &device_props, NULL);
test_error(err,
"clGetDeviceInfo for CL_DEVICE_QUEUE_PROPERTIES failed");
if ((device_props & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) != 0)
{
// Create ooo queue
clCommandQueueWrapper test_queue = clCreateCommandQueue(
context, device, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &err);
test_error(err, "Could not create command queue");
cl_int status = doTest(device, context, test_queue);
if (status != TEST_PASS && status != TEST_SKIPPED_ITSELF)
{
total_status = TEST_FAIL;
}
}
}
// test external semaphore sync fd with in-order harness queue
{
cl_int status = doTest(device, context, queue);
if (status != TEST_PASS && status != TEST_SKIPPED_ITSELF)
{
total_status = TEST_FAIL;
}
}
return total_status;
}