From 2b770c4f348d9ad71a22c3b949a1cffe32e9d1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Petit?= Date: Wed, 29 Sep 2021 12:38:42 +0100 Subject: [PATCH] Update cl_khr_integer_dot_product tests for v2 (#1317) * Update cl_khr_integer_dot_product tests for v2 Signed-off-by: Kevin Petit Signed-off-by: Marco Cattani Change-Id: I97dbd820f1f32f6b377e47d0bf638f36bb91930a * only query acceleration properties with v2+ Change-Id: I3f13a0cba7f1f686365b10adf81690e089cd3d74 --- test_common/harness/deviceInfo.cpp | 34 ++++++++++ test_common/harness/deviceInfo.h | 5 ++ .../integer_ops/test_integer_dot_product.cpp | 67 +++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/test_common/harness/deviceInfo.cpp b/test_common/harness/deviceInfo.cpp index 287a1423..97ab8c85 100644 --- a/test_common/harness/deviceInfo.cpp +++ b/test_common/harness/deviceInfo.cpp @@ -63,6 +63,40 @@ int is_extension_available(cl_device_id device, const char *extensionName) return false; } +cl_version get_extension_version(cl_device_id device, const char *extensionName) +{ + cl_int err; + size_t size; + + err = clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS_WITH_VERSION, 0, nullptr, + &size); + if (err != CL_SUCCESS) + { + throw std::runtime_error("clGetDeviceInfo(CL_DEVICE_EXTENSIONS_WITH_" + "VERSION) failed to return size\n"); + } + + std::vector extensions(size / sizeof(cl_name_version)); + err = clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS_WITH_VERSION, size, + extensions.data(), &size); + if (err != CL_SUCCESS) + { + throw std::runtime_error("clGetDeviceInfo(CL_DEVICE_EXTENSIONS_WITH_" + "VERSION) failed to return value\n"); + } + + for (auto &ext : extensions) + { + if (!strcmp(extensionName, ext.name)) + { + return ext.version; + } + } + + throw std::runtime_error("Extension " + std::string(extensionName) + + " not supported by device!"); +} + /* Returns a string containing the supported extensions list for a device. */ std::string get_device_extensions_string(cl_device_id device) { diff --git a/test_common/harness/deviceInfo.h b/test_common/harness/deviceInfo.h index f8c55805..912dd198 100644 --- a/test_common/harness/deviceInfo.h +++ b/test_common/harness/deviceInfo.h @@ -31,6 +31,11 @@ std::string get_device_info_string(cl_device_id device, /* Determines if an extension is supported by a device. */ int is_extension_available(cl_device_id device, const char *extensionName); +/* Returns the version of the extension the device supports or throws an + * exception if the extension is not supported by the device. */ +cl_version get_extension_version(cl_device_id device, + const char *extensionName); + /* Returns a string containing the supported extensions list for a device. */ std::string get_device_extensions_string(cl_device_id device); diff --git a/test_conformance/integer_ops/test_integer_dot_product.cpp b/test_conformance/integer_ops/test_integer_dot_product.cpp index be25b320..602d59b6 100644 --- a/test_conformance/integer_ops/test_integer_dot_product.cpp +++ b/test_conformance/integer_ops/test_integer_dot_product.cpp @@ -336,6 +336,21 @@ int test_integer_dot_product(cl_device_id deviceID, cl_context context, return TEST_SKIPPED_ITSELF; } + Version deviceVersion = get_device_cl_version(deviceID); + cl_version extensionVersion; + + if ((deviceVersion >= Version(3, 0)) + || is_extension_available(deviceID, "cl_khr_extended_versioning")) + { + extensionVersion = + get_extension_version(deviceID, "cl_khr_integer_dot_product"); + } + else + { + // Assume 1.0.0 is supported if the version can't be queried + extensionVersion = CL_MAKE_VERSION(1, 0, 0); + } + cl_int error = CL_SUCCESS; int result = TEST_PASS; @@ -346,12 +361,63 @@ int test_integer_dot_product(cl_device_id deviceID, cl_context context, test_error( error, "Unable to query CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR"); + + // Check that the required capabilities are reported test_assert_error( dotCaps & CL_DEVICE_INTEGER_DOT_PRODUCT_INPUT_4x8BIT_PACKED_KHR, "When cl_khr_integer_dot_product is supported " "CL_DEVICE_INTEGER_DOT_PRODUCT_INPUT_4x8BIT_PACKED_KHR must be " "supported"); + if (extensionVersion >= CL_MAKE_VERSION(2, 0, 0)) + { + test_assert_error( + dotCaps & CL_DEVICE_INTEGER_DOT_PRODUCT_INPUT_4x8BIT_KHR, + "When cl_khr_integer_dot_product is supported with version >= 2.0.0" + "CL_DEVICE_INTEGER_DOT_PRODUCT_INPUT_4x8BIT_KHR must be " + "supported"); + } + + // Check that acceleration properties can be queried + if (extensionVersion >= CL_MAKE_VERSION(2, 0, 0)) + { + size_t size_ret; + error = clGetDeviceInfo( + deviceID, + CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR, 0, + nullptr, &size_ret); + test_error( + error, + "Unable to query size of data returned by " + "CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR"); + + cl_device_integer_dot_product_acceleration_properties_khr + accelerationProperties; + error = clGetDeviceInfo( + deviceID, + CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR, + sizeof(accelerationProperties), &accelerationProperties, nullptr); + test_error(error, "Unable to query 8-bit acceleration properties"); + + error = clGetDeviceInfo( + deviceID, + CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_4x8BIT_PACKED_KHR, + 0, nullptr, &size_ret); + test_error( + error, + "Unable to query size of data returned by " + "CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_4x8BIT_" + "PACKED_KHR"); + + error = clGetDeviceInfo( + deviceID, + CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_4x8BIT_PACKED_KHR, + sizeof(accelerationProperties), &accelerationProperties, nullptr); + test_error(error, + "Unable to query 4x8-bit packed acceleration properties"); + } + + // Report when unknown capabilities are found if (dotCaps & ~(CL_DEVICE_INTEGER_DOT_PRODUCT_INPUT_4x8BIT_PACKED_KHR | CL_DEVICE_INTEGER_DOT_PRODUCT_INPUT_4x8BIT_KHR)) @@ -359,6 +425,7 @@ int test_integer_dot_product(cl_device_id deviceID, cl_context context, log_info("NOTE: found an unknown / untested capability!\n"); } + // Test built-in functions if (dotCaps & CL_DEVICE_INTEGER_DOT_PRODUCT_INPUT_4x8BIT_KHR) { result |= test_vectype(deviceID, context, queue,