diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/correctness/tester.cpp | 21 | ||||
-rw-r--r-- | test/routines/level2/xtrsv.hpp | 32 |
2 files changed, 51 insertions, 2 deletions
diff --git a/test/correctness/tester.cpp b/test/correctness/tester.cpp index c0ed5ba4..dd2f3f99 100644 --- a/test/correctness/tester.cpp +++ b/test/correctness/tester.cpp @@ -40,6 +40,12 @@ float getAbsoluteErrorMargin<half>() { return 0.10f; // especially small values are inaccurate for half-precision } +// Error margin: numbers beyond this value are considered equal to inf or NaN +template <typename T> +T getAlmostInfNumber() { + return T{1e35}; // used for correctness testing of TRSV and TRSM routines +} + // Maximum number of test results printed on a single line template <typename T, typename U> const size_t Tester<T,U>::kResultsPerLine = size_t{64}; @@ -426,8 +432,19 @@ bool TestSimilarityNear(const T val1, const T val2, if (val1 == val2) { return true; } - // Handles cases with both results NaN - else if (std::isnan(val1) && std::isnan(val2)) { + // Handles cases with both results NaN or inf + else if ((std::isnan(val1) && std::isnan(val2)) || (std::isinf(val1) && std::isinf(val2))) { + return true; + } + // Also considers it OK if one of the results in NaN and the other is inf + // Note: for TRSV and TRSM routines + else if ((std::isnan(val1) && std::isinf(val2)) || (std::isinf(val1) && std::isnan(val2))) { + return true; + } + // Also considers it OK if one of the values is super large and the other is inf or NaN + // Note: for TRSV and TRSM routines + else if ((std::abs(val1) > getAlmostInfNumber<T>() && (std::isinf(val2) || std::isnan(val2))) || + (std::abs(val2) > getAlmostInfNumber<T>() && (std::isinf(val1) || std::isnan(val1)))) { return true; } // The values are zero or very small: the relative error is less meaningful diff --git a/test/routines/level2/xtrsv.hpp b/test/routines/level2/xtrsv.hpp index 67094b3d..811feac5 100644 --- a/test/routines/level2/xtrsv.hpp +++ b/test/routines/level2/xtrsv.hpp @@ -29,6 +29,35 @@ namespace clblast { // ================================================================================================= +// Prepares the data +template <typename T> +void PrepareData(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { + if (args.a_ld < args.n) { return; } + + // Copies input buffers to the host + std::vector<T> a_mat_cpu(args.a_size, static_cast<T>(0)); + std::vector<T> x_vec_cpu(args.x_size, static_cast<T>(0)); + buffers.a_mat.Read(queue, args.a_size, a_mat_cpu); + buffers.x_vec.Read(queue, args.x_size, x_vec_cpu); + + // Generates 'proper' input for the TRSV routine + // TODO: Improve this, currently loosely based on clBLAS's implementation + for (auto i = size_t{0}; i < args.n; ++i) { + auto diagonal = a_mat_cpu[i*args.a_ld + i + args.a_offset]; + diagonal = AbsoluteValue(diagonal) + static_cast<T>(args.n / size_t{4}); + for (auto j = size_t{0}; j < args.n; ++j) { + a_mat_cpu[j*args.a_ld + i + args.a_offset] /= T{2.0}; + } + a_mat_cpu[i*args.a_ld + i + args.a_offset] = diagonal; + x_vec_cpu[i * args.x_inc + args.x_offset] /= T{2.0}; + } + + // Copies input buffers back to the OpenCL device + buffers.a_mat.Write(queue, args.a_size, a_mat_cpu); + buffers.x_vec.Write(queue, args.x_size, x_vec_cpu); + return; +} + // See comment at top of file for a description of the class template <typename T> class TestXtrsv { @@ -71,6 +100,7 @@ class TestXtrsv { // Describes how to run the CLBlast routine static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { + PrepareData(args, buffers, queue); auto queue_plain = queue(); auto event = cl_event{}; auto status = Trsv<T>(args.layout, args.triangle, args.a_transpose, args.diagonal, @@ -85,6 +115,7 @@ class TestXtrsv { // Describes how to run the clBLAS routine (for correctness/performance comparison) #ifdef CLBLAST_REF_CLBLAS static StatusCode RunReference1(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { + PrepareData(args, buffers, queue); auto queue_plain = queue(); auto event = cl_event{}; auto status = clblasXtrsv<T>(convertToCLBLAS(args.layout), @@ -103,6 +134,7 @@ class TestXtrsv { // Describes how to run the CPU BLAS routine (for correctness/performance comparison) #ifdef CLBLAST_REF_CBLAS static StatusCode RunReference2(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { + PrepareData(args, buffers, queue); std::vector<T> a_mat_cpu(args.a_size, static_cast<T>(0)); std::vector<T> x_vec_cpu(args.x_size, static_cast<T>(0)); buffers.a_mat.Read(queue, args.a_size, a_mat_cpu); |