Skip to content

Commit

Permalink
Use platform of supplied device for platform_info
Browse files Browse the repository at this point in the history
Instead of iterating over all available platform, just
get the platform belonging to the supplied device handle.
  • Loading branch information
saurabhnv committed Aug 16, 2024
1 parent b4c6565 commit 843ba0d
Showing 1 changed file with 55 additions and 78 deletions.
133 changes: 55 additions & 78 deletions test_conformance/vulkan/test_vulkan_platform_device_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,102 +53,79 @@ _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;
cl_int errNum;
cl_uint *handle_type;
size_t handle_type_size = 0;
cl_uint num_handles = 0;
cl_uint num_platforms_skipped = 0;
cl_bool external_mem_extn_available = false;
cl_bool external_sema_extn_available = false;
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");
platform = getPlatformFromDevice(deviceID);

platforms =
(cl_platform_id *)malloc(num_platforms * sizeof(cl_platform_id));
if (!platforms)
{
printf("error allocating memory\n");
exit(1);
external_mem_extn_available =
is_platform_extension_available(platform, "cl_khr_external_semaphore");
external_sema_extn_available =
is_platform_extension_available(platform, "cl_khr_external_memory");
supports_atleast_one_sema_query = false;

if (!external_mem_extn_available && !external_sema_extn_available) {
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++)
{
cl_bool external_mem_extn_available =
is_platform_extension_available(platforms[i], "cl_khr_external_semaphore");
cl_bool external_sema_extn_available =
is_platform_extension_available(platforms[i], "cl_khr_external_memory");
cl_bool supports_atleast_one_sema_query = false;

if (!external_mem_extn_available && !external_sema_extn_available) {
log_info("Platform %d does not support 'cl_khr_external_semaphore' "
"and 'cl_khr_external_memory'. Skipping the test.\n", i);
num_platforms_skipped++;
errNum =
clGetPlatformInfo(platform, platform_info_table[i].info, 0,
NULL, &handle_type_size);
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;
}

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(platforms[i], platform_info_table[j].info, 0,
NULL, &handle_type_size);
test_error(errNum, "clGetPlatformInfo failed");

if (handle_type_size == 0) {
if (platform_info_table[j].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[j].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;
}

if ((platform_info_table[j].info == CL_PLATFORM_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR) ||
(platform_info_table[j].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");

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)
{
free(handle_type);
}
log_info("%s: \n", platform_info_table[i].name);
while (num_handles--)
{
log_info("%x \n", handle_type[num_handles]);
}

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;
if (handle_type)
{
free(handle_type);
}
}
if (platforms)
{
free(platforms);
}

if (num_platforms_skipped == num_platforms) {
return TEST_SKIPPED_ITSELF;
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;
Expand Down

0 comments on commit 843ba0d

Please sign in to comment.