From e865c1e8dd7491b2bce1876781aae3806399ce92 Mon Sep 17 00:00:00 2001 From: saurabhnv <156190705+saurabhnv@users.noreply.github.com> Date: Tue, 24 Sep 2024 21:25:01 +0530 Subject: [PATCH] Fix vulkan subtest for diffCtx and platform/device info (#2046) Fixes: 1. Multi import diff ctx subtest which acquires/releases external memory via queue not associated with the context in which memory was imported. 2. Platform/Device info subtests to handle different platforms and availability of the query. --- test_common/harness/testHarness.cpp | 37 +++++ test_common/harness/testHarness.h | 4 + .../vulkan/test_vulkan_api_consistency.cpp | 7 +- .../vulkan/test_vulkan_interop_buffer.cpp | 4 +- .../test_vulkan_platform_device_info.cpp | 145 +++++++++++++----- 5 files changed, 152 insertions(+), 45 deletions(-) diff --git a/test_common/harness/testHarness.cpp b/test_common/harness/testHarness.cpp index 0e3c49e9a3..99aaf7c6a0 100644 --- a/test_common/harness/testHarness.cpp +++ b/test_common/harness/testHarness.cpp @@ -1294,6 +1294,43 @@ cl_platform_id getPlatformFromDevice(cl_device_id deviceID) return platform; } +/** + * Helper to return a string containing platform information + * for the specified platform info parameter. + */ +std::string get_platform_info_string(cl_platform_id platform, + cl_platform_info param_name) +{ + size_t size = 0; + int err; + + if ((err = clGetPlatformInfo(platform, param_name, 0, NULL, &size)) + != CL_SUCCESS + || size == 0) + { + throw std::runtime_error("clGetPlatformInfo failed\n"); + } + + std::vector info(size); + + if ((err = clGetPlatformInfo(platform, param_name, size, info.data(), NULL)) + != CL_SUCCESS) + { + throw std::runtime_error("clGetPlatformInfo failed\n"); + } + + /* The returned string does not include the null terminator. */ + return std::string(info.data(), size - 1); +} + +bool is_platform_extension_available(cl_platform_id platform, + const char *extensionName) +{ + std::string extString = + get_platform_info_string(platform, CL_PLATFORM_EXTENSIONS); + return extString.find(extensionName) != std::string::npos; +} + void PrintArch(void) { vlog("sizeof( void*) = %zu\n", sizeof(void *)); diff --git a/test_common/harness/testHarness.h b/test_common/harness/testHarness.h index b266db80f4..524e604791 100644 --- a/test_common/harness/testHarness.h +++ b/test_common/harness/testHarness.h @@ -185,6 +185,10 @@ extern int gHasLong; // This is set to 1 if the device suppots long and ulong extern bool gCoreILProgram; extern cl_platform_id getPlatformFromDevice(cl_device_id deviceID); +extern std::string get_platform_info_string(cl_platform_id platform, + cl_platform_info param_name); +extern bool is_platform_extension_available(cl_platform_id platform, + const char *extensionName); #if !defined(__APPLE__) void memset_pattern4(void *, const void *, size_t); diff --git a/test_conformance/vulkan/test_vulkan_api_consistency.cpp b/test_conformance/vulkan/test_vulkan_api_consistency.cpp index fe06052e10..09e02981a6 100644 --- a/test_conformance/vulkan/test_vulkan_api_consistency.cpp +++ b/test_conformance/vulkan/test_vulkan_api_consistency.cpp @@ -517,9 +517,10 @@ int test_consistency_external_semaphore(cl_device_id deviceID, // Pass invalid object to release call errNum = clReleaseSemaphoreKHRptr(NULL); - test_failure_error(errNum, CL_INVALID_VALUE, - "clReleaseSemaphoreKHRptr fails with " - "CL_INVALID_VALUE when NULL semaphore object is passed"); + test_failure_error( + errNum, CL_INVALID_SEMAPHORE_KHR, + "clReleaseSemaphoreKHRptr fails with " + "CL_INVALID_SEMAPHORE_KHR when NULL semaphore object is passed"); // Release both semaphore objects errNum = clReleaseSemaphoreKHRptr(clVk2Clsemaphore); diff --git a/test_conformance/vulkan/test_vulkan_interop_buffer.cpp b/test_conformance/vulkan/test_vulkan_interop_buffer.cpp index b010fdb5bc..222dde8aba 100644 --- a/test_conformance/vulkan/test_vulkan_interop_buffer.cpp +++ b/test_conformance/vulkan/test_vulkan_interop_buffer.cpp @@ -1382,7 +1382,7 @@ int run_test_with_multi_import_diff_ctx( "Failed to set kernel arg"); err = clEnqueueAcquireExternalMemObjectsKHRptr( - cmd_queue1, 1, &buffers2[i][launchIter], 0, + cmd_queue2, 1, &buffers2[i][launchIter], 0, nullptr, nullptr); test_error_and_cleanup(err, CLEANUP, "Failed to acquire buffers"); @@ -1402,7 +1402,7 @@ int run_test_with_multi_import_diff_ctx( for (int i = 0; i < numBuffers; i++) { err = clEnqueueReleaseExternalMemObjectsKHRptr( - cmd_queue1, 1, &buffers2[i][launchIter], 0, + cmd_queue2, 1, &buffers2[i][launchIter], 0, nullptr, nullptr); test_error_and_cleanup(err, CLEANUP, "Failed to release buffers"); diff --git a/test_conformance/vulkan/test_vulkan_platform_device_info.cpp b/test_conformance/vulkan/test_vulkan_platform_device_info.cpp index 12f373b5c5..1c25c0f58a 100644 --- a/test_conformance/vulkan/test_vulkan_platform_device_info.cpp +++ b/test_conformance/vulkan/test_vulkan_platform_device_info.cpp @@ -16,9 +16,11 @@ #include #include +#include "harness/deviceInfo.h" #include "harness/testHarness.h" #include #include +#include typedef struct { @@ -51,62 +53,81 @@ _info device_info_table[] = { int test_platform_info(cl_device_id deviceID, cl_context _context, cl_command_queue _queue, int num_elements) { - cl_uint num_platforms; - cl_uint i, j; - cl_platform_id *platforms; + cl_uint i; + cl_platform_id platform = getPlatformFromDevice(deviceID); cl_int errNum; cl_uint *handle_type; size_t handle_type_size = 0; cl_uint num_handles = 0; + cl_bool external_mem_extn_available = + is_platform_extension_available(platform, "cl_khr_external_semaphore"); + cl_bool external_sema_extn_available = + is_platform_extension_available(platform, "cl_khr_external_memory"); + cl_bool supports_atleast_one_sema_query = false; - // get total # of platforms - errNum = clGetPlatformIDs(0, NULL, &num_platforms); - test_error(errNum, "clGetPlatformIDs (getting count) failed"); - - platforms = - (cl_platform_id *)malloc(num_platforms * sizeof(cl_platform_id)); - if (!platforms) + if (!external_mem_extn_available && !external_sema_extn_available) { - printf("error allocating memory\n"); - exit(1); + log_info("Platform does not support 'cl_khr_external_semaphore' " + "and 'cl_khr_external_memory'. Skipping the test.\n"); + return TEST_SKIPPED_ITSELF; } - log_info("%d platforms available\n", num_platforms); - errNum = clGetPlatformIDs(num_platforms, platforms, NULL); - test_error(errNum, "clGetPlatformIDs (getting IDs) failed"); - for (i = 0; i < num_platforms; i++) + log_info("Platform (id %lu) info:\n", (unsigned long)platform); + + for (i = 0; + i < sizeof(platform_info_table) / sizeof(platform_info_table[0]); i++) { - log_info("Platform%d (id %lu) info:\n", i, (unsigned long)platforms[i]); - for (j = 0; - j < sizeof(platform_info_table) / sizeof(platform_info_table[0]); - j++) + errNum = clGetPlatformInfo(platform, platform_info_table[i].info, 0, + NULL, &handle_type_size); + test_error(errNum, "clGetPlatformInfo failed"); + + if (handle_type_size == 0) { - errNum = - clGetPlatformInfo(platforms[i], platform_info_table[j].info, 0, - NULL, &handle_type_size); - test_error(errNum, "clGetPlatformInfo failed"); - num_handles = handle_type_size / sizeof(cl_uint); - handle_type = (cl_uint *)malloc(handle_type_size); - errNum = - clGetPlatformInfo(platforms[i], platform_info_table[j].info, - handle_type_size, handle_type, NULL); - test_error(errNum, "clGetPlatformInfo failed"); - - log_info("%s: \n", platform_info_table[j].name); - while (num_handles--) - { - log_info("%x \n", handle_type[num_handles]); - } - if (handle_type) + if (platform_info_table[i].info + == CL_PLATFORM_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR + && external_mem_extn_available) { - free(handle_type); + test_fail( + "External memory import handle types should be reported if " + "cl_khr_external_memory is available.\n"); } + log_info("%s not supported. Skipping the query.\n", + platform_info_table[i].name); + continue; + } + + if ((platform_info_table[i].info + == CL_PLATFORM_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR) + || (platform_info_table[i].info + == CL_PLATFORM_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR)) + { + supports_atleast_one_sema_query = true; + } + + num_handles = handle_type_size / sizeof(cl_uint); + handle_type = (cl_uint *)malloc(handle_type_size); + errNum = clGetPlatformInfo(platform, platform_info_table[i].info, + handle_type_size, handle_type, NULL); + test_error(errNum, "clGetPlatformInfo failed"); + + log_info("%s: \n", platform_info_table[i].name); + while (num_handles--) + { + log_info("%x \n", handle_type[num_handles]); + } + if (handle_type) + { + free(handle_type); } } - if (platforms) + + if (external_sema_extn_available && !supports_atleast_one_sema_query) { - free(platforms); + log_info("External semaphore import/export or both should be supported " + "if cl_khr_external_semaphore is available.\n"); + return TEST_FAIL; } + return TEST_PASS; } @@ -118,6 +139,19 @@ int test_device_info(cl_device_id deviceID, cl_context _context, size_t handle_type_size = 0; cl_uint num_handles = 0; cl_int errNum = CL_SUCCESS; + cl_bool external_mem_extn_available = + is_extension_available(deviceID, "cl_khr_external_memory"); + cl_bool external_sema_extn_available = + is_extension_available(deviceID, "cl_khr_external_semaphore"); + cl_bool supports_atleast_one_sema_query = false; + + if (!external_mem_extn_available && !external_sema_extn_available) + { + log_info("Device does not support 'cl_khr_external_semaphore' " + "and 'cl_khr_external_memory'. Skipping the test.\n"); + return TEST_SKIPPED_ITSELF; + } + for (j = 0; j < sizeof(device_info_table) / sizeof(device_info_table[0]); j++) { @@ -125,6 +159,29 @@ int test_device_info(cl_device_id deviceID, cl_context _context, &handle_type_size); test_error(errNum, "clGetDeviceInfo failed"); + if (handle_type_size == 0) + { + if (device_info_table[j].info + == CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR + && external_mem_extn_available) + { + test_fail( + "External memory import handle types should be reported if " + "cl_khr_external_memory is available.\n"); + } + log_info("%s not supported. Skipping the query.\n", + device_info_table[j].name); + continue; + } + + if ((device_info_table[j].info + == CL_DEVICE_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR) + || (device_info_table[j].info + == CL_DEVICE_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR)) + { + supports_atleast_one_sema_query = true; + } + num_handles = handle_type_size / sizeof(cl_uint); handle_type = (cl_uint *)malloc(handle_type_size); @@ -142,5 +199,13 @@ int test_device_info(cl_device_id deviceID, cl_context _context, free(handle_type); } } + + if (external_sema_extn_available && !supports_atleast_one_sema_query) + { + log_info("External semaphore import/export or both should be supported " + "if cl_khr_external_semaphore is available.\n"); + return TEST_FAIL; + } + return TEST_PASS; }