From e3076d26ccb2bbe0869011d7f0664281f581d1e9 Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Tue, 27 Sep 2016 19:42:58 +0200 Subject: [PATCH] Added more relaxed error checking for the half-precision tests --- CHANGELOG | 1 + test/correctness/tester.cpp | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0c181f2b..4d8c6612 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Development version (next release) - It is now possible to set OpenCL compiler options through the env variable CLBLAST_BUILD_OPTIONS - Fixed a bug in the tests and samples related to waiting for an invalid event +- Various minor fixes and enhancements Version 0.9.0 - Updated to version 6.0 of the CLCudaAPI C++11 OpenCL header diff --git a/test/correctness/tester.cpp b/test/correctness/tester.cpp index 362c5c2c..41e457b6 100644 --- a/test/correctness/tester.cpp +++ b/test/correctness/tester.cpp @@ -358,28 +358,33 @@ void Tester::PrintErrorLog(const std::vector &error_log) { // Compares two floating point values and returns whether they are within an acceptable error // margin. This replaces GTest's EXPECT_NEAR(). template -bool TestSimilarity(const T val1, const T val2) { +bool TestSimilarityNear(const T val1, const T val2, + const T error_margin_absolute, const T error_margin_relative) { const auto difference = std::fabs(val1 - val2); - // Set the allowed error margin for floating-point comparisons - constexpr auto kErrorMarginRelative = T(0.025); - constexpr auto kErrorMarginAbsolute = T(1.0e-3); - // Shortcut, handles infinities if (val1 == val2) { return true; } // The values are zero or very small: the relative error is less meaningful - else if (val1 == 0 || val2 == 0 || difference < kErrorMarginAbsolute) { - return (difference < kErrorMarginAbsolute); + else if (val1 == 0 || val2 == 0 || difference < error_margin_absolute) { + return (difference < error_margin_absolute); } // Use relative error else { const auto absolute_sum = std::fabs(val1) + std::fabs(val2); - return (difference / absolute_sum) < kErrorMarginRelative; + return (difference / absolute_sum) < error_margin_relative; } } +// Default method for similarity testing +template +bool TestSimilarity(const T val1, const T val2) { + constexpr auto kErrorMarginRelative = T(0.025); + constexpr auto kErrorMarginAbsolute = T(0.001); + return TestSimilarityNear(val1, val2, kErrorMarginRelative, kErrorMarginAbsolute); +} + // Compiles the default case for standard data-types template bool TestSimilarity(const float, const float); template bool TestSimilarity(const double, const double); @@ -399,7 +404,10 @@ bool TestSimilarity(const double2 val1, const double2 val2) { } template <> bool TestSimilarity(const half val1, const half val2) { - return TestSimilarity(HalfToFloat(val1), HalfToFloat(val2)); + constexpr auto kErrorMarginRelative = float(0.050); + constexpr auto kErrorMarginAbsolute = float(0.002); + return TestSimilarityNear(HalfToFloat(val1), HalfToFloat(val2), + kErrorMarginRelative, kErrorMarginAbsolute); } // =================================================================================================