Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new query for cl_khr_semaphore test to verify device handle list #1942

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 50 additions & 10 deletions test_conformance/extensions/cl_khr_semaphore/test_semaphores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <system_error>
#include <thread>
#include <chrono>
#include <vector>

#define FLUSH_DELAY_S 5

Expand Down Expand Up @@ -115,7 +116,7 @@ static int semaphore_cross_queue_helper(cl_device_id deviceID,
&wait_event);
test_error(err, "Could not wait semaphore");

// Finish queue_1 and queue_2
// Finish queue_1 and queue_2
err = clFinish(queue_1);
test_error(err, "Could not finish queue");

Expand All @@ -133,7 +134,7 @@ static int semaphore_cross_queue_helper(cl_device_id deviceID,
return TEST_PASS;
}

// Confirm that a signal followed by a wait will complete successfully
// Confirm that a signal followed by a wait will complete successfully
int test_semaphores_simple_1(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
Expand Down Expand Up @@ -586,25 +587,59 @@ int test_semaphores_multi_wait(cl_device_id deviceID, cl_context context,
int test_semaphores_queries(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
cl_int err;
cl_int err = CL_SUCCESS;

if (!is_extension_available(deviceID, "cl_khr_semaphore"))
cl_platform_id platform_id = 0;
cl_uint num_devices = 0;
// find out what platform the harness is using.
err = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM, sizeof(cl_platform_id),
&platform_id, nullptr);
test_error(err, "clGetDeviceInfo failed");

err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, 0, nullptr,
&num_devices);
test_error(err, "clGetDeviceIDs failed");

std::vector<cl_device_id> devices(num_devices);
cl_device_id capable_device = deviceID;

err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, num_devices,
devices.data(), nullptr);
test_error(err, "clGetDeviceIDs failed");

// if possible use device other than the one from harness
shajder marked this conversation as resolved.
Show resolved Hide resolved
for (auto device : devices)
{
if (deviceID != device
&& is_extension_available(capable_device, "cl_khr_semaphore"))
{
capable_device = device;
break;
}
}

if (deviceID == capable_device
&& !is_extension_available(capable_device, "cl_khr_semaphore"))
{
log_info("cl_khr_semaphore is not supported on this platoform. "
shajder marked this conversation as resolved.
Show resolved Hide resolved
"Skipping test.\n");
return TEST_SKIPPED_ITSELF;
}

// Obtain pointers to semaphore's API
GET_PFN(deviceID, clCreateSemaphoreWithPropertiesKHR);
GET_PFN(deviceID, clGetSemaphoreInfoKHR);
GET_PFN(deviceID, clRetainSemaphoreKHR);
GET_PFN(deviceID, clReleaseSemaphoreKHR);
GET_PFN(capable_device, clCreateSemaphoreWithPropertiesKHR);
GET_PFN(capable_device, clGetSemaphoreInfoKHR);
GET_PFN(capable_device, clRetainSemaphoreKHR);
GET_PFN(capable_device, clReleaseSemaphoreKHR);

// Create binary semaphore
cl_semaphore_properties_khr sema_props[] = {
static_cast<cl_semaphore_properties_khr>(CL_SEMAPHORE_TYPE_KHR),
static_cast<cl_semaphore_properties_khr>(CL_SEMAPHORE_TYPE_BINARY_KHR),
static_cast<cl_semaphore_properties_khr>(
CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR),
(cl_semaphore_properties_khr)capable_device,
CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR,
shajder marked this conversation as resolved.
Show resolved Hide resolved
0
};
cl_semaphore_khr sema =
Expand All @@ -623,6 +658,11 @@ int test_semaphores_queries(cl_device_id deviceID, cl_context context,
// value
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 1);

// Confirm that querying CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR returns the
// same device id the semaphore was created with
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR, cl_device_id,
capable_device);

err = clRetainSemaphoreKHR(sema);
test_error(err, "Could not retain semaphore");
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 2);
Expand All @@ -634,7 +674,7 @@ int test_semaphores_queries(cl_device_id deviceID, cl_context context,
// Confirm that querying CL_SEMAPHORE_PROPERTIES_KHR returns the same
// properties the semaphore was created with
SEMAPHORE_PARAM_TEST_ARRAY(CL_SEMAPHORE_PROPERTIES_KHR,
cl_semaphore_properties_khr, 3, sema_props);
cl_semaphore_properties_khr, 5, sema_props);
shajder marked this conversation as resolved.
Show resolved Hide resolved

// Confirm that querying CL_SEMAPHORE_PAYLOAD_KHR returns the unsignaled
// state
Expand Down Expand Up @@ -745,4 +785,4 @@ int test_semaphores_import_export_fd(cl_device_id deviceID, cl_context context,
err = clReleaseSemaphoreKHR(sema_2);
test_error(err, "Could not release semaphore");
return TEST_PASS;
}
}
Loading