mirror of
https://github.com/CNugteren/CLBlast.git
synced 2024-07-07 12:23:46 +02:00
Added more relaxed error checking for the half-precision tests
This commit is contained in:
parent
a2bfae3c46
commit
e3076d26cc
|
@ -2,6 +2,7 @@
|
||||||
Development version (next release)
|
Development version (next release)
|
||||||
- It is now possible to set OpenCL compiler options through the env variable CLBLAST_BUILD_OPTIONS
|
- 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
|
- Fixed a bug in the tests and samples related to waiting for an invalid event
|
||||||
|
- Various minor fixes and enhancements
|
||||||
|
|
||||||
Version 0.9.0
|
Version 0.9.0
|
||||||
- Updated to version 6.0 of the CLCudaAPI C++11 OpenCL header
|
- Updated to version 6.0 of the CLCudaAPI C++11 OpenCL header
|
||||||
|
|
|
@ -358,28 +358,33 @@ void Tester<T,U>::PrintErrorLog(const std::vector<ErrorLogEntry> &error_log) {
|
||||||
// Compares two floating point values and returns whether they are within an acceptable error
|
// Compares two floating point values and returns whether they are within an acceptable error
|
||||||
// margin. This replaces GTest's EXPECT_NEAR().
|
// margin. This replaces GTest's EXPECT_NEAR().
|
||||||
template <typename T>
|
template <typename T>
|
||||||
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);
|
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
|
// Shortcut, handles infinities
|
||||||
if (val1 == val2) {
|
if (val1 == val2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// The values are zero or very small: the relative error is less meaningful
|
// The values are zero or very small: the relative error is less meaningful
|
||||||
else if (val1 == 0 || val2 == 0 || difference < kErrorMarginAbsolute) {
|
else if (val1 == 0 || val2 == 0 || difference < error_margin_absolute) {
|
||||||
return (difference < kErrorMarginAbsolute);
|
return (difference < error_margin_absolute);
|
||||||
}
|
}
|
||||||
// Use relative error
|
// Use relative error
|
||||||
else {
|
else {
|
||||||
const auto absolute_sum = std::fabs(val1) + std::fabs(val2);
|
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 <typename T>
|
||||||
|
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
|
// Compiles the default case for standard data-types
|
||||||
template bool TestSimilarity<float>(const float, const float);
|
template bool TestSimilarity<float>(const float, const float);
|
||||||
template bool TestSimilarity<double>(const double, const double);
|
template bool TestSimilarity<double>(const double, const double);
|
||||||
|
@ -399,7 +404,10 @@ bool TestSimilarity(const double2 val1, const double2 val2) {
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
bool TestSimilarity(const half val1, const half val2) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =================================================================================================
|
// =================================================================================================
|
||||||
|
|
Loading…
Reference in a new issue