From 2998463eb4a33221c49cec0d07e3a323e4922041 Mon Sep 17 00:00:00 2001 From: Marcin Hajder Date: Tue, 15 Oct 2024 17:44:23 +0200 Subject: [PATCH] Added missing test cases for CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR queries (#2063) According to comments from issue #1875 --------- Co-authored-by: Nikhil Joshi --- .../cl_khr_semaphore/CMakeLists.txt | 1 + .../extensions/cl_khr_semaphore/main.cpp | 4 +- .../extensions/cl_khr_semaphore/procs.h | 14 +- .../cl_khr_semaphore/semaphore_base.h | 24 +- .../cl_khr_semaphore/test_semaphores.cpp | 125 +------- .../test_semaphores_negative_create.cpp | 21 -- .../test_semaphores_queries.cpp | 278 ++++++++++++++++++ 7 files changed, 319 insertions(+), 148 deletions(-) create mode 100644 test_conformance/extensions/cl_khr_semaphore/test_semaphores_queries.cpp diff --git a/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt b/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt index c13ca39d..5f408cdb 100644 --- a/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt +++ b/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt @@ -7,6 +7,7 @@ set(${MODULE_NAME}_SOURCES test_semaphores_negative_release_retain.cpp test_semaphores_negative_getinfo.cpp test_semaphores_negative_create.cpp + test_semaphores_queries.cpp semaphore_base.h ) diff --git a/test_conformance/extensions/cl_khr_semaphore/main.cpp b/test_conformance/extensions/cl_khr_semaphore/main.cpp index 1ba7ff2a..44897dd7 100644 --- a/test_conformance/extensions/cl_khr_semaphore/main.cpp +++ b/test_conformance/extensions/cl_khr_semaphore/main.cpp @@ -33,7 +33,9 @@ test_definition test_list[] = { ADD_TEST_VERSION(semaphores_cross_queues_io, Version(1, 2)), ADD_TEST_VERSION(semaphores_multi_signal, Version(1, 2)), ADD_TEST_VERSION(semaphores_multi_wait, Version(1, 2)), - ADD_TEST_VERSION(semaphores_queries, Version(1, 2)), + 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_negative_create_invalid_context, Version(1, 2)), ADD_TEST_VERSION(semaphores_negative_create_invalid_property, diff --git a/test_conformance/extensions/cl_khr_semaphore/procs.h b/test_conformance/extensions/cl_khr_semaphore/procs.h index bf59ea89..06e0c4f9 100644 --- a/test_conformance/extensions/cl_khr_semaphore/procs.h +++ b/test_conformance/extensions/cl_khr_semaphore/procs.h @@ -39,8 +39,18 @@ extern int test_semaphores_multi_signal(cl_device_id deviceID, int num_elements); extern int test_semaphores_multi_wait(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_semaphores_queries(cl_device_id deviceID, cl_context context, - cl_command_queue queue, int num_elements); +extern int test_semaphores_device_list_queries(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_semaphores_no_device_list_queries(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_semaphores_multi_device_context_queries(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); extern int test_semaphores_import_export_fd(cl_device_id deviceID, cl_context context, cl_command_queue queue, diff --git a/test_conformance/extensions/cl_khr_semaphore/semaphore_base.h b/test_conformance/extensions/cl_khr_semaphore/semaphore_base.h index e50f33ae..9ce5e381 100644 --- a/test_conformance/extensions/cl_khr_semaphore/semaphore_base.h +++ b/test_conformance/extensions/cl_khr_semaphore/semaphore_base.h @@ -17,11 +17,33 @@ #define CL_KHR_SEMAPHORE_BASE_H #include + +#include + #include "harness/deviceInfo.h" #include "harness/testHarness.h" - #include "harness/typeWrappers.h" +// scope guard helper to ensure proper releasing of sub devices +struct SubDevicesScopeGuarded +{ + SubDevicesScopeGuarded(const cl_int dev_count) + { + sub_devices.resize(dev_count); + } + ~SubDevicesScopeGuarded() + { + for (auto &device : sub_devices) + { + cl_int err = clReleaseDevice(device); + if (err != CL_SUCCESS) + log_error("\n Releasing sub-device failed \n"); + } + } + + std::vector sub_devices; +}; + struct SemaphoreBase { SemaphoreBase(cl_device_id device): device(device) {} diff --git a/test_conformance/extensions/cl_khr_semaphore/test_semaphores.cpp b/test_conformance/extensions/cl_khr_semaphore/test_semaphores.cpp index f4f28324..6cf4d009 100644 --- a/test_conformance/extensions/cl_khr_semaphore/test_semaphores.cpp +++ b/test_conformance/extensions/cl_khr_semaphore/test_semaphores.cpp @@ -14,63 +14,14 @@ // limitations under the License. // - -#include "harness/typeWrappers.h" -#include "harness/errorHelpers.h" -#include #include -#include -#include + +#include "semaphore_base.h" #include "semaphore_base.h" #define FLUSH_DELAY_S 5 -#define SEMAPHORE_PARAM_TEST(param_name, param_type, expected) \ - do \ - { \ - param_type value; \ - size_t size; \ - cl_int error = clGetSemaphoreInfoKHR(semaphore, param_name, \ - sizeof(value), &value, &size); \ - 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); \ - } \ - if (size != sizeof(value)) \ - { \ - test_fail( \ - "ERROR: Returned size of parameter %s does not validate! " \ - "(expected %d, got %d)\n", \ - #param_name, (int)sizeof(value), (int)size); \ - } \ - } while (false) - -#define SEMAPHORE_PARAM_TEST_ARRAY(param_name, param_type, num_params, \ - expected) \ - do \ - { \ - param_type value[num_params]; \ - size_t size; \ - cl_int error = clGetSemaphoreInfoKHR(semaphore, param_name, \ - sizeof(value), &value, &size); \ - test_error(error, "Unable to get " #param_name " from semaphore"); \ - if (size != sizeof(value)) \ - { \ - test_fail( \ - "ERROR: Returned size of parameter %s does not validate! " \ - "(expected %d, got %d)\n", \ - #param_name, (int)sizeof(value), (int)size); \ - } \ - if (memcmp(value, expected, size) != 0) \ - { \ - test_fail("ERROR: Parameter %s did not validate!\n", #param_name); \ - } \ - } while (false) - namespace { const char* source = "__kernel void empty() {}"; @@ -515,71 +466,6 @@ struct SemaphoreMultiWait : public SemaphoreTestBase clSemaphoreWrapper semaphore_second = nullptr; }; -struct SemaphoreQueries : public SemaphoreTestBase -{ - SemaphoreQueries(cl_device_id device, cl_context context, - cl_command_queue queue) - : SemaphoreTestBase(device, context, queue) - {} - - cl_int Run() override - { - cl_int err = CL_SUCCESS; - // Create binary semaphore - cl_semaphore_properties_khr sema_props[] = { - static_cast(CL_SEMAPHORE_TYPE_KHR), - static_cast( - CL_SEMAPHORE_TYPE_BINARY_KHR), - static_cast( - CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR), - (cl_semaphore_properties_khr)device, - CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR, - 0 - }; - semaphore = - clCreateSemaphoreWithPropertiesKHR(context, sema_props, &err); - test_error(err, "Could not create semaphore"); - - // Confirm that querying CL_SEMAPHORE_TYPE_KHR returns - // CL_SEMAPHORE_TYPE_BINARY_KHR - SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_TYPE_KHR, cl_semaphore_type_khr, - CL_SEMAPHORE_TYPE_BINARY_KHR); - - // Confirm that querying CL_SEMAPHORE_CONTEXT_KHR returns the right - // context - SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_CONTEXT_KHR, cl_context, context); - - // Confirm that querying CL_SEMAPHORE_REFERENCE_COUNT_KHR returns the - // right value - SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 1); - - err = clRetainSemaphoreKHR(semaphore); - test_error(err, "Could not retain semaphore"); - SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 2); - - err = clReleaseSemaphoreKHR(semaphore); - test_error(err, "Could not release semaphore"); - 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, - device); - - // 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, 6, sema_props); - - // Confirm that querying CL_SEMAPHORE_PAYLOAD_KHR returns the unsignaled - // state - SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_PAYLOAD_KHR, cl_semaphore_payload_khr, - 0); - - return CL_SUCCESS; - } -}; - struct SemaphoreImportExportFD : public SemaphoreTestBase { SemaphoreImportExportFD(cl_device_id device, cl_context context, @@ -726,13 +612,6 @@ int test_semaphores_multi_wait(cl_device_id deviceID, cl_context context, return MakeAndRunTest(deviceID, context, defaultQueue); } -// Confirm the semaphores can be successfully queried -int test_semaphores_queries(cl_device_id deviceID, cl_context context, - cl_command_queue defaultQueue, int num_elements) -{ - return MakeAndRunTest(deviceID, context, defaultQueue); -} - // 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, diff --git a/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_create.cpp b/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_create.cpp index 35aeaa98..f4c5db2d 100644 --- a/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_create.cpp +++ b/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_create.cpp @@ -20,7 +20,6 @@ #include #include #include -#include namespace { @@ -51,26 +50,6 @@ struct CreateInvalidContext : public SemaphoreTestBase } }; -// scope guard helper to ensure proper releasing of sub devices -struct SubDevicesScopeGuarded -{ - SubDevicesScopeGuarded(const cl_int dev_count) - { - sub_devices.resize(dev_count); - } - ~SubDevicesScopeGuarded() - { - for (auto& device : sub_devices) - { - cl_int err = clReleaseDevice(device); - if (err != CL_SUCCESS) - log_error("\n Releasing sub-device failed \n"); - } - } - - std::vector sub_devices; -}; - // (1) property name in sema_props is not a supported property name, // (2) value specified for a supported property name is not valid, // (3) the same property name is specified more than once. diff --git a/test_conformance/extensions/cl_khr_semaphore/test_semaphores_queries.cpp b/test_conformance/extensions/cl_khr_semaphore/test_semaphores_queries.cpp new file mode 100644 index 00000000..8d988c71 --- /dev/null +++ b/test_conformance/extensions/cl_khr_semaphore/test_semaphores_queries.cpp @@ -0,0 +1,278 @@ +// +// Copyright (c) 2023 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 "semaphore_base.h" + +#define FLUSH_DELAY_S 5 + +#define SEMAPHORE_PARAM_TEST(param_name, param_type, expected) \ + do \ + { \ + param_type value; \ + size_t size; \ + cl_int error = clGetSemaphoreInfoKHR(semaphore, param_name, \ + sizeof(value), &value, &size); \ + 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); \ + } \ + if (size != sizeof(value)) \ + { \ + test_fail( \ + "ERROR: Returned size of parameter %s does not validate! " \ + "(expected %d, got %d)\n", \ + #param_name, (int)sizeof(value), (int)size); \ + } \ + } while (false) + +#define SEMAPHORE_PARAM_TEST_ARRAY(param_name, param_type, num_params, \ + expected) \ + do \ + { \ + param_type value[num_params]; \ + size_t size; \ + cl_int error = clGetSemaphoreInfoKHR(semaphore, param_name, \ + sizeof(value), &value, &size); \ + test_error(error, "Unable to get " #param_name " from semaphore"); \ + if (size != sizeof(value)) \ + { \ + test_fail( \ + "ERROR: Returned size of parameter %s does not validate! " \ + "(expected %d, got %d)\n", \ + #param_name, (int)sizeof(value), (int)size); \ + } \ + if (memcmp(value, expected, size) != 0) \ + { \ + test_fail("ERROR: Parameter %s did not validate!\n", #param_name); \ + } \ + } while (false) + +namespace { + +struct SemaphoreWithDeviceListQueries : public SemaphoreTestBase +{ + SemaphoreWithDeviceListQueries(cl_device_id device, cl_context context, + cl_command_queue queue) + : SemaphoreTestBase(device, context, queue) + {} + + cl_int Run() override + { + cl_int err = CL_SUCCESS; + + // Query binary semaphore created with + // CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR + + // Create binary semaphore + cl_semaphore_properties_khr sema_props[] = { + static_cast(CL_SEMAPHORE_TYPE_KHR), + static_cast( + CL_SEMAPHORE_TYPE_BINARY_KHR), + static_cast( + CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR), + (cl_semaphore_properties_khr)device, + CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR, + 0 + }; + semaphore = + clCreateSemaphoreWithPropertiesKHR(context, sema_props, &err); + test_error(err, "Could not create semaphore"); + + // Confirm that querying CL_SEMAPHORE_TYPE_KHR returns + // CL_SEMAPHORE_TYPE_BINARY_KHR + SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_TYPE_KHR, cl_semaphore_type_khr, + CL_SEMAPHORE_TYPE_BINARY_KHR); + + // Confirm that querying CL_SEMAPHORE_CONTEXT_KHR returns the right + // context + SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_CONTEXT_KHR, cl_context, context); + + // Confirm that querying CL_SEMAPHORE_REFERENCE_COUNT_KHR returns + // the right value + SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 1); + + err = clRetainSemaphoreKHR(semaphore); + test_error(err, "Could not retain semaphore"); + SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 2); + + err = clReleaseSemaphoreKHR(semaphore); + test_error(err, "Could not release semaphore"); + 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, + device); + + // 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, 6, sema_props); + + // Confirm that querying CL_SEMAPHORE_PAYLOAD_KHR returns the + // unsignaled state + SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_PAYLOAD_KHR, cl_semaphore_payload_khr, + 0); + + return TEST_PASS; + } +}; + +struct SemaphoreNoDeviceListQueries : public SemaphoreTestBase +{ + SemaphoreNoDeviceListQueries(cl_device_id device, cl_context context, + cl_command_queue queue) + : SemaphoreTestBase(device, context, queue) + {} + + cl_int Run() override + { + cl_int err = CL_SUCCESS; + + // Query binary semaphore created without + // CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR + + // Create binary semaphore + cl_semaphore_properties_khr sema_props[] = { + static_cast(CL_SEMAPHORE_TYPE_KHR), + static_cast( + CL_SEMAPHORE_TYPE_BINARY_KHR), + 0 + }; + semaphore = + clCreateSemaphoreWithPropertiesKHR(context, sema_props, &err); + test_error(err, "Could not create semaphore"); + + // Confirm that querying CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR returns + // device id the semaphore was created with + SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR, cl_device_id, + device); + + return TEST_PASS; + } +}; + +struct SemaphoreMultiDeviceContextQueries : public SemaphoreTestBase +{ + SemaphoreMultiDeviceContextQueries(cl_device_id device, cl_context context, + cl_command_queue queue) + : SemaphoreTestBase(device, context, queue) + {} + + cl_int Run() override + { + // partition device and create new context if possible + cl_uint maxComputeUnits = 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[] = { + CL_DEVICE_PARTITION_EQUALLY, maxComputeUnits / 2, 0 + }; + + cl_uint deviceCount = 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"); + return TEST_SKIPPED_ITSELF; + } + + if (deviceCount < 2) + test_error_ret( + CL_INVALID_VALUE, + "Multi context test for CL_INVALID_PROPERTY not supported", + TEST_SKIPPED_ITSELF); + + // get the list of subDevices + SubDevicesScopeGuarded scope_guard(deviceCount); + err = clCreateSubDevices(device, partitionProp, deviceCount, + scope_guard.sub_devices.data(), &deviceCount); + if (err != CL_SUCCESS) + { + log_info("Can't partition device, test not supported\n"); + return TEST_SKIPPED_ITSELF; + } + + /* Create a multi device context */ + clContextWrapper multi_device_context = clCreateContext( + NULL, (cl_uint)deviceCount, scope_guard.sub_devices.data(), nullptr, + nullptr, &err); + test_error_ret(err, "Unable to create testing context", CL_SUCCESS); + + cl_semaphore_properties_khr sema_props[] = { + (cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_KHR, + (cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_BINARY_KHR, + static_cast( + CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR), + (cl_semaphore_properties_khr)scope_guard.sub_devices[0], + CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR, + 0 + }; + + // Try to create semaphore with multi device context + semaphore = clCreateSemaphoreWithPropertiesKHR(multi_device_context, + sema_props, &err); + test_error(err, "Unable to create semaphore with properties"); + + // 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, + scope_guard.sub_devices[0]); + + return TEST_PASS; + } +}; + +} // anonymous namespace + +// Confirm the semaphore with device list can be successfully queried +int test_semaphores_device_list_queries(cl_device_id deviceID, + cl_context context, + cl_command_queue defaultQueue, + int num_elements) +{ + return MakeAndRunTest(deviceID, context, + defaultQueue); +} + +// Confirm the semaphore without device list can be successfully queried +int test_semaphores_no_device_list_queries(cl_device_id deviceID, + cl_context context, + cl_command_queue defaultQueue, + int num_elements) +{ + return MakeAndRunTest(deviceID, context, + defaultQueue); +} + +// Confirm the semaphore created with multi-device context can be successfully +// queried +int test_semaphores_multi_device_context_queries(cl_device_id deviceID, + cl_context context, + cl_command_queue defaultQueue, + int num_elements) +{ + return MakeAndRunTest(deviceID, context, + defaultQueue); +}