From fe6d92968980543b803d0d4172e71b255c9a1225 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Sun, 8 Dec 2024 11:35:40 -0800 Subject: [PATCH 1/5] fix formatting --- test_conformance/api/test_platform.cpp | 462 +++++++++++++------------ 1 file changed, 239 insertions(+), 223 deletions(-) diff --git a/test_conformance/api/test_platform.cpp b/test_conformance/api/test_platform.cpp index 841612a753..4bb2e91c71 100644 --- a/test_conformance/api/test_platform.cpp +++ b/test_conformance/api/test_platform.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 @@ -22,37 +22,33 @@ #define PRINT_EXTENSION_INFO 0 int test_platform_extensions(cl_device_id deviceID, cl_context context, - cl_command_queue queue, int num_elements) + cl_command_queue queue, int num_elements) { - const char * extensions[] = { - "cl_khr_byte_addressable_store", -// "cl_APPLE_SetMemObjectDestructor", - "cl_khr_global_int32_base_atomics", - "cl_khr_global_int32_extended_atomics", - "cl_khr_local_int32_base_atomics", - "cl_khr_local_int32_extended_atomics", - "cl_khr_int64_base_atomics", - "cl_khr_int64_extended_atomics", -// need to put in entires for various atomics - "cl_khr_3d_image_writes", - "cl_khr_fp16", - "cl_khr_fp64", - NULL - }; + const char *extensions[] = { "cl_khr_byte_addressable_store", + // "cl_APPLE_SetMemObjectDestructor", + "cl_khr_global_int32_base_atomics", + "cl_khr_global_int32_extended_atomics", + "cl_khr_local_int32_base_atomics", + "cl_khr_local_int32_extended_atomics", + "cl_khr_int64_base_atomics", + "cl_khr_int64_extended_atomics", + // need to put in entires for various atomics + "cl_khr_3d_image_writes", "cl_khr_fp16", + "cl_khr_fp64", NULL }; bool extensionsSupported[] = { - false, //"cl_khr_byte_addressable_store", - false, // need to put in entires for various atomics - false, // "cl_khr_global_int32_base_atomics", - false, // "cl_khr_global_int32_extended_atomics", - false, // "cl_khr_local_int32_base_atomics", - false, // "cl_khr_local_int32_extended_atomics", - false, // "cl_khr_int64_base_atomics", - false, // "cl_khr_int64_extended_atomics", - false, //"cl_khr_3d_image_writes", - false, //"cl_khr_fp16", - false, //"cl_khr_fp64", - false //NULL + false, //"cl_khr_byte_addressable_store", + false, // need to put in entires for various atomics + false, // "cl_khr_global_int32_base_atomics", + false, // "cl_khr_global_int32_extended_atomics", + false, // "cl_khr_local_int32_base_atomics", + false, // "cl_khr_local_int32_extended_atomics", + false, // "cl_khr_int64_base_atomics", + false, // "cl_khr_int64_extended_atomics", + false, //"cl_khr_3d_image_writes", + false, //"cl_khr_fp16", + false, //"cl_khr_fp64", + false // NULL }; int extensionIndex; @@ -70,29 +66,26 @@ int test_platform_extensions(cl_device_id deviceID, cl_context context, // pass CL_DEVICE_PLATFORM to clGetDeviceInfo // to get a result of type cl_platform_id - err = clGetDeviceInfo(deviceID, - CL_DEVICE_PLATFORM, - sizeof(cl_platform_id), - (void *)(&platformID), - NULL); + err = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), + (void *)(&platformID), NULL); - if(err != CL_SUCCESS) + if (err != CL_SUCCESS) { - vlog_error("test_platform_extensions : could not get platformID from device\n"); - return -1; + vlog_error("test_platform_extensions : could not get platformID from " + "device\n"); + return -1; } // now we grab the set of extensions specified by the platform - err = clGetPlatformInfo(platformID, - CL_PLATFORM_EXTENSIONS, - sizeof(platform_extensions), - (void *)(&platform_extensions[0]), - NULL); - if(err != CL_SUCCESS) + err = clGetPlatformInfo(platformID, CL_PLATFORM_EXTENSIONS, + sizeof(platform_extensions), + (void *)(&platform_extensions[0]), NULL); + if (err != CL_SUCCESS) { - vlog_error("test_platform_extensions : could not get extension string from platform\n"); - return -1; + vlog_error("test_platform_extensions : could not get extension string " + "from platform\n"); + return -1; } #if PRINT_EXTENSION_INFO @@ -100,30 +93,30 @@ int test_platform_extensions(cl_device_id deviceID, cl_context context, #endif // here we parse the platform extensions, to look for the "important" ones - for(extensionIndex=0; extensions[extensionIndex] != NULL; ++extensionIndex) + for (extensionIndex = 0; extensions[extensionIndex] != NULL; + ++extensionIndex) { - if(strstr(platform_extensions, extensions[extensionIndex]) != NULL) - { - // we found it + if (strstr(platform_extensions, extensions[extensionIndex]) != NULL) + { + // we found it #if PRINT_EXTENSION_INFO - log_info("Found \"%s\" in platform extensions\n", - extensions[extensionIndex]); + log_info("Found \"%s\" in platform extensions\n", + extensions[extensionIndex]); #endif - extensionsSupported[extensionIndex] = true; - } + extensionsSupported[extensionIndex] = true; + } } // and then we grab the set of extensions specified by the device // (this can be turned into a "loop over all devices in this platform") - err = clGetDeviceInfo(deviceID, - CL_DEVICE_EXTENSIONS, - sizeof(device_extensions), - (void *)(&device_extensions[0]), - NULL); - if(err != CL_SUCCESS) + err = clGetDeviceInfo(deviceID, CL_DEVICE_EXTENSIONS, + sizeof(device_extensions), + (void *)(&device_extensions[0]), NULL); + if (err != CL_SUCCESS) { - vlog_error("test_platform_extensions : could not get extension string from device\n"); - return -1; + vlog_error("test_platform_extensions : could not get extension string " + "from device\n"); + return -1; } @@ -131,204 +124,227 @@ int test_platform_extensions(cl_device_id deviceID, cl_context context, log_info("Device extensions include \"%s\"\n\n", device_extensions); #endif - for(extensionIndex=0; extensions[extensionIndex] != NULL; ++extensionIndex) - { - if(extensionsSupported[extensionIndex] == false) + for (extensionIndex = 0; extensions[extensionIndex] != NULL; + ++extensionIndex) { - continue; // skip this one - } + if (extensionsSupported[extensionIndex] == false) + { + continue; // skip this one + } - if(strstr(device_extensions, extensions[extensionIndex]) == NULL) - { - // device does not support it - vlog_error("Platform supports extension \"%s\" but device does not\n", - extensions[extensionIndex]); - return -1; - } + if (strstr(device_extensions, extensions[extensionIndex]) == NULL) + { + // device does not support it + vlog_error( + "Platform supports extension \"%s\" but device does not\n", + extensions[extensionIndex]); + return -1; + } } return 0; } -int test_get_platform_ids(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) { - cl_platform_id platforms[16]; - cl_uint num_platforms; - char *string_returned; - - string_returned = (char*)malloc(8192); - - int total_errors = 0; - int err = CL_SUCCESS; - - - err = clGetPlatformIDs(16, platforms, &num_platforms); - test_error(err, "clGetPlatformIDs failed"); - - if (num_platforms <= 16) { - // Try with NULL - err = clGetPlatformIDs(num_platforms, platforms, NULL); - test_error(err, "clGetPlatformIDs failed with NULL for return size"); - } - - if (num_platforms < 1) { - log_error("Found 0 platforms.\n"); - return -1; - } - log_info("Found %d platforms.\n", num_platforms); +int test_get_platform_ids(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) +{ + cl_platform_id platforms[16]; + cl_uint num_platforms; + char *string_returned; + string_returned = (char *)malloc(8192); - for (int p=0; p<(int)num_platforms; p++) { - cl_device_id *devices; - cl_uint num_devices; - size_t size; + int total_errors = 0; + int err = CL_SUCCESS; - log_info("Platform %d (%p):\n", p, platforms[p]); + err = clGetPlatformIDs(16, platforms, &num_platforms); + test_error(err, "clGetPlatformIDs failed"); - memset(string_returned, 0, 8192); - err = clGetPlatformInfo(platforms[p], CL_PLATFORM_PROFILE, 8192, string_returned, &size); - test_error(err, "clGetPlatformInfo for CL_PLATFORM_PROFILE failed"); - log_info("\tCL_PLATFORM_PROFILE: %s\n", string_returned); - if (strlen(string_returned)+1 != size) { - log_error( - "Returned string length %zu does not equal reported one %zu.\n", - strlen(string_returned) + 1, size); - total_errors++; + if (num_platforms <= 16) + { + // Try with NULL + err = clGetPlatformIDs(num_platforms, platforms, NULL); + test_error(err, "clGetPlatformIDs failed with NULL for return size"); } - memset(string_returned, 0, 8192); - err = clGetPlatformInfo(platforms[p], CL_PLATFORM_VERSION, 8192, string_returned, &size); - test_error(err, "clGetPlatformInfo for CL_PLATFORM_VERSION failed"); - log_info("\tCL_PLATFORM_VERSION: %s\n", string_returned); - if (strlen(string_returned)+1 != size) { - log_error( - "Returned string length %zu does not equal reported one %zu.\n", - strlen(string_returned) + 1, size); - total_errors++; + if (num_platforms < 1) + { + log_error("Found 0 platforms.\n"); + return -1; } + log_info("Found %d platforms.\n", num_platforms); - memset(string_returned, 0, 8192); - err = clGetPlatformInfo(platforms[p], CL_PLATFORM_NAME, 8192, string_returned, &size); - test_error(err, "clGetPlatformInfo for CL_PLATFORM_NAME failed"); - log_info("\tCL_PLATFORM_NAME: %s\n", string_returned); - if (strlen(string_returned)+1 != size) { - log_error( - "Returned string length %zu does not equal reported one %zu.\n", - strlen(string_returned) + 1, size); - total_errors++; - } - memset(string_returned, 0, 8192); - err = clGetPlatformInfo(platforms[p], CL_PLATFORM_VENDOR, 8192, string_returned, &size); - test_error(err, "clGetPlatformInfo for CL_PLATFORM_VENDOR failed"); - log_info("\tCL_PLATFORM_VENDOR: %s\n", string_returned); - if (strlen(string_returned)+1 != size) { - log_error( - "Returned string length %zu does not equal reported one %zu.\n", - strlen(string_returned) + 1, size); - total_errors++; - } + for (int p = 0; p < (int)num_platforms; p++) + { + cl_device_id *devices; + cl_uint num_devices; + size_t size; - memset(string_returned, 0, 8192); - err = clGetPlatformInfo(platforms[p], CL_PLATFORM_EXTENSIONS, 8192, string_returned, &size); - test_error(err, "clGetPlatformInfo for CL_PLATFORM_EXTENSIONS failed"); - log_info("\tCL_PLATFORM_EXTENSIONS: %s\n", string_returned); - if (strlen(string_returned)+1 != size) { - log_error( - "Returned string length %zu does not equal reported one %zu.\n", - strlen(string_returned) + 1, size); - total_errors++; - } - err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices); - test_error(err, "clGetDeviceIDs failed.\n"); - if (num_devices == 0) - { - log_error("clGetDeviceIDs must return at least one device\n"); - total_errors++; - } + log_info("Platform %d (%p):\n", p, platforms[p]); - devices = (cl_device_id *)malloc(num_devices*sizeof(cl_device_id)); - memset(devices, 0, sizeof(cl_device_id)*num_devices); - err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL); - test_error(err, "clGetDeviceIDs failed.\n"); + memset(string_returned, 0, 8192); + err = clGetPlatformInfo(platforms[p], CL_PLATFORM_PROFILE, 8192, + string_returned, &size); + test_error(err, "clGetPlatformInfo for CL_PLATFORM_PROFILE failed"); + log_info("\tCL_PLATFORM_PROFILE: %s\n", string_returned); + if (strlen(string_returned) + 1 != size) + { + log_error( + "Returned string length %zu does not equal reported one %zu.\n", + strlen(string_returned) + 1, size); + total_errors++; + } - log_info("\tPlatform has %d devices.\n", (int)num_devices); - for (int d = 0; d < (int)num_devices; d++) - { - size_t returned_size; - cl_platform_id returned_platform; - cl_context context; - cl_context_properties properties[] = { - CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[p], 0 - }; - - err = clGetDeviceInfo(devices[d], CL_DEVICE_PLATFORM, - sizeof(cl_platform_id), &returned_platform, - &returned_size); - test_error(err, "clGetDeviceInfo failed for CL_DEVICE_PLATFORM\n"); - if (returned_size != sizeof(cl_platform_id)) + memset(string_returned, 0, 8192); + err = clGetPlatformInfo(platforms[p], CL_PLATFORM_VERSION, 8192, + string_returned, &size); + test_error(err, "clGetPlatformInfo for CL_PLATFORM_VERSION failed"); + log_info("\tCL_PLATFORM_VERSION: %s\n", string_returned); + if (strlen(string_returned) + 1 != size) { - log_error("Reported return size (%zu) does not match expected size " - "(%zu).\n", - returned_size, sizeof(cl_platform_id)); + log_error( + "Returned string length %zu does not equal reported one %zu.\n", + strlen(string_returned) + 1, size); total_errors++; } memset(string_returned, 0, 8192); - err = clGetDeviceInfo(devices[d], CL_DEVICE_NAME, 8192, string_returned, - NULL); - test_error(err, "clGetDeviceInfo failed for CL_DEVICE_NAME\n"); - - log_info("\t\tPlatform for device %d (%s) is %p.\n", d, string_returned, - returned_platform); - - log_info("\t\t\tTesting clCreateContext for the platform/device...\n"); - // Try creating a context for the platform - context = clCreateContext(properties, 1, &devices[d], NULL, NULL, &err); - test_error( - err, - "\t\tclCreateContext failed for device with platform properties\n"); - - memset(properties, 0, sizeof(cl_context_properties) * 3); - - err = clGetContextInfo(context, CL_CONTEXT_PROPERTIES, - sizeof(cl_context_properties) * 3, properties, - &returned_size); - test_error(err, "clGetContextInfo for CL_CONTEXT_PROPERTIES failed"); - if (returned_size != sizeof(cl_context_properties) * 3) + err = clGetPlatformInfo(platforms[p], CL_PLATFORM_NAME, 8192, + string_returned, &size); + test_error(err, "clGetPlatformInfo for CL_PLATFORM_NAME failed"); + log_info("\tCL_PLATFORM_NAME: %s\n", string_returned); + if (strlen(string_returned) + 1 != size) { - log_error("Invalid size returned from clGetContextInfo for " - "CL_CONTEXT_PROPERTIES. Got %zu, expected %zu.\n", - returned_size, sizeof(cl_context_properties) * 3); + log_error( + "Returned string length %zu does not equal reported one %zu.\n", + strlen(string_returned) + 1, size); total_errors++; } - if (properties[0] != (cl_context_properties)CL_CONTEXT_PLATFORM - || properties[1] != (cl_context_properties)platforms[p]) + memset(string_returned, 0, 8192); + err = clGetPlatformInfo(platforms[p], CL_PLATFORM_VENDOR, 8192, + string_returned, &size); + test_error(err, "clGetPlatformInfo for CL_PLATFORM_VENDOR failed"); + log_info("\tCL_PLATFORM_VENDOR: %s\n", string_returned); + if (strlen(string_returned) + 1 != size) { log_error( - "Wrong properties returned. Expected: [%p %p], got [%p %p]\n", - (void *)CL_CONTEXT_PLATFORM, platforms[p], - (void *)properties[0], (void *)properties[1]); + "Returned string length %zu does not equal reported one %zu.\n", + strlen(string_returned) + 1, size); total_errors++; } - err = clReleaseContext(context); - test_error(err, "clReleaseContext failed"); - } - free(devices); + memset(string_returned, 0, 8192); + err = clGetPlatformInfo(platforms[p], CL_PLATFORM_EXTENSIONS, 8192, + string_returned, &size); + test_error(err, "clGetPlatformInfo for CL_PLATFORM_EXTENSIONS failed"); + log_info("\tCL_PLATFORM_EXTENSIONS: %s\n", string_returned); + if (strlen(string_returned) + 1 != size) + { + log_error( + "Returned string length %zu does not equal reported one %zu.\n", + strlen(string_returned) + 1, size); + total_errors++; + } - err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_DEFAULT, 0, NULL, - &num_devices); - test_error(err, "clGetDeviceIDs failed.\n"); - if (num_devices != 1) - { - log_error("clGetDeviceIDs must return exactly one device\n"); - total_errors++; + err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, 0, NULL, + &num_devices); + test_error(err, "clGetDeviceIDs failed.\n"); + if (num_devices == 0) + { + log_error("clGetDeviceIDs must return at least one device\n"); + total_errors++; + } + + devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id)); + memset(devices, 0, sizeof(cl_device_id) * num_devices); + err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, num_devices, + devices, NULL); + test_error(err, "clGetDeviceIDs failed.\n"); + + log_info("\tPlatform has %d devices.\n", (int)num_devices); + for (int d = 0; d < (int)num_devices; d++) + { + size_t returned_size; + cl_platform_id returned_platform; + cl_context context; + cl_context_properties properties[] = { + CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[p], 0 + }; + + err = clGetDeviceInfo(devices[d], CL_DEVICE_PLATFORM, + sizeof(cl_platform_id), &returned_platform, + &returned_size); + test_error(err, "clGetDeviceInfo failed for CL_DEVICE_PLATFORM\n"); + if (returned_size != sizeof(cl_platform_id)) + { + log_error( + "Reported return size (%zu) does not match expected size " + "(%zu).\n", + returned_size, sizeof(cl_platform_id)); + total_errors++; + } + + memset(string_returned, 0, 8192); + err = clGetDeviceInfo(devices[d], CL_DEVICE_NAME, 8192, + string_returned, NULL); + test_error(err, "clGetDeviceInfo failed for CL_DEVICE_NAME\n"); + + log_info("\t\tPlatform for device %d (%s) is %p.\n", d, + string_returned, returned_platform); + + log_info( + "\t\t\tTesting clCreateContext for the platform/device...\n"); + // Try creating a context for the platform + context = + clCreateContext(properties, 1, &devices[d], NULL, NULL, &err); + test_error(err, + "\t\tclCreateContext failed for device with platform " + "properties\n"); + + memset(properties, 0, sizeof(cl_context_properties) * 3); + + err = clGetContextInfo(context, CL_CONTEXT_PROPERTIES, + sizeof(cl_context_properties) * 3, + properties, &returned_size); + test_error(err, + "clGetContextInfo for CL_CONTEXT_PROPERTIES failed"); + if (returned_size != sizeof(cl_context_properties) * 3) + { + log_error("Invalid size returned from clGetContextInfo for " + "CL_CONTEXT_PROPERTIES. Got %zu, expected %zu.\n", + returned_size, sizeof(cl_context_properties) * 3); + total_errors++; + } + + if (properties[0] != (cl_context_properties)CL_CONTEXT_PLATFORM + || properties[1] != (cl_context_properties)platforms[p]) + { + log_error("Wrong properties returned. Expected: [%p %p], got " + "[%p %p]\n", + (void *)CL_CONTEXT_PLATFORM, platforms[p], + (void *)properties[0], (void *)properties[1]); + total_errors++; + } + + err = clReleaseContext(context); + test_error(err, "clReleaseContext failed"); + } + free(devices); + + err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_DEFAULT, 0, NULL, + &num_devices); + test_error(err, "clGetDeviceIDs failed.\n"); + if (num_devices != 1) + { + log_error("clGetDeviceIDs must return exactly one device\n"); + total_errors++; + } } - } - free(string_returned); + free(string_returned); - return total_errors; + return total_errors; } From 8080a7f804c20174605a3f7f387402520bd2357e Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Sun, 8 Dec 2024 12:24:17 -0800 Subject: [PATCH 2/5] update and modernize the test for platform extensions --- test_conformance/api/test_platform.cpp | 152 +++++++++---------------- 1 file changed, 53 insertions(+), 99 deletions(-) diff --git a/test_conformance/api/test_platform.cpp b/test_conformance/api/test_platform.cpp index 4bb2e91c71..3f8dfeaef8 100644 --- a/test_conformance/api/test_platform.cpp +++ b/test_conformance/api/test_platform.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The Khronos Group Inc. +// Copyright (c) 2017-2024 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. @@ -17,131 +17,85 @@ #include -#define EXTENSION_NAME_BUF_SIZE 4096 - -#define PRINT_EXTENSION_INFO 0 +#include int test_platform_extensions(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) { - const char *extensions[] = { "cl_khr_byte_addressable_store", - // "cl_APPLE_SetMemObjectDestructor", - "cl_khr_global_int32_base_atomics", - "cl_khr_global_int32_extended_atomics", - "cl_khr_local_int32_base_atomics", - "cl_khr_local_int32_extended_atomics", - "cl_khr_int64_base_atomics", - "cl_khr_int64_extended_atomics", - // need to put in entires for various atomics - "cl_khr_3d_image_writes", "cl_khr_fp16", - "cl_khr_fp64", NULL }; - - bool extensionsSupported[] = { - false, //"cl_khr_byte_addressable_store", - false, // need to put in entires for various atomics - false, // "cl_khr_global_int32_base_atomics", - false, // "cl_khr_global_int32_extended_atomics", - false, // "cl_khr_local_int32_base_atomics", - false, // "cl_khr_local_int32_extended_atomics", - false, // "cl_khr_int64_base_atomics", - false, // "cl_khr_int64_extended_atomics", - false, //"cl_khr_3d_image_writes", - false, //"cl_khr_fp16", - false, //"cl_khr_fp64", - false // NULL - }; - - int extensionIndex; - cl_platform_id platformID; cl_int err; - char platform_extensions[EXTENSION_NAME_BUF_SIZE]; - char device_extensions[EXTENSION_NAME_BUF_SIZE]; - - // Okay, so what we're going to do is just check the device indicated by - // deviceID against the platform that includes this device + err = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), + (void *)(&platformID), NULL); + test_error(err, "clGetDeviceInfo failed for CL_DEVICE_PLATFORM"); + // Note that we read into a vector for tokenization, rather than a string, + // because strtok_r modifies the string. - // pass CL_DEVICE_PLATFORM to clGetDeviceInfo - // to get a result of type cl_platform_id + size_t size = 0; - err = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), - (void *)(&platformID), NULL); + err = clGetPlatformInfo(platformID, CL_PLATFORM_EXTENSIONS, 0, NULL, &size); + test_error(err, + "clGetPlatformInfo failed to get CL_PLATFORM_EXTENSIONS size"); - if (err != CL_SUCCESS) - { - vlog_error("test_platform_extensions : could not get platformID from " - "device\n"); - return -1; - } + std::vector platformExtensions(size); + err = clGetPlatformInfo(platformID, CL_PLATFORM_EXTENSIONS, size, + platformExtensions.data(), NULL); + test_error(err, "clGetPlatformInfo failed for CL_PLATFORM_EXTENSIONS"); + err = clGetDeviceInfo(deviceID, CL_DEVICE_EXTENSIONS, 0, NULL, &size); + test_error(err, "clGetDeviceInfo failed to get CL_DEVICE_EXTENSIONS size"); - // now we grab the set of extensions specified by the platform - err = clGetPlatformInfo(platformID, CL_PLATFORM_EXTENSIONS, - sizeof(platform_extensions), - (void *)(&platform_extensions[0]), NULL); - if (err != CL_SUCCESS) - { - vlog_error("test_platform_extensions : could not get extension string " - "from platform\n"); - return -1; - } + std::vector deviceExtensions(size); + err = clGetDeviceInfo(deviceID, CL_DEVICE_EXTENSIONS, size, + deviceExtensions.data(), NULL); + test_error(err, "clGetDeviceInfo failed for CL_DEVICE_EXTENSIONS"); -#if PRINT_EXTENSION_INFO - log_info("Platform extensions include \"%s\"\n\n", platform_extensions); -#endif + // First, check that all platform extensions are reported by the device. - // here we parse the platform extensions, to look for the "important" ones - for (extensionIndex = 0; extensions[extensionIndex] != NULL; - ++extensionIndex) + for (char *saveptr = nullptr, + *token = strtok_r(platformExtensions.data(), " ", &saveptr); + token != nullptr; token = strtok_r(nullptr, " ", &saveptr)) { - if (strstr(platform_extensions, extensions[extensionIndex]) != NULL) + // log_info("Checking platform extension: %s\n", token); + if (is_extension_available(deviceID, token) == false) { - // we found it -#if PRINT_EXTENSION_INFO - log_info("Found \"%s\" in platform extensions\n", - extensions[extensionIndex]); -#endif - extensionsSupported[extensionIndex] = true; + test_fail("%s is supported by the platform but not by the device\n", + token); } } - // and then we grab the set of extensions specified by the device - // (this can be turned into a "loop over all devices in this platform") - err = clGetDeviceInfo(deviceID, CL_DEVICE_EXTENSIONS, - sizeof(device_extensions), - (void *)(&device_extensions[0]), NULL); - if (err != CL_SUCCESS) - { - vlog_error("test_platform_extensions : could not get extension string " - "from device\n"); - return -1; - } + // Next, check that device extensions reported by all devices are reported + // by the platform. + cl_uint numDevices = 0; + err = clGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, 0, NULL, &numDevices); + test_error(err, "clGetDeviceIDs failed to get number of devices"); -#if PRINT_EXTENSION_INFO - log_info("Device extensions include \"%s\"\n\n", device_extensions); -#endif + std::vector devices(numDevices); + err = clGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, numDevices, + devices.data(), NULL); + test_error(err, "clGetDeviceIDs failed to get device IDs"); - for (extensionIndex = 0; extensions[extensionIndex] != NULL; - ++extensionIndex) + for (char *saveptr = nullptr, + *token = strtok_r(deviceExtensions.data(), " ", &saveptr); + token != nullptr; token = strtok_r(nullptr, " ", &saveptr)) { - if (extensionsSupported[extensionIndex] == false) + // log_info("Checking device extension: %s\n", token); + bool supportedByAllDevices = std::all_of( + devices.begin(), devices.end(), [&](cl_device_id device) { + return is_extension_available(device, token); + }); + if (supportedByAllDevices + && !is_platform_extension_available(platformID, token)) { - continue; // skip this one - } - - if (strstr(device_extensions, extensions[extensionIndex]) == NULL) - { - // device does not support it - vlog_error( - "Platform supports extension \"%s\" but device does not\n", - extensions[extensionIndex]); - return -1; + test_fail( + "%s is supported by all devices but not by the platform\n", + token); } } - return 0; + + return TEST_PASS; } int test_get_platform_ids(cl_device_id deviceID, cl_context context, From 77e99c209c8c1f0afb0946f1a15edbcd2b053b46 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Thu, 12 Dec 2024 16:40:18 -0800 Subject: [PATCH 3/5] add platform extensions Platform extensions may be supported by the platform only, without being supported by devices in the platform. --- test_conformance/api/test_platform.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test_conformance/api/test_platform.cpp b/test_conformance/api/test_platform.cpp index 3f8dfeaef8..feb44dba3b 100644 --- a/test_conformance/api/test_platform.cpp +++ b/test_conformance/api/test_platform.cpp @@ -22,6 +22,15 @@ int test_platform_extensions(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) { + // These extensions are special extensions that may be reported by the + // platform and not by the devices in the platform. + // clang-format off + const std::vector cPlatformExtensions = { + "cl_khr_icd", + "cl_amd_offline_devices", + }; + // clang-format on + cl_platform_id platformID; cl_int err; @@ -58,9 +67,13 @@ int test_platform_extensions(cl_device_id deviceID, cl_context context, token != nullptr; token = strtok_r(nullptr, " ", &saveptr)) { // log_info("Checking platform extension: %s\n", token); - if (is_extension_available(deviceID, token) == false) + bool isPlatformExtension = std::find(cPlatformExtensions.begin(), + cPlatformExtensions.end(), token) + != cPlatformExtensions.end(); + if (!isPlatformExtension && !is_extension_available(deviceID, token)) { - test_fail("%s is supported by the platform but not by the device\n", + test_fail("%s is not a platform extension and is supported by the " + "platform but not by the device\n", token); } } From ec8e5600978822b8c2befdb615b4147ecd163874 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Thu, 12 Dec 2024 17:25:12 -0800 Subject: [PATCH 4/5] modernize tokenization using istringstream --- test_conformance/api/test_platform.cpp | 105 +++++++++++-------------- 1 file changed, 48 insertions(+), 57 deletions(-) diff --git a/test_conformance/api/test_platform.cpp b/test_conformance/api/test_platform.cpp index feb44dba3b..ec3c69ac3f 100644 --- a/test_conformance/api/test_platform.cpp +++ b/test_conformance/api/test_platform.cpp @@ -18,6 +18,7 @@ #include #include +#include int test_platform_extensions(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) @@ -38,73 +39,63 @@ int test_platform_extensions(cl_device_id deviceID, cl_context context, (void *)(&platformID), NULL); test_error(err, "clGetDeviceInfo failed for CL_DEVICE_PLATFORM"); - // Note that we read into a vector for tokenization, rather than a string, - // because strtok_r modifies the string. - - size_t size = 0; - - err = clGetPlatformInfo(platformID, CL_PLATFORM_EXTENSIONS, 0, NULL, &size); - test_error(err, - "clGetPlatformInfo failed to get CL_PLATFORM_EXTENSIONS size"); - - std::vector platformExtensions(size); - err = clGetPlatformInfo(platformID, CL_PLATFORM_EXTENSIONS, size, - platformExtensions.data(), NULL); - test_error(err, "clGetPlatformInfo failed for CL_PLATFORM_EXTENSIONS"); - - err = clGetDeviceInfo(deviceID, CL_DEVICE_EXTENSIONS, 0, NULL, &size); - test_error(err, "clGetDeviceInfo failed to get CL_DEVICE_EXTENSIONS size"); - - std::vector deviceExtensions(size); - err = clGetDeviceInfo(deviceID, CL_DEVICE_EXTENSIONS, size, - deviceExtensions.data(), NULL); - test_error(err, "clGetDeviceInfo failed for CL_DEVICE_EXTENSIONS"); - // First, check that all platform extensions are reported by the device. - - for (char *saveptr = nullptr, - *token = strtok_r(platformExtensions.data(), " ", &saveptr); - token != nullptr; token = strtok_r(nullptr, " ", &saveptr)) { - // log_info("Checking platform extension: %s\n", token); - bool isPlatformExtension = std::find(cPlatformExtensions.begin(), - cPlatformExtensions.end(), token) - != cPlatformExtensions.end(); - if (!isPlatformExtension && !is_extension_available(deviceID, token)) + std::string platformExtensions = + get_platform_info_string(platformID, CL_PLATFORM_EXTENSIONS); + + std::istringstream is(platformExtensions); + std::string token; + while (std::getline(is, token, ' ')) { - test_fail("%s is not a platform extension and is supported by the " - "platform but not by the device\n", - token); + //log_info("Checking platform extension: %s\n", token.c_str()); + bool isPlatformExtension = + std::find(cPlatformExtensions.begin(), + cPlatformExtensions.end(), token) + != cPlatformExtensions.end(); + if (!isPlatformExtension + && !is_extension_available(deviceID, token.c_str())) + { + test_fail( + "%s is not a platform extension and is supported by the " + "platform but not by the device\n", + token.c_str()); + } } } // Next, check that device extensions reported by all devices are reported // by the platform. - - cl_uint numDevices = 0; - err = clGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, 0, NULL, &numDevices); - test_error(err, "clGetDeviceIDs failed to get number of devices"); - - std::vector devices(numDevices); - err = clGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, numDevices, - devices.data(), NULL); - test_error(err, "clGetDeviceIDs failed to get device IDs"); - - for (char *saveptr = nullptr, - *token = strtok_r(deviceExtensions.data(), " ", &saveptr); - token != nullptr; token = strtok_r(nullptr, " ", &saveptr)) { - // log_info("Checking device extension: %s\n", token); - bool supportedByAllDevices = std::all_of( - devices.begin(), devices.end(), [&](cl_device_id device) { - return is_extension_available(device, token); - }); - if (supportedByAllDevices - && !is_platform_extension_available(platformID, token)) + cl_uint numDevices = 0; + err = clGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, 0, NULL, + &numDevices); + test_error(err, "clGetDeviceIDs failed to get number of devices"); + + std::vector devices(numDevices); + err = clGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, numDevices, + devices.data(), NULL); + test_error(err, "clGetDeviceIDs failed to get device IDs"); + + std::string deviceExtensions = + get_device_info_string(deviceID, CL_DEVICE_EXTENSIONS); + + std::istringstream is(deviceExtensions); + std::string token; + while (std::getline(is, token, ' ')) { - test_fail( - "%s is supported by all devices but not by the platform\n", - token); + //log_info("Checking device extension: %s\n", token.c_str()); + bool supportedByAllDevices = std::all_of( + devices.begin(), devices.end(), [&](cl_device_id device) { + return is_extension_available(device, token.c_str()); + }); + if (supportedByAllDevices + && !is_platform_extension_available(platformID, token.c_str())) + { + test_fail( + "%s is supported by all devices but not by the platform\n", + token.c_str()); + } } } From 4e58165dc96f3020f02bbbd7dc5a3321d5a38a8e Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Thu, 12 Dec 2024 17:26:37 -0800 Subject: [PATCH 5/5] formatting fix --- test_conformance/api/test_platform.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_conformance/api/test_platform.cpp b/test_conformance/api/test_platform.cpp index ec3c69ac3f..7175ac7414 100644 --- a/test_conformance/api/test_platform.cpp +++ b/test_conformance/api/test_platform.cpp @@ -48,7 +48,7 @@ int test_platform_extensions(cl_device_id deviceID, cl_context context, std::string token; while (std::getline(is, token, ' ')) { - //log_info("Checking platform extension: %s\n", token.c_str()); + // log_info("Checking platform extension: %s\n", token.c_str()); bool isPlatformExtension = std::find(cPlatformExtensions.begin(), cPlatformExtensions.end(), token) @@ -84,7 +84,7 @@ int test_platform_extensions(cl_device_id deviceID, cl_context context, std::string token; while (std::getline(is, token, ' ')) { - //log_info("Checking device extension: %s\n", token.c_str()); + // log_info("Checking device extension: %s\n", token.c_str()); bool supportedByAllDevices = std::all_of( devices.begin(), devices.end(), [&](cl_device_id device) { return is_extension_available(device, token.c_str());