From 29aab3019ed08f8f185944914ab7a9e8bd493e36 Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Thu, 17 Nov 2016 22:19:36 +0100 Subject: Fixed a bug in the error margins; relaxed the error margins for half-precision --- test/correctness/tester.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/correctness/tester.cpp b/test/correctness/tester.cpp index 5c4435f2..481640fc 100644 --- a/test/correctness/tester.cpp +++ b/test/correctness/tester.cpp @@ -22,6 +22,24 @@ namespace clblast { // ================================================================================================= +// Eror margings (relative and absolute) +template +float getRelativeErrorMargin() { + return 0.005f; // 0.5% is considered acceptable for float/double-precision +} +template <> +float getRelativeErrorMargin() { + return 0.080f; // 8% (!) error is considered acceptable for half-precision +} +template +float getAbsoluteErrorMargin() { + return 0.001f; +} +template <> +float getAbsoluteErrorMargin() { + return 0.10f; // especially small values are inaccurate for half-precision +} + // Maximum number of test results printed on a single line template const size_t Tester::kResultsPerLine = size_t{64}; @@ -118,6 +136,8 @@ Tester::Tester(int argc, char *argv[], const bool silent, kUnsupportedPrecision.c_str()); fprintf(stdout, " %s -> Test not completed: Reference CBLAS doesn't output error codes\n", kUnsupportedReference.c_str()); + fprintf(stdout, "* Testing with error margins of %.1lf%% (relative) and %.3lf (absolute)\n", + 100.0f * getRelativeErrorMargin(), getAbsoluteErrorMargin()); // Initializes clBLAS #ifdef CLBLAST_REF_CLBLAS @@ -404,9 +424,9 @@ bool TestSimilarityNear(const T val1, const T val2, // 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); + const auto kErrorMarginRelative = static_cast(getRelativeErrorMargin()); + const auto kErrorMarginAbsolute = static_cast(getAbsoluteErrorMargin()); + return TestSimilarityNear(val1, val2, kErrorMarginAbsolute, kErrorMarginRelative); } // Compiles the default case for standard data-types @@ -428,10 +448,10 @@ bool TestSimilarity(const double2 val1, const double2 val2) { } template <> bool TestSimilarity(const half val1, const half val2) { - constexpr auto kErrorMarginRelative = float(0.050); - constexpr auto kErrorMarginAbsolute = float(0.002); + const auto kErrorMarginRelative = getRelativeErrorMargin(); + const auto kErrorMarginAbsolute = getAbsoluteErrorMargin(); return TestSimilarityNear(HalfToFloat(val1), HalfToFloat(val2), - kErrorMarginRelative, kErrorMarginAbsolute); + kErrorMarginAbsolute, kErrorMarginRelative); } // ================================================================================================= -- cgit v1.2.3