diff options
Diffstat (limited to 'test/correctness')
-rw-r--r-- | test/correctness/testblas.cc | 45 | ||||
-rw-r--r-- | test/correctness/testblas.h | 47 | ||||
-rw-r--r-- | test/correctness/tester.cc | 16 | ||||
-rw-r--r-- | test/correctness/tester.h | 6 |
4 files changed, 72 insertions, 42 deletions
diff --git a/test/correctness/testblas.cc b/test/correctness/testblas.cc index 1329b2c5..cc9a5adb 100644 --- a/test/correctness/testblas.cc +++ b/test/correctness/testblas.cc @@ -79,24 +79,6 @@ void TestBlas<T,U>::TestRegular(std::vector<Arguments<U>> &test_vector, const st // Iterates over all the to-be-tested combinations of arguments for (auto &args: test_vector) { - // Runs the reference clBLAS code - auto x_vec1 = Buffer<T>(context_, args.x_size); - auto y_vec1 = Buffer<T>(context_, args.y_size); - auto a_mat1 = Buffer<T>(context_, args.a_size); - auto b_mat1 = Buffer<T>(context_, args.b_size); - auto c_mat1 = Buffer<T>(context_, args.c_size); - auto ap_mat1 = Buffer<T>(context_, args.ap_size); - auto scalar1 = Buffer<T>(context_, args.scalar_size); - x_vec1.Write(queue_, args.x_size, x_source_); - y_vec1.Write(queue_, args.y_size, y_source_); - a_mat1.Write(queue_, args.a_size, a_source_); - b_mat1.Write(queue_, args.b_size, b_source_); - c_mat1.Write(queue_, args.c_size, c_source_); - ap_mat1.Write(queue_, args.ap_size, ap_source_); - scalar1.Write(queue_, args.scalar_size, scalar_source_); - auto buffers1 = Buffers<T>{x_vec1, y_vec1, a_mat1, b_mat1, c_mat1, ap_mat1, scalar1}; - auto status1 = run_reference_(args, buffers1, queue_); - // Runs the CLBlast code auto x_vec2 = Buffer<T>(context_, args.x_size); auto y_vec2 = Buffer<T>(context_, args.y_size); @@ -115,6 +97,33 @@ void TestBlas<T,U>::TestRegular(std::vector<Arguments<U>> &test_vector, const st auto buffers2 = Buffers<T>{x_vec2, y_vec2, a_mat2, b_mat2, c_mat2, ap_mat2, scalar2}; auto status2 = run_routine_(args, buffers2, queue_); + #ifndef CLBLAST_REF_CLBLAS + // Don't continue with CBLAS if there are incorrect parameters + if (status2 != StatusCode::kSuccess) { + // TODO: Mark this as a skipped test instead of a succesfull test + TestErrorCodes(status2, status2, args); + continue; + } + #endif + + // Runs the reference BLAS code + auto x_vec1 = Buffer<T>(context_, args.x_size); + auto y_vec1 = Buffer<T>(context_, args.y_size); + auto a_mat1 = Buffer<T>(context_, args.a_size); + auto b_mat1 = Buffer<T>(context_, args.b_size); + auto c_mat1 = Buffer<T>(context_, args.c_size); + auto ap_mat1 = Buffer<T>(context_, args.ap_size); + auto scalar1 = Buffer<T>(context_, args.scalar_size); + x_vec1.Write(queue_, args.x_size, x_source_); + y_vec1.Write(queue_, args.y_size, y_source_); + a_mat1.Write(queue_, args.a_size, a_source_); + b_mat1.Write(queue_, args.b_size, b_source_); + c_mat1.Write(queue_, args.c_size, c_source_); + ap_mat1.Write(queue_, args.ap_size, ap_source_); + scalar1.Write(queue_, args.scalar_size, scalar_source_); + auto buffers1 = Buffers<T>{x_vec1, y_vec1, a_mat1, b_mat1, c_mat1, ap_mat1, scalar1}; + auto status1 = run_reference_(args, buffers1, queue_); + // Tests for equality of the two status codes if (status1 != StatusCode::kSuccess || status2 != StatusCode::kSuccess) { TestErrorCodes(status1, status2, args); diff --git a/test/correctness/testblas.h b/test/correctness/testblas.h index 7c9032bd..8181aaf6 100644 --- a/test/correctness/testblas.h +++ b/test/correctness/testblas.h @@ -68,7 +68,7 @@ class TestBlas: public Tester<T,U> { static const std::vector<Transpose> kTransposes; // Data-type dependent, see .cc-file // Shorthand for the routine-specific functions passed to the tester - using Routine = std::function<StatusCode(const Arguments<U>&, const Buffers<T>&, Queue&)>; + using Routine = std::function<StatusCode(const Arguments<U>&, Buffers<T>&, Queue&)>; using ResultGet = std::function<std::vector<T>(const Arguments<U>&, Buffers<T>&, Queue&)>; using ResultIndex = std::function<size_t(const Arguments<U>&, const size_t, const size_t)>; using ResultIterator = std::function<size_t(const Arguments<U>&)>; @@ -76,8 +76,9 @@ class TestBlas: public Tester<T,U> { // Constructor, initializes the base class tester and input data TestBlas(int argc, char *argv[], const bool silent, const std::string &name, const std::vector<std::string> &options, - const Routine run_routine, const Routine run_reference, const ResultGet get_result, - const ResultIndex get_index, const ResultIterator get_id1, const ResultIterator get_id2); + const Routine run_routine, const Routine run_reference, + const ResultGet get_result, const ResultIndex get_index, + const ResultIterator get_id1, const ResultIterator get_id2); // The test functions, taking no inputs void TestRegular(std::vector<Arguments<U>> &test_vector, const std::string &name); @@ -110,9 +111,17 @@ class TestBlas: public Tester<T,U> { template <typename C, typename T, typename U> void RunTests(int argc, char *argv[], const bool silent, const std::string &name) { + // Sets the reference to test against + #ifdef CLBLAST_REF_CLBLAS + const auto reference_routine = C::RunReference1; // clBLAS when available + #else + const auto reference_routine = C::RunReference2; // otherwise CBLAS + #endif + // Creates a tester auto options = C::GetOptions(); - TestBlas<T,U> tester{argc, argv, silent, name, options, C::RunRoutine, C::RunReference, + TestBlas<T,U> tester{argc, argv, silent, name, options, + C::RunRoutine, reference_routine, C::DownloadResult, C::GetResultIndex, C::ResultID1, C::ResultID2}; // This variable holds the arguments relevant for this routine @@ -250,23 +259,25 @@ void RunTests(int argc, char *argv[], const bool silent, const std::string &name } // Creates the arguments vector for the invalid-buffer tests - auto invalid_test_vector = std::vector<Arguments<U>>{}; - auto i_args = args; - i_args.m = i_args.n = i_args.k = i_args.kl = i_args.ku = tester.kBufferSize; - i_args.a_ld = i_args.b_ld = i_args.c_ld = tester.kBufferSize; - for (auto &x_size: x_sizes) { i_args.x_size = x_size; - for (auto &y_size: y_sizes) { i_args.y_size = y_size; - for (auto &a_size: a_sizes) { i_args.a_size = a_size; - for (auto &b_size: b_sizes) { i_args.b_size = b_size; - for (auto &c_size: c_sizes) { i_args.c_size = c_size; - for (auto &ap_size: ap_sizes) { i_args.ap_size = ap_size; - invalid_test_vector.push_back(i_args); + #ifdef CLBLAST_REF_CLBLAS + auto invalid_test_vector = std::vector<Arguments<U>>{}; + auto i_args = args; + i_args.m = i_args.n = i_args.k = i_args.kl = i_args.ku = tester.kBufferSize; + i_args.a_ld = i_args.b_ld = i_args.c_ld = tester.kBufferSize; + for (auto &x_size: x_sizes) { i_args.x_size = x_size; + for (auto &y_size: y_sizes) { i_args.y_size = y_size; + for (auto &a_size: a_sizes) { i_args.a_size = a_size; + for (auto &b_size: b_sizes) { i_args.b_size = b_size; + for (auto &c_size: c_sizes) { i_args.c_size = c_size; + for (auto &ap_size: ap_sizes) { i_args.ap_size = ap_size; + invalid_test_vector.push_back(i_args); + } } } } } } - } + #endif // Sets the name of this test-case auto names = std::vector<std::string>{}; @@ -287,7 +298,9 @@ void RunTests(int argc, char *argv[], const bool silent, const std::string &name // Runs the tests tester.TestRegular(regular_test_vector, case_name); - tester.TestInvalid(invalid_test_vector, case_name); + #ifdef CLBLAST_REF_CLBLAS + tester.TestInvalid(invalid_test_vector, case_name); + #endif } } } diff --git a/test/correctness/tester.cc b/test/correctness/tester.cc index 8169f700..872a131a 100644 --- a/test/correctness/tester.cc +++ b/test/correctness/tester.cc @@ -69,10 +69,12 @@ Tester<T,U>::Tester(int argc, char *argv[], const bool silent, kUnsupportedPrecision.c_str()); // Initializes clBLAS - auto status = clblasSetup(); - if (status != CL_SUCCESS) { - throw std::runtime_error("clBLAS setup error: "+ToString(static_cast<int>(status))); - } + #ifdef CLBLAST_REF_CLBLAS + auto status = clblasSetup(); + if (status != CL_SUCCESS) { + throw std::runtime_error("clBLAS setup error: "+ToString(static_cast<int>(status))); + } + #endif } // Destructor prints the summary of the test cases and cleans-up the clBLAS library @@ -87,7 +89,11 @@ Tester<T,U>::~Tester() { fprintf(stdout, " %zu test(s) failed%s\n", tests_failed_, kPrintEnd.c_str()); } fprintf(stdout, "\n"); - clblasTeardown(); + + // Cleans-up clBLAS + #ifdef CLBLAST_REF_CLBLAS + clblasTeardown(); + #endif } // ================================================================================================= diff --git a/test/correctness/tester.h b/test/correctness/tester.h index db714f3d..d489f829 100644 --- a/test/correctness/tester.h +++ b/test/correctness/tester.h @@ -23,7 +23,9 @@ #include <memory> // The libraries -#include <clBLAS.h> +#ifdef CLBLAST_REF_CLBLAS + #include <clBLAS.h> +#endif #include "clblast.h" #include "internal/utilities.h" @@ -92,7 +94,7 @@ class Tester { Queue queue_; // Whether or not to run the full test-suite or just a smoke test - bool full_test_; + const bool full_test_; // Retrieves the offset values to test with const std::vector<size_t> GetOffsets() const; |