mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Moved sub-test external_semaphores_import_export_fd to test_external_semaphore executable (#2110)
Fixes #1989 according to task description. Moreover, fixes #1876 as well.
This commit is contained in:
@@ -3,6 +3,7 @@ set(MODULE_NAME CL_KHR_EXTERNAL_SEMAPHORE)
|
||||
set(${MODULE_NAME}_SOURCES
|
||||
main.cpp
|
||||
test_external_semaphore.cpp
|
||||
test_external_semaphore_sync_fd.cpp
|
||||
)
|
||||
|
||||
set (CLConform_VULKAN_LIBRARIES_DIR "${VULKAN_LIB_DIR}")
|
||||
|
||||
@@ -16,16 +16,17 @@
|
||||
#include "harness/testHarness.h"
|
||||
|
||||
test_definition test_list[] = {
|
||||
ADD_TEST(external_semaphores_queries),
|
||||
ADD_TEST(external_semaphores_cross_context),
|
||||
ADD_TEST(external_semaphores_simple_1),
|
||||
ADD_TEST(external_semaphores_simple_2),
|
||||
ADD_TEST(external_semaphores_reuse),
|
||||
ADD_TEST(external_semaphores_cross_queues_ooo),
|
||||
ADD_TEST(external_semaphores_cross_queues_io),
|
||||
ADD_TEST(external_semaphores_cross_queues_io2),
|
||||
ADD_TEST(external_semaphores_multi_signal),
|
||||
ADD_TEST(external_semaphores_multi_wait),
|
||||
ADD_TEST_VERSION(external_semaphores_queries, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_cross_context, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_simple_1, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_simple_2, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_reuse, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_cross_queues_ooo, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_cross_queues_io, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_cross_queues_io2, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_multi_signal, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_multi_wait, Version(1, 2)),
|
||||
ADD_TEST_VERSION(external_semaphores_import_export_fd, Version(1, 2)),
|
||||
};
|
||||
|
||||
|
||||
@@ -39,4 +40,4 @@ int main(int argc, const char *argv[])
|
||||
const cl_command_queue_properties queue_properties = 0;
|
||||
return runTestHarnessWithCheck(argc, argv, ARRAY_SIZE(test_list), test_list,
|
||||
false, queue_properties, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,4 +63,4 @@ extern int test_external_semaphores_import_export_fd(cl_device_id deviceID,
|
||||
cl_context context,
|
||||
cl_command_queue queue,
|
||||
int num_elements);
|
||||
#endif // CL_KHR_EXTERNAL_SEMAPHORE_PROCS_H
|
||||
#endif // CL_KHR_EXTERNAL_SEMAPHORE_PROCS_H
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
|
||||
#define SEMAPHORE_PARAM_TEST(param_name, param_type, expected) \
|
||||
do \
|
||||
@@ -16,9 +17,9 @@
|
||||
test_error(error, "Unable to get " #param_name " from semaphore"); \
|
||||
if (value != expected) \
|
||||
{ \
|
||||
test_fail("ERROR: Parameter %s did not validate! (expected %d, " \
|
||||
"got %d)\n", \
|
||||
#param_name, expected, value); \
|
||||
test_fail("ERROR: Parameter %s did not validate! " \
|
||||
"(expected %" PRIuPTR " got %" PRIuPTR ")\n", \
|
||||
#param_name, (uintptr_t)expected, (uintptr_t)value); \
|
||||
} \
|
||||
if (size != sizeof(value)) \
|
||||
{ \
|
||||
@@ -51,7 +52,7 @@
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
static const char* source = "__kernel void empty() {}";
|
||||
static const char *source = "__kernel void empty() {}";
|
||||
|
||||
static void log_info_semaphore_type(
|
||||
VulkanExternalSemaphoreHandleType vkExternalSemaphoreHandleType)
|
||||
@@ -63,7 +64,7 @@ static void log_info_semaphore_type(
|
||||
log_info("%s", semaphore_type_description.str().c_str());
|
||||
}
|
||||
|
||||
static int init_vuikan_device(cl_uint num_devices, cl_device_id* deviceIds)
|
||||
static int init_vulkan_device(cl_uint num_devices, cl_device_id *deviceIds)
|
||||
{
|
||||
cl_platform_id platform = nullptr;
|
||||
|
||||
@@ -83,7 +84,7 @@ static int init_vuikan_device(cl_uint num_devices, cl_device_id* deviceIds)
|
||||
|
||||
static cl_int get_device_semaphore_handle_types(
|
||||
cl_device_id deviceID, cl_device_info param,
|
||||
std::vector<cl_external_semaphore_handle_type_khr>& handle_types)
|
||||
std::vector<cl_external_semaphore_handle_type_khr> &handle_types)
|
||||
{
|
||||
int err = CL_SUCCESS;
|
||||
// Query for export support
|
||||
@@ -125,7 +126,7 @@ int test_external_semaphores_queries(cl_device_id deviceID, cl_context context,
|
||||
REQUIRE_EXTENSION("cl_khr_semaphore");
|
||||
REQUIRE_EXTENSION("cl_khr_external_semaphore");
|
||||
|
||||
if (init_vuikan_device(1, &deviceID))
|
||||
if (init_vulkan_device(1, &deviceID))
|
||||
{
|
||||
log_info("Cannot initialise Vulkan. "
|
||||
"Skipping test.\n");
|
||||
@@ -330,7 +331,7 @@ int test_external_semaphores_simple_1(cl_device_id deviceID, cl_context context,
|
||||
{
|
||||
REQUIRE_EXTENSION("cl_khr_external_semaphore");
|
||||
|
||||
if (init_vuikan_device(1, &deviceID))
|
||||
if (init_vulkan_device(1, &deviceID))
|
||||
{
|
||||
log_info("Cannot initialise Vulkan. "
|
||||
"Skipping test.\n");
|
||||
@@ -405,7 +406,7 @@ int test_external_semaphores_simple_2(cl_device_id deviceID, cl_context context,
|
||||
{
|
||||
REQUIRE_EXTENSION("cl_khr_external_semaphore");
|
||||
|
||||
if (init_vuikan_device(1, &deviceID))
|
||||
if (init_vulkan_device(1, &deviceID))
|
||||
{
|
||||
log_info("Cannot initialise Vulkan. "
|
||||
"Skipping test.\n");
|
||||
@@ -512,7 +513,7 @@ int test_external_semaphores_reuse(cl_device_id deviceID, cl_context context,
|
||||
{
|
||||
REQUIRE_EXTENSION("cl_khr_external_semaphore");
|
||||
|
||||
if (init_vuikan_device(1, &deviceID))
|
||||
if (init_vulkan_device(1, &deviceID))
|
||||
{
|
||||
log_info("Cannot initialise Vulkan. "
|
||||
"Skipping test.\n");
|
||||
@@ -632,7 +633,7 @@ static int external_semaphore_cross_queue_helper(cl_device_id deviceID,
|
||||
{
|
||||
REQUIRE_EXTENSION("cl_khr_external_semaphore");
|
||||
|
||||
if (init_vuikan_device(1, &deviceID))
|
||||
if (init_vulkan_device(1, &deviceID))
|
||||
{
|
||||
log_info("Cannot initialise Vulkan. "
|
||||
"Skipping test.\n");
|
||||
@@ -682,7 +683,7 @@ static int external_semaphore_cross_queue_helper(cl_device_id deviceID,
|
||||
nullptr, 0, nullptr, &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");
|
||||
|
||||
@@ -747,7 +748,7 @@ int test_external_semaphores_cross_queues_io2(cl_device_id deviceID,
|
||||
{
|
||||
REQUIRE_EXTENSION("cl_khr_external_semaphore");
|
||||
|
||||
if (init_vuikan_device(1, &deviceID))
|
||||
if (init_vulkan_device(1, &deviceID))
|
||||
{
|
||||
log_info("Cannot initialise Vulkan. "
|
||||
"Skipping test.\n");
|
||||
@@ -856,7 +857,7 @@ int test_external_semaphores_multi_signal(cl_device_id deviceID,
|
||||
{
|
||||
REQUIRE_EXTENSION("cl_khr_external_semaphore");
|
||||
|
||||
if (init_vuikan_device(1, &deviceID))
|
||||
if (init_vulkan_device(1, &deviceID))
|
||||
{
|
||||
log_info("Cannot initialise Vulkan. "
|
||||
"Skipping test.\n");
|
||||
@@ -947,7 +948,7 @@ int test_external_semaphores_multi_wait(cl_device_id deviceID,
|
||||
{
|
||||
REQUIRE_EXTENSION("cl_khr_external_semaphore");
|
||||
|
||||
if (init_vuikan_device(1, &deviceID))
|
||||
if (init_vulkan_device(1, &deviceID))
|
||||
{
|
||||
log_info("Cannot initialise Vulkan. "
|
||||
"Skipping test.\n");
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// Copyright (c) 2024 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include "harness/typeWrappers.h"
|
||||
#include "harness/extensionHelpers.h"
|
||||
#include "harness/errorHelpers.h"
|
||||
|
||||
// Test it is possible to export a semaphore to a sync fd and import the same
|
||||
// sync fd to a new semaphore
|
||||
int test_external_semaphores_import_export_fd(cl_device_id deviceID,
|
||||
cl_context context,
|
||||
cl_command_queue defaultQueue,
|
||||
int num_elements)
|
||||
{
|
||||
cl_int err = CL_SUCCESS;
|
||||
|
||||
if (!is_extension_available(deviceID, "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(deviceID, "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(deviceID, 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
|
||||
GET_PFN(deviceID, clCreateSemaphoreWithPropertiesKHR);
|
||||
GET_PFN(deviceID, clEnqueueSignalSemaphoresKHR);
|
||||
GET_PFN(deviceID, clEnqueueWaitSemaphoresKHR);
|
||||
GET_PFN(deviceID, clGetSemaphoreHandleForTypeKHR);
|
||||
GET_PFN(deviceID, clReleaseSemaphoreKHR);
|
||||
|
||||
// Create ooo queue
|
||||
clCommandQueueWrapper queue = clCreateCommandQueue(
|
||||
context, deviceID, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &err);
|
||||
test_error(err, "Could not create command queue");
|
||||
|
||||
// Create semaphore
|
||||
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_BINARY_KHR),
|
||||
static_cast<cl_semaphore_properties_khr>(
|
||||
CL_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR),
|
||||
static_cast<cl_semaphore_properties_khr>(
|
||||
CL_SEMAPHORE_HANDLE_SYNC_FD_KHR),
|
||||
static_cast<cl_semaphore_properties_khr>(
|
||||
CL_SEMAPHORE_EXPORT_HANDLE_TYPES_LIST_END_KHR),
|
||||
0
|
||||
};
|
||||
cl_semaphore_khr sema_1 =
|
||||
clCreateSemaphoreWithPropertiesKHR(context, sema_1_props, &err);
|
||||
test_error(err, "Could not create semaphore");
|
||||
|
||||
// Signal semaphore
|
||||
clEventWrapper signal_event;
|
||||
err = clEnqueueSignalSemaphoresKHR(queue, 1, &sema_1, nullptr, 0, nullptr,
|
||||
&signal_event);
|
||||
test_error(err, "Could not signal semaphore");
|
||||
|
||||
// Extract sync fd
|
||||
int handle = -1;
|
||||
size_t handle_size;
|
||||
err = clGetSemaphoreHandleForTypeKHR(sema_1, deviceID,
|
||||
CL_SEMAPHORE_HANDLE_SYNC_FD_KHR,
|
||||
sizeof(handle), &handle, &handle_size);
|
||||
test_error(err, "Could not extract semaphore handle");
|
||||
test_assert_error(sizeof(handle) == handle_size, "Invalid handle size");
|
||||
test_assert_error(handle >= 0, "Invalid handle");
|
||||
|
||||
// Create semaphore from sync fd
|
||||
cl_semaphore_properties_khr sema_2_props[] = {
|
||||
static_cast<cl_semaphore_properties_khr>(CL_SEMAPHORE_TYPE_KHR),
|
||||
static_cast<cl_semaphore_properties_khr>(CL_SEMAPHORE_TYPE_BINARY_KHR),
|
||||
CL_SEMAPHORE_HANDLE_SYNC_FD_KHR,
|
||||
static_cast<cl_semaphore_properties_khr>(handle), 0
|
||||
};
|
||||
|
||||
cl_semaphore_khr sema_2 =
|
||||
clCreateSemaphoreWithPropertiesKHR(context, sema_2_props, &err);
|
||||
test_error(err, "Could not create semaphore");
|
||||
|
||||
// Wait semaphore
|
||||
clEventWrapper wait_event;
|
||||
err = clEnqueueWaitSemaphoresKHR(queue, 1, &sema_2, nullptr, 0, nullptr,
|
||||
&wait_event);
|
||||
test_error(err, "Could not wait semaphore");
|
||||
|
||||
// Finish
|
||||
err = clFinish(queue);
|
||||
test_error(err, "Could not finish queue");
|
||||
|
||||
// Check all events are completed
|
||||
test_assert_event_complete(signal_event);
|
||||
test_assert_event_complete(wait_event);
|
||||
|
||||
// Release semaphore
|
||||
err = clReleaseSemaphoreKHR(sema_1);
|
||||
test_error(err, "Could not release semaphore");
|
||||
|
||||
err = clReleaseSemaphoreKHR(sema_2);
|
||||
test_error(err, "Could not release semaphore");
|
||||
return TEST_PASS;
|
||||
}
|
||||
@@ -36,7 +36,6 @@ test_definition test_list[] = {
|
||||
ADD_TEST_VERSION(semaphores_device_list_queries, Version(1, 2)),
|
||||
ADD_TEST_VERSION(semaphores_no_device_list_queries, Version(1, 2)),
|
||||
ADD_TEST_VERSION(semaphores_multi_device_context_queries, Version(1, 2)),
|
||||
ADD_TEST_VERSION(semaphores_import_export_fd, Version(1, 2)),
|
||||
ADD_TEST_VERSION(semaphores_ooo_ops_single_queue, Version(1, 2)),
|
||||
ADD_TEST_VERSION(semaphores_ooo_ops_cross_queue, Version(1, 2)),
|
||||
ADD_TEST_VERSION(semaphores_negative_create_invalid_context, Version(1, 2)),
|
||||
|
||||
@@ -378,95 +378,6 @@ struct SemaphoreMultiWait : public SemaphoreTestBase
|
||||
clSemaphoreWrapper semaphore_second = nullptr;
|
||||
};
|
||||
|
||||
struct SemaphoreImportExportFD : public SemaphoreTestBase
|
||||
{
|
||||
SemaphoreImportExportFD(cl_device_id device, cl_context context,
|
||||
cl_command_queue queue, cl_int nelems)
|
||||
: SemaphoreTestBase(device, context, queue, nelems),
|
||||
semaphore_second(this)
|
||||
{}
|
||||
|
||||
cl_int Run() override
|
||||
{
|
||||
cl_int err = CL_SUCCESS;
|
||||
if (!is_extension_available(device,
|
||||
"cl_khr_external_semaphore_sync_fd"))
|
||||
{
|
||||
log_info(
|
||||
"cl_khr_external_semaphore_sync_fd is not supported on this "
|
||||
"platform. Skipping test.\n");
|
||||
return TEST_SKIPPED_ITSELF;
|
||||
}
|
||||
|
||||
// Create ooo queue
|
||||
clCommandQueueWrapper queue = clCreateCommandQueue(
|
||||
context, device, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &err);
|
||||
test_error(err, "Could not create command queue");
|
||||
|
||||
// Create semaphore
|
||||
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_BINARY_KHR),
|
||||
static_cast<cl_semaphore_properties_khr>(
|
||||
CL_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR),
|
||||
static_cast<cl_semaphore_properties_khr>(
|
||||
CL_SEMAPHORE_HANDLE_SYNC_FD_KHR),
|
||||
static_cast<cl_semaphore_properties_khr>(
|
||||
CL_SEMAPHORE_EXPORT_HANDLE_TYPES_LIST_END_KHR),
|
||||
0
|
||||
};
|
||||
semaphore =
|
||||
clCreateSemaphoreWithPropertiesKHR(context, sema_1_props, &err);
|
||||
test_error(err, "Could not create semaphore");
|
||||
|
||||
// Signal semaphore
|
||||
clEventWrapper signal_event;
|
||||
err = clEnqueueSignalSemaphoresKHR(queue, 1, semaphore, nullptr, 0,
|
||||
nullptr, &signal_event);
|
||||
test_error(err, "Could not signal semaphore");
|
||||
|
||||
// Extract sync fd
|
||||
int handle = -1;
|
||||
size_t handle_size;
|
||||
err = clGetSemaphoreHandleForTypeKHR(
|
||||
semaphore, device, CL_SEMAPHORE_HANDLE_SYNC_FD_KHR, sizeof(handle),
|
||||
&handle, &handle_size);
|
||||
test_error(err, "Could not extract semaphore handle");
|
||||
test_assert_error(sizeof(handle) == handle_size, "Invalid handle size");
|
||||
test_assert_error(handle >= 0, "Invalid handle");
|
||||
|
||||
// Create semaphore from sync fd
|
||||
cl_semaphore_properties_khr sema_2_props[] = {
|
||||
static_cast<cl_semaphore_properties_khr>(CL_SEMAPHORE_TYPE_KHR),
|
||||
static_cast<cl_semaphore_properties_khr>(
|
||||
CL_SEMAPHORE_TYPE_BINARY_KHR),
|
||||
CL_SEMAPHORE_HANDLE_SYNC_FD_KHR,
|
||||
static_cast<cl_semaphore_properties_khr>(handle), 0
|
||||
};
|
||||
|
||||
semaphore_second =
|
||||
clCreateSemaphoreWithPropertiesKHR(context, sema_2_props, &err);
|
||||
test_error(err, "Could not create semaphore");
|
||||
|
||||
// Wait semaphore
|
||||
clEventWrapper wait_event;
|
||||
err = clEnqueueWaitSemaphoresKHR(queue, 1, semaphore_second, nullptr, 0,
|
||||
nullptr, &wait_event);
|
||||
test_error(err, "Could not wait semaphore");
|
||||
|
||||
// Finish
|
||||
err = clFinish(queue);
|
||||
test_error(err, "Could not finish queue");
|
||||
|
||||
// Check all events are completed
|
||||
test_assert_event_complete(signal_event);
|
||||
test_assert_event_complete(wait_event);
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
clSemaphoreWrapper semaphore_second = nullptr;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
// Confirm that a signal followed by a wait will complete successfully
|
||||
@@ -510,13 +421,3 @@ int test_semaphores_multi_wait(cl_device_id deviceID, cl_context context,
|
||||
return MakeAndRunTest<SemaphoreMultiWait>(deviceID, context, defaultQueue,
|
||||
num_elements);
|
||||
}
|
||||
|
||||
// Test it is possible to export a semaphore to a sync fd and import the same
|
||||
// sync fd to a new semaphore
|
||||
int test_semaphores_import_export_fd(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue defaultQueue,
|
||||
int num_elements)
|
||||
{
|
||||
return MakeAndRunTest<SemaphoreImportExportFD>(deviceID, context,
|
||||
defaultQueue, num_elements);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user