From 1a3e19c37e5655f1692376f16f3df442afaa8b49 Mon Sep 17 00:00:00 2001 From: Alastair Murray Date: Tue, 22 Sep 2020 21:49:13 +0100 Subject: [PATCH] Use Version type for cl_khr_spir extension version checks (#953) * Use Version type for cl_khr_spir extension version checks The current method of using `std::find(versions, 1.2f)` is unreliable due to performing a floating point comparison. I.e. on some compiles it will spuriously report that the required version is missing and skip the tests. * Address clang-format failure. * Correct typo. --- test_conformance/spir/main.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test_conformance/spir/main.cpp b/test_conformance/spir/main.cpp index 5634d5b6..3a18988c 100644 --- a/test_conformance/spir/main.cpp +++ b/test_conformance/spir/main.cpp @@ -141,7 +141,8 @@ static bool is_dir_exits(const char* path) return false; } -static void get_spir_version(cl_device_id device, std::vector& versions) +static void get_spir_version(cl_device_id device, + std::vector &versions) { char version[64] = {0}; cl_int err; @@ -162,11 +163,11 @@ static void get_spir_version(cl_device_id device, std::vector& versions) std::copy(std::istream_iterator(versionStream), std::istream_iterator(), std::back_inserter(versionVector)); - for(std::list::const_iterator it = versionVector.begin(), - e = versionVector.end(); it != e; - it++) + for (auto &v : versionVector) { - versions.push_back(atof(it->c_str())); + auto major = v[v.find('.') - 1]; + auto minor = v[v.find('.') + 1]; + versions.push_back(Version{ major - '0', minor - '0' }); } } @@ -6929,10 +6930,12 @@ int main (int argc, const char* argv[]) cl_device_id device = get_platform_device(device_type, choosen_device_index, choosen_platform_index); printDeviceHeader(device); - std::vector versions; + std::vector versions; get_spir_version(device, versions); - if (!is_extension_available( device, "cl_khr_spir") || - std::find(versions.begin(), versions.end(), 1.2f) == versions.end()) + + if (!is_extension_available(device, "cl_khr_spir") + || (std::find(versions.begin(), versions.end(), Version{ 1, 2 }) + == versions.end())) { log_info("Spir extension version 1.2 is not supported by the device\n"); return 0;