From 521d067083e964680f3812c0f8c86607de17aa1e Mon Sep 17 00:00:00 2001 From: Ahmed Hesham <117350656+ahesham-arm@users.noreply.github.com> Date: Sat, 8 Mar 2025 22:37:04 +0000 Subject: [PATCH] Migrate device_partition suite to the new test registration framework (#2301) Contributes to #2181 --- test_conformance/device_partition/main.cpp | 29 +---- test_conformance/device_partition/procs.h | 29 ----- test_conformance/device_partition/testBase.h | 7 +- .../test_device_partition.cpp | 107 +++++++++++------- 4 files changed, 67 insertions(+), 105 deletions(-) delete mode 100644 test_conformance/device_partition/procs.h diff --git a/test_conformance/device_partition/main.cpp b/test_conformance/device_partition/main.cpp index a8af6ffb..65777e48 100644 --- a/test_conformance/device_partition/main.cpp +++ b/test_conformance/device_partition/main.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 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 @@ -13,33 +13,10 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "harness/compat.h" - -#include -#include -#include "procs.h" #include "harness/testHarness.h" -#include "harness/mt19937.h" - -#if !defined(_WIN32) -#include -#endif - -test_definition test_list[] = { - ADD_TEST( partition_equally ), - ADD_TEST( partition_by_counts ), - ADD_TEST( partition_by_affinity_domain_numa ), - ADD_TEST( partition_by_affinity_domain_l4_cache ), - ADD_TEST( partition_by_affinity_domain_l3_cache ), - ADD_TEST( partition_by_affinity_domain_l2_cache ), - ADD_TEST( partition_by_affinity_domain_l1_cache ), - ADD_TEST( partition_by_affinity_domain_next_partitionable ), - ADD_TEST( partition_all ), -}; - -const int test_num = ARRAY_SIZE( test_list ); int main(int argc, const char *argv[]) { - return runTestHarness(argc, argv, test_num, test_list, true, 0); + return runTestHarness(argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), true, 0); } diff --git a/test_conformance/device_partition/procs.h b/test_conformance/device_partition/procs.h deleted file mode 100644 index 1e543daf..00000000 --- a/test_conformance/device_partition/procs.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright (c) 2017 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/errorHelpers.h" -#include "harness/kernelHelpers.h" -#include "harness/typeWrappers.h" -#include "harness/mt19937.h" - -extern int test_partition_all(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_partition_equally(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_partition_by_counts(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_partition_by_affinity_domain_numa(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_partition_by_affinity_domain_l4_cache(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_partition_by_affinity_domain_l3_cache(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_partition_by_affinity_domain_l2_cache(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_partition_by_affinity_domain_l1_cache(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_partition_by_affinity_domain_next_partitionable(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); diff --git a/test_conformance/device_partition/testBase.h b/test_conformance/device_partition/testBase.h index 5b49bfd7..a358b81a 100644 --- a/test_conformance/device_partition/testBase.h +++ b/test_conformance/device_partition/testBase.h @@ -1,6 +1,6 @@ // // Copyright (c) 2017 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 @@ -23,9 +23,4 @@ #include #include -#include "procs.h" - #endif // _testBase_h - - - diff --git a/test_conformance/device_partition/test_device_partition.cpp b/test_conformance/device_partition/test_device_partition.cpp index 2daa09a0..9573e5f9 100644 --- a/test_conformance/device_partition/test_device_partition.cpp +++ b/test_conformance/device_partition/test_device_partition.cpp @@ -416,14 +416,16 @@ int test_device_partition_type_support(cl_device_id parentDevice, const cl_devic return -1; } -int test_partition_of_device(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, cl_device_partition_property *partition_type, +int test_partition_of_device(cl_device_id device, cl_context context, + cl_command_queue queue, int num_elements, + cl_device_partition_property *partition_type, cl_uint starting_property, cl_uint ending_property) { cl_uint maxComputeUnits; cl_uint maxSubDevices; // maximal number of sub-devices that can be created in one call to clCreateSubDevices int err = 0; - if (init_device_partition_test(deviceID, maxComputeUnits, maxSubDevices) != 0) + if (init_device_partition_test(device, maxComputeUnits, maxSubDevices) != 0) return -1; if (maxComputeUnits <= 1) @@ -432,10 +434,11 @@ int test_partition_of_device(cl_device_id deviceID, cl_context context, cl_comma if (partition_type != NULL) { // if we're not the root device size_t psize; - err = clGetDeviceInfo(deviceID, CL_DEVICE_PARTITION_TYPE, 0, NULL, &psize); + err = clGetDeviceInfo(device, CL_DEVICE_PARTITION_TYPE, 0, NULL, &psize); test_error( err, "Unable to get CL_DEVICE_PARTITION_TYPE" ); cl_device_partition_property *properties_returned = (cl_device_partition_property *)alloca(psize); - err = clGetDeviceInfo(deviceID, CL_DEVICE_PARTITION_TYPE, psize, (void *) properties_returned, NULL); + err = clGetDeviceInfo(device, CL_DEVICE_PARTITION_TYPE, psize, + (void *)properties_returned, NULL); test_error( err, "Unable to get CL_DEVICE_PARTITION_TYPE" ); // test returned type @@ -480,31 +483,36 @@ int test_partition_of_device(cl_device_id deviceID, cl_context context, cl_comma // loop thru each type, creating sub-devices for each type for (cl_uint i = starting_property;i < ending_property;i++) { - if (test_device_partition_type_support(deviceID, partitionProp[i][0], partitionProp[i][1]) != 0) - { - if (partitionProp[i][0] == CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN) + if (test_device_partition_type_support(device, partitionProp[i][0], + partitionProp[i][1]) + != 0) { - log_info( "Device partition type \"%s\" \"%s\" is not supported on device %p. Skipping test...\n", - printPartition(partitionProp[i][0]), - printAffinity(partitionProp[i][1]), deviceID); - } - else - { - log_info( "Device partition type \"%s\" is not supported on device %p. Skipping test...\n", - printPartition(partitionProp[i][0]), deviceID); - } - continue; + if (partitionProp[i][0] == CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN) + { + log_info("Device partition type \"%s\" \"%s\" is not supported " + "on device %p. Skipping test...\n", + printPartition(partitionProp[i][0]), + printAffinity(partitionProp[i][1]), device); + } + else + { + log_info("Device partition type \"%s\" is not supported on " + "device %p. Skipping test...\n", + printPartition(partitionProp[i][0]), device); + } + continue; } if (partitionProp[i][0] == CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN) { - log_info("Testing on device %p partition type \"%s\" \"%s\"\n", deviceID, printPartition(partitionProp[i][0]), - printAffinity(partitionProp[i][1])); + log_info("Testing on device %p partition type \"%s\" \"%s\"\n", + device, printPartition(partitionProp[i][0]), + printAffinity(partitionProp[i][1])); } else { log_info("Testing on device %p partition type \"%s\" (%d,%d)\n", - deviceID, printPartition(partitionProp[i][0]), + device, printPartition(partitionProp[i][0]), static_cast(partitionProp[i][1]), static_cast(partitionProp[i][2])); } @@ -512,9 +520,9 @@ int test_partition_of_device(cl_device_id deviceID, cl_context context, cl_comma cl_uint deviceCount; // how many sub-devices can we create? - err = clCreateSubDevices(deviceID, partitionProp[i], 0, NULL, &deviceCount); + err = clCreateSubDevices(device, partitionProp[i], 0, NULL, &deviceCount); if ( err == CL_DEVICE_PARTITION_FAILED ) { - log_info( "The device %p could not be further partitioned.\n", deviceID ); + log_info("The device %p could not be further partitioned.\n", device); continue; } test_error( err, "Failed to get number of sub-devices" ); @@ -522,7 +530,8 @@ int test_partition_of_device(cl_device_id deviceID, cl_context context, cl_comma // get the list of subDevices // create room for 1 more device_id, so that we can put the parent device in there. cl_device_id *subDevices = (cl_device_id*)alloca(sizeof(cl_device_id) * (deviceCount + 1)); - err = clCreateSubDevices(deviceID, partitionProp[i], deviceCount, subDevices, &deviceCount); + err = clCreateSubDevices(device, partitionProp[i], deviceCount, + subDevices, &deviceCount); test_error( err, "Actual creation of sub-devices failed" ); log_info("Testing on all devices in context\n"); @@ -532,8 +541,9 @@ int test_partition_of_device(cl_device_id deviceID, cl_context context, cl_comma log_info("Testing on a parent device for context\n"); // add the parent device - subDevices[deviceCount] = deviceID; - err = test_device_set(deviceCount + 1, deviceCount, subDevices, num_elements, &deviceID); + subDevices[deviceCount] = device; + err = test_device_set(deviceCount + 1, deviceCount, subDevices, + num_elements, &device); } if (err != 0) { @@ -557,52 +567,61 @@ int test_partition_of_device(cl_device_id deviceID, cl_context context, cl_comma } // for - log_info("Testing on all device %p finished\n", deviceID); + log_info("Testing on all device %p finished\n", device); return 0; } -int test_partition_equally(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_equally) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 0, 1); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 0, 1); } -int test_partition_by_counts(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_by_counts) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 1, 2); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 1, 2); } -int test_partition_by_affinity_domain_numa(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_by_affinity_domain_numa) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 2, 3); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 2, 3); } -int test_partition_by_affinity_domain_l4_cache(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_by_affinity_domain_l4_cache) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 3, 4); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 3, 4); } -int test_partition_by_affinity_domain_l3_cache(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_by_affinity_domain_l3_cache) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 4, 5); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 4, 5); } -int test_partition_by_affinity_domain_l2_cache(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_by_affinity_domain_l2_cache) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 5, 6); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 5, 6); } -int test_partition_by_affinity_domain_l1_cache(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_by_affinity_domain_l1_cache) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 6, 7); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 6, 7); } -int test_partition_by_affinity_domain_next_partitionable(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_by_affinity_domain_next_partitionable) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 7, 8); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 7, 8); } -int test_partition_all(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +REGISTER_TEST(partition_all) { - return test_partition_of_device(deviceID, context, queue, num_elements, NULL, 0, 8); + return test_partition_of_device(device, context, queue, num_elements, NULL, + 0, 8); }