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.
This commit is contained in:
saurabhnv
2024-09-24 21:25:01 +05:30
committed by GitHub
parent 0c7fbc46e6
commit e865c1e8dd
5 changed files with 152 additions and 45 deletions

View File

@@ -1294,6 +1294,43 @@ cl_platform_id getPlatformFromDevice(cl_device_id deviceID)
return platform; 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<char> 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) void PrintArch(void)
{ {
vlog("sizeof( void*) = %zu\n", sizeof(void *)); vlog("sizeof( void*) = %zu\n", sizeof(void *));

View File

@@ -185,6 +185,10 @@ extern int gHasLong; // This is set to 1 if the device suppots long and ulong
extern bool gCoreILProgram; extern bool gCoreILProgram;
extern cl_platform_id getPlatformFromDevice(cl_device_id deviceID); 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__) #if !defined(__APPLE__)
void memset_pattern4(void *, const void *, size_t); void memset_pattern4(void *, const void *, size_t);

View File

@@ -517,9 +517,10 @@ int test_consistency_external_semaphore(cl_device_id deviceID,
// Pass invalid object to release call // Pass invalid object to release call
errNum = clReleaseSemaphoreKHRptr(NULL); errNum = clReleaseSemaphoreKHRptr(NULL);
test_failure_error(errNum, CL_INVALID_VALUE, test_failure_error(
errNum, CL_INVALID_SEMAPHORE_KHR,
"clReleaseSemaphoreKHRptr fails with " "clReleaseSemaphoreKHRptr fails with "
"CL_INVALID_VALUE when NULL semaphore object is passed"); "CL_INVALID_SEMAPHORE_KHR when NULL semaphore object is passed");
// Release both semaphore objects // Release both semaphore objects
errNum = clReleaseSemaphoreKHRptr(clVk2Clsemaphore); errNum = clReleaseSemaphoreKHRptr(clVk2Clsemaphore);

View File

@@ -1382,7 +1382,7 @@ int run_test_with_multi_import_diff_ctx(
"Failed to set kernel arg"); "Failed to set kernel arg");
err = clEnqueueAcquireExternalMemObjectsKHRptr( err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers2[i][launchIter], 0, cmd_queue2, 1, &buffers2[i][launchIter], 0,
nullptr, nullptr); nullptr, nullptr);
test_error_and_cleanup(err, CLEANUP, test_error_and_cleanup(err, CLEANUP,
"Failed to acquire buffers"); "Failed to acquire buffers");
@@ -1402,7 +1402,7 @@ int run_test_with_multi_import_diff_ctx(
for (int i = 0; i < numBuffers; i++) for (int i = 0; i < numBuffers; i++)
{ {
err = clEnqueueReleaseExternalMemObjectsKHRptr( err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers2[i][launchIter], 0, cmd_queue2, 1, &buffers2[i][launchIter], 0,
nullptr, nullptr); nullptr, nullptr);
test_error_and_cleanup(err, CLEANUP, test_error_and_cleanup(err, CLEANUP,
"Failed to release buffers"); "Failed to release buffers");

View File

@@ -16,9 +16,11 @@
#include <CL/cl.h> #include <CL/cl.h>
#include <CL/cl_ext.h> #include <CL/cl_ext.h>
#include "harness/deviceInfo.h"
#include "harness/testHarness.h" #include "harness/testHarness.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector>
typedef struct typedef struct
{ {
@@ -51,48 +53,64 @@ _info device_info_table[] = {
int test_platform_info(cl_device_id deviceID, cl_context _context, int test_platform_info(cl_device_id deviceID, cl_context _context,
cl_command_queue _queue, int num_elements) cl_command_queue _queue, int num_elements)
{ {
cl_uint num_platforms; cl_uint i;
cl_uint i, j; cl_platform_id platform = getPlatformFromDevice(deviceID);
cl_platform_id *platforms;
cl_int errNum; cl_int errNum;
cl_uint *handle_type; cl_uint *handle_type;
size_t handle_type_size = 0; size_t handle_type_size = 0;
cl_uint num_handles = 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 if (!external_mem_extn_available && !external_sema_extn_available)
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)
{ {
printf("error allocating memory\n"); log_info("Platform does not support 'cl_khr_external_semaphore' "
exit(1); "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]); errNum = clGetPlatformInfo(platform, platform_info_table[i].info, 0,
for (j = 0;
j < sizeof(platform_info_table) / sizeof(platform_info_table[0]);
j++)
{
errNum =
clGetPlatformInfo(platforms[i], platform_info_table[j].info, 0,
NULL, &handle_type_size); NULL, &handle_type_size);
test_error(errNum, "clGetPlatformInfo failed"); test_error(errNum, "clGetPlatformInfo failed");
if (handle_type_size == 0)
{
if (platform_info_table[i].info
== CL_PLATFORM_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",
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); num_handles = handle_type_size / sizeof(cl_uint);
handle_type = (cl_uint *)malloc(handle_type_size); handle_type = (cl_uint *)malloc(handle_type_size);
errNum = errNum = clGetPlatformInfo(platform, platform_info_table[i].info,
clGetPlatformInfo(platforms[i], platform_info_table[j].info,
handle_type_size, handle_type, NULL); handle_type_size, handle_type, NULL);
test_error(errNum, "clGetPlatformInfo failed"); test_error(errNum, "clGetPlatformInfo failed");
log_info("%s: \n", platform_info_table[j].name); log_info("%s: \n", platform_info_table[i].name);
while (num_handles--) while (num_handles--)
{ {
log_info("%x \n", handle_type[num_handles]); log_info("%x \n", handle_type[num_handles]);
@@ -102,11 +120,14 @@ int test_platform_info(cl_device_id deviceID, cl_context _context,
free(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; return TEST_PASS;
} }
@@ -118,6 +139,19 @@ int test_device_info(cl_device_id deviceID, cl_context _context,
size_t handle_type_size = 0; size_t handle_type_size = 0;
cl_uint num_handles = 0; cl_uint num_handles = 0;
cl_int errNum = CL_SUCCESS; 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]); for (j = 0; j < sizeof(device_info_table) / sizeof(device_info_table[0]);
j++) j++)
{ {
@@ -125,6 +159,29 @@ int test_device_info(cl_device_id deviceID, cl_context _context,
&handle_type_size); &handle_type_size);
test_error(errNum, "clGetDeviceInfo failed"); 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); num_handles = handle_type_size / sizeof(cl_uint);
handle_type = (cl_uint *)malloc(handle_type_size); 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); 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; return TEST_PASS;
} }