diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2017-02-19 17:43:26 +0100 |
---|---|---|
committer | Cedric Nugteren <web@cedricnugteren.nl> | 2017-02-19 17:43:26 +0100 |
commit | 133ebfc83414c4aa0e8fce9f6f7b9d43e6774380 (patch) | |
tree | 572c3754bac2522328d3653766c0a2267843553c /test/routines | |
parent | c248f900c036e1d1644e2cc744c45c94f61c5835 (diff) |
Added data-preparation function for the TRSV tests and special nan/inf checks in the error checking to make the tests pass
Diffstat (limited to 'test/routines')
-rw-r--r-- | test/routines/level2/xtrsv.hpp | 32 |
1 files changed, 32 insertions, 0 deletions
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); |