From e5c0edbfd7dcfe96af6cca6c25ca8b346871b014 Mon Sep 17 00:00:00 2001 From: CNugteren Date: Sun, 28 Jun 2015 15:52:57 +0200 Subject: Re-organized the test infrastructure to avoid code duplication --- CMakeLists.txt | 48 ++------ test/correctness/routines/xaxpy.cc | 86 +++++++------- test/correctness/routines/xgemm.cc | 124 ++++++++++---------- test/correctness/routines/xgemv.cc | 113 ++++++++++--------- test/correctness/routines/xsymm.cc | 122 ++++++++++---------- test/correctness/routines/xsyr2k.cc | 123 ++++++++++---------- test/correctness/routines/xsyrk.cc | 114 +++++++++---------- test/correctness/testab.cc | 192 ------------------------------- test/correctness/testab.h | 85 -------------- test/correctness/testabc.cc | 218 ------------------------------------ test/correctness/testabc.h | 86 -------------- test/correctness/testac.cc | 191 ------------------------------- test/correctness/testac.h | 85 -------------- test/correctness/testaxy.cc | 213 ----------------------------------- test/correctness/testaxy.h | 88 --------------- test/correctness/testblas.cc | 185 ++++++++++++++++++++++++++++++ test/correctness/testblas.h | 104 +++++++++++++++++ test/correctness/tester.cc | 10 -- test/correctness/tester.h | 4 - test/correctness/testxy.cc | 176 ----------------------------- test/correctness/testxy.h | 84 -------------- test/routines/xaxpy.h | 94 ++++++++++++++++ test/routines/xgemm.h | 114 +++++++++++++++++++ test/routines/xgemv.h | 112 ++++++++++++++++++ test/routines/xsymm.h | 114 +++++++++++++++++++ test/routines/xsyr2k.h | 110 ++++++++++++++++++ test/routines/xsyrk.h | 102 +++++++++++++++++ 27 files changed, 1295 insertions(+), 1802 deletions(-) delete mode 100644 test/correctness/testab.cc delete mode 100644 test/correctness/testab.h delete mode 100644 test/correctness/testabc.cc delete mode 100644 test/correctness/testabc.h delete mode 100644 test/correctness/testac.cc delete mode 100644 test/correctness/testac.h delete mode 100644 test/correctness/testaxy.cc delete mode 100644 test/correctness/testaxy.h create mode 100644 test/correctness/testblas.cc create mode 100644 test/correctness/testblas.h delete mode 100644 test/correctness/testxy.cc delete mode 100644 test/correctness/testxy.h create mode 100644 test/routines/xaxpy.h create mode 100644 test/routines/xgemm.h create mode 100644 test/routines/xgemv.h create mode 100644 test/routines/xsymm.h create mode 100644 test/routines/xsyr2k.h create mode 100644 test/routines/xsyrk.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a1ec976..60b1aaed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,12 +95,10 @@ include_directories(${clblast_SOURCE_DIR}/include ${OPENCL_INCLUDE_DIRS}) # Sets the supported routines and the used kernels. New routines and kernels should be added here. set(KERNELS copy pad transpose padtranspose xaxpy xgemv xgemm) set(SAMPLE_PROGRAMS sgemm) -set(ROUTINES_XY xaxpy) -set(ROUTINES_AXY xgemv) -set(ROUTINES_ABC xgemm xsymm xsyr2k) -set(ROUTINES_AB ) -set(ROUTINES_AC xsyrk) -set(ROUTINES ${ROUTINES_XY} ${ROUTINES_AXY} ${ROUTINES_ABC} ${ROUTINES_AB} ${ROUTINES_AC}) +set(ROUTINES + xaxpy + xgemv + xgemm xsymm xsyrk xsyr2k) # ================================================================================================== @@ -170,45 +168,14 @@ if(TESTS) include_directories(${clblast_SOURCE_DIR}/test ${clBLAS_SOURCE_DIR}) # Creates the common correctness-tests objects (requires CMake 2.8.8) - add_library(test_correctness_common OBJECT test/correctness/tester.cc) - add_library(test_correctness_xy OBJECT test/correctness/testxy.cc) - add_library(test_correctness_axy OBJECT test/correctness/testaxy.cc) - add_library(test_correctness_abc OBJECT test/correctness/testabc.cc) - add_library(test_correctness_ab OBJECT test/correctness/testab.cc) - add_library(test_correctness_ac OBJECT test/correctness/testac.cc) + add_library(test_correctness_common OBJECT + test/correctness/tester.cc test/correctness/testblas.cc) # Compiles the correctness-tests - foreach(ROUTINE ${ROUTINES_XY}) - add_executable(test_${ROUTINE} - $ - $ - test/correctness/routines/${ROUTINE}.cc) - endforeach() - foreach(ROUTINE ${ROUTINES_AXY}) - add_executable(test_${ROUTINE} - $ - $ - test/correctness/routines/${ROUTINE}.cc) - endforeach() - foreach(ROUTINE ${ROUTINES_ABC}) - add_executable(test_${ROUTINE} - $ - $ - test/correctness/routines/${ROUTINE}.cc) - endforeach() - foreach(ROUTINE ${ROUTINES_AB}) - add_executable(test_${ROUTINE} - $ - $ - test/correctness/routines/${ROUTINE}.cc) - endforeach() - foreach(ROUTINE ${ROUTINES_AC}) + foreach(ROUTINE ${ROUTINES}) add_executable(test_${ROUTINE} $ - $ test/correctness/routines/${ROUTINE}.cc) - endforeach() - foreach(ROUTINE ${ROUTINES}) target_link_libraries(test_${ROUTINE} clBLAS clblast ${OPENCL_LIBRARIES}) install(TARGETS test_${ROUTINE} DESTINATION bin) endforeach() @@ -217,7 +184,6 @@ if(TESTS) add_library(test_performance_common OBJECT test/performance/client.cc) # Compiles the performance-tests - set(TEST_PERF_COMM ) foreach(ROUTINE ${ROUTINES}) add_executable(client_${ROUTINE} $ test/performance/routines/${ROUTINE}.cc) diff --git a/test/correctness/routines/xaxpy.cc b/test/correctness/routines/xaxpy.cc index 45dcf6bb..5922a96d 100644 --- a/test/correctness/routines/xaxpy.cc +++ b/test/correctness/routines/xaxpy.cc @@ -7,57 +7,63 @@ // Author(s): // Cedric Nugteren // -// This file implements the tests for the Xaxpy routine. It is based on the TestXY class. +// This file implements the tests for the Xaxpy routine. // // ================================================================================================= -#include "wrapper_clblas.h" -#include "correctness/testxy.h" +#include "correctness/testblas.h" +#include "routines/xaxpy.h" namespace clblast { // ================================================================================================= -// The correctness tester, containing the function calls to CLBlast and to clBLAS for comparison. +// The correctness tester template -void XaxpyTest(int argc, char *argv[], const bool silent, const std::string &name) { +void RunTest(int argc, char *argv[], const bool silent, const std::string &name) { - // Creates the CLBlast lambda - auto clblast_lambda = [](const Arguments &args, - const Buffer &x_vec, const Buffer &y_vec, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - return Axpy(args.n, args.alpha, - x_vec(), args.x_offset, args.x_inc, - y_vec(), args.y_offset, args.y_inc, - &queue_plain, &event); - }; - - // Creates the clBLAS lambda (for comparison) - auto clblas_lambda = [](const Arguments &args, - const Buffer &x_vec, const Buffer &y_vec, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - auto status = clblasXaxpy(args.n, args.alpha, - x_vec(), args.x_offset, args.x_inc, - y_vec(), args.y_offset, args.y_inc, - 1, &queue_plain, 0, nullptr, &event); - return static_cast(status); - }; + // Creates a tester + TestBlas tester{argc, argv, silent, name, TestXaxpy::GetOptions(), + TestXaxpy::RunRoutine, TestXaxpy::RunReference, + TestXaxpy::DownloadResult, TestXaxpy::GetResultIndex, + TestXaxpy::ResultID1, TestXaxpy::ResultID2}; - // Initializes the arguments relevant for this routine + // This variable holds the arguments relevant for this routine auto args = Arguments{}; - const auto options = std::vector{kArgN, kArgXInc, kArgYInc, - kArgXOffset, kArgYOffset, kArgAlpha}; - // Creates a tester - TestXY tester{argc, argv, silent, name, options, clblast_lambda, clblas_lambda}; + // Creates the arguments vector for the regular tests + auto regular_test_vector = std::vector>{}; + for (auto &n: tester.kVectorDims) { args.n = n; + for (auto &x_inc: tester.kIncrements) { args.x_inc = x_inc; + for (auto &x_offset: tester.kOffsets) { args.x_offset = x_offset; + for (auto &y_inc: tester.kIncrements) { args.y_inc = y_inc; + for (auto &y_offset: tester.kOffsets) { args.y_offset = y_offset; + for (auto &alpha: tester.kAlphaValues) { args.alpha = alpha; + args.x_size = TestXaxpy::GetSizeX(args); + args.y_size = TestXaxpy::GetSizeY(args); + if (args.x_size<1 || args.y_size<1) { continue; } + regular_test_vector.push_back(args); + } + } + } + } + } + } + + // Creates the arguments vector for the invalid-buffer tests + auto invalid_test_vector = std::vector>{}; + args.n = tester.kBufferSize; + args.x_inc = args.y_inc = 1; + args.x_offset = args.y_offset = 0; + for (auto &x_size: tester.kVecSizes) { args.x_size = x_size; + for (auto &y_size: tester.kVecSizes) { args.y_size = y_size; + invalid_test_vector.push_back(args); + } + } // Runs the tests const auto case_name = "default"; - tester.TestRegular(args, case_name); - tester.TestInvalidBufferSizes(args, case_name); + tester.TestRegular(regular_test_vector, case_name); + tester.TestInvalid(invalid_test_vector, case_name); } // ================================================================================================= @@ -65,10 +71,10 @@ void XaxpyTest(int argc, char *argv[], const bool silent, const std::string &nam // Main function (not within the clblast namespace) int main(int argc, char *argv[]) { - clblast::XaxpyTest(argc, argv, false, "SAXPY"); - clblast::XaxpyTest(argc, argv, true, "DAXPY"); - clblast::XaxpyTest(argc, argv, true, "CAXPY"); - clblast::XaxpyTest(argc, argv, true, "ZAXPY"); + clblast::RunTest(argc, argv, false, "SAXPY"); + clblast::RunTest(argc, argv, true, "DAXPY"); + clblast::RunTest(argc, argv, true, "CAXPY"); + clblast::RunTest(argc, argv, true, "ZAXPY"); return 0; } diff --git a/test/correctness/routines/xgemm.cc b/test/correctness/routines/xgemm.cc index b829aaa3..2c0a3492 100644 --- a/test/correctness/routines/xgemm.cc +++ b/test/correctness/routines/xgemm.cc @@ -7,77 +7,81 @@ // Author(s): // Cedric Nugteren // -// This file implements the tests for the Xgemm routine. It is based on the TestABC class. +// This file implements the tests for the Xgemm routine. // // ================================================================================================= -#include "wrapper_clblas.h" -#include "correctness/testabc.h" +#include "correctness/testblas.h" +#include "routines/xgemm.h" namespace clblast { // ================================================================================================= -// The correctness tester, containing the function calls to CLBlast and to clBLAS for comparison. +// The correctness tester template -void XgemmTest(int argc, char *argv[], const bool silent, const std::string &name) { +void RunTest(int argc, char *argv[], const bool silent, const std::string &name) { - // Creates the CLBlast lambda - auto clblast_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - return Gemm(args.layout, args.a_transpose, args.b_transpose, - args.m, args.n, args.k, - args.alpha, - a_mat(), args.a_offset, args.a_ld, - b_mat(), args.b_offset, args.b_ld, - args.beta, - c_mat(), args.c_offset, args.c_ld, - &queue_plain, &event); - }; - - // Creates the clBLAS lambda (for comparison) - auto clblas_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - auto status = clblasXgemm(static_cast(args.layout), - static_cast(args.a_transpose), - static_cast(args.b_transpose), - args.m, args.n, args.k, - args.alpha, - a_mat(), args.a_offset, args.a_ld, - b_mat(), args.b_offset, args.b_ld, - args.beta, - c_mat(), args.c_offset, args.c_ld, - 1, &queue_plain, 0, nullptr, &event); - return static_cast(status); - }; + // Creates a tester + TestBlas tester{argc, argv, silent, name, TestXgemm::GetOptions(), + TestXgemm::RunRoutine, TestXgemm::RunReference, + TestXgemm::DownloadResult, TestXgemm::GetResultIndex, + TestXgemm::ResultID1, TestXgemm::ResultID2}; - // Initializes the arguments relevant for this routine + // This variable holds the arguments relevant for this routine auto args = Arguments{}; - const auto options = std::vector{kArgM, kArgN, kArgK, kArgLayout, - kArgATransp, kArgBTransp, - kArgALeadDim, kArgBLeadDim, kArgCLeadDim, - kArgAOffset, kArgBOffset, kArgCOffset}; - - // Creates a tester - TestABC tester{argc, argv, silent, name, options, clblast_lambda, clblas_lambda}; // Loops over the test-cases from a data-layout point of view - for (auto &layout: tester.kLayouts) { - args.layout = layout; - for (auto &a_transpose: tester.kTransposes) { - args.a_transpose = a_transpose; - for (auto &b_transpose: tester.kTransposes) { - args.b_transpose = b_transpose; - const auto case_name = ToString(layout)+" "+ToString(a_transpose)+" "+ToString(b_transpose); + for (auto &layout: tester.kLayouts) { args.layout = layout; + for (auto &a_transpose: tester.kTransposes) { args.a_transpose = a_transpose; + for (auto &b_transpose: tester.kTransposes) { args.b_transpose = b_transpose; + + // Creates the arguments vector for the regular tests + auto regular_test_vector = std::vector>{}; + for (auto &m: tester.kMatrixDims) { args.m = m; + for (auto &n: tester.kMatrixDims) { args.n = n; + for (auto &k: tester.kMatrixDims) { args.k = k; + for (auto &a_ld: tester.kMatrixDims) { args.a_ld = a_ld; + for (auto &a_offset: tester.kOffsets) { args.a_offset = a_offset; + for (auto &b_ld: tester.kMatrixDims) { args.b_ld = b_ld; + for (auto &b_offset: tester.kOffsets) { args.b_offset = b_offset; + for (auto &c_ld: tester.kMatrixDims) { args.c_ld = c_ld; + for (auto &c_offset: tester.kOffsets) { args.c_offset = c_offset; + for (auto &alpha: tester.kAlphaValues) { args.alpha = alpha; + for (auto &beta: tester.kBetaValues) { args.beta = beta; + args.a_size = TestXgemm::GetSizeA(args); + args.b_size = TestXgemm::GetSizeB(args); + args.c_size = TestXgemm::GetSizeC(args); + if (args.a_size<1 || args.b_size<1 || args.c_size<1) { continue; } + regular_test_vector.push_back(args); + } + } + } + } + } + } + } + } + } + } + } + + // Creates the arguments vector for the invalid-buffer tests + auto invalid_test_vector = std::vector>{}; + args.m = args.n = args.k = tester.kBufferSize; + args.a_ld = args.b_ld = args.c_ld = tester.kBufferSize; + args.a_offset = args.b_offset = args.c_offset = 0; + for (auto &a_size: tester.kMatSizes) { args.a_size = a_size; + for (auto &b_size: tester.kMatSizes) { args.b_size = b_size; + for (auto &c_size: tester.kMatSizes) { args.c_size = c_size; + invalid_test_vector.push_back(args); + } + } + } // Runs the tests - tester.TestRegular(args, case_name, false); - tester.TestInvalidBufferSizes(args, case_name); + const auto case_name = ToString(layout)+" "+ToString(a_transpose)+" "+ToString(b_transpose); + tester.TestRegular(regular_test_vector, case_name); + tester.TestInvalid(invalid_test_vector, case_name); } } } @@ -88,10 +92,10 @@ void XgemmTest(int argc, char *argv[], const bool silent, const std::string &nam // Main function (not within the clblast namespace) int main(int argc, char *argv[]) { - clblast::XgemmTest(argc, argv, false, "SGEMM"); - clblast::XgemmTest(argc, argv, true, "DGEMM"); - clblast::XgemmTest(argc, argv, true, "CGEMM"); - clblast::XgemmTest(argc, argv, true, "ZGEMM"); + clblast::RunTest(argc, argv, false, "SGEMM"); + clblast::RunTest(argc, argv, true, "DGEMM"); + clblast::RunTest(argc, argv, true, "CGEMM"); + clblast::RunTest(argc, argv, true, "ZGEMM"); return 0; } diff --git a/test/correctness/routines/xgemv.cc b/test/correctness/routines/xgemv.cc index 1f484eb4..163669e5 100644 --- a/test/correctness/routines/xgemv.cc +++ b/test/correctness/routines/xgemv.cc @@ -7,68 +7,79 @@ // Author(s): // Cedric Nugteren // -// This file implements the tests for the Xgemv routine. It is based on the TestAXY class. +// This file implements the tests for the Xgemv routine. // // ================================================================================================= -#include "wrapper_clblas.h" -#include "correctness/testaxy.h" +#include "correctness/testblas.h" +#include "routines/xgemv.h" namespace clblast { // ================================================================================================= -// The correctness tester, containing the function calls to CLBlast and to clBLAS for comparison. +// The correctness tester template -void XgemvTest(int argc, char *argv[], const bool silent, const std::string &name) { +void RunTest(int argc, char *argv[], const bool silent, const std::string &name) { - // Creates the CLBlast lambda - auto clblast_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &x_vec, const Buffer &y_vec, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - return Gemv(args.layout, args.a_transpose, args.m, args.n, args.alpha, - a_mat(), args.a_offset, args.a_ld, - x_vec(), args.x_offset, args.x_inc, args.beta, - y_vec(), args.y_offset, args.y_inc, - &queue_plain, &event); - }; - - // Creates the clBLAS lambda (for comparison) - auto clblas_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &x_vec, const Buffer &y_vec, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - auto status = clblasXgemv(static_cast(args.layout), - static_cast(args.a_transpose), - args.m, args.n, args.alpha, - a_mat(), args.a_offset, args.a_ld, - x_vec(), args.x_offset, args.x_inc, args.beta, - y_vec(), args.y_offset, args.y_inc, - 1, &queue_plain, 0, nullptr, &event); - return static_cast(status); - }; + // Creates a tester + TestBlas tester{argc, argv, silent, name, TestXgemv::GetOptions(), + TestXgemv::RunRoutine, TestXgemv::RunReference, + TestXgemv::DownloadResult, TestXgemv::GetResultIndex, + TestXgemv::ResultID1, TestXgemv::ResultID2}; - // Initializes the arguments relevant for this routine + // This variable holds the arguments relevant for this routine auto args = Arguments{}; - const auto options = std::vector{kArgM, kArgN, kArgLayout, kArgATransp, - kArgALeadDim, kArgXInc, kArgYInc, - kArgAOffset, kArgXOffset, kArgYOffset}; - - // Creates a tester - TestAXY tester{argc, argv, silent, name, options, clblast_lambda, clblas_lambda}; // Loops over the test-cases from a data-layout point of view - for (auto &layout: tester.kLayouts) { - args.layout = layout; - for (auto &a_transpose: tester.kTransposes) { - args.a_transpose = a_transpose; - const auto case_name = ToString(layout)+" "+ToString(a_transpose); + for (auto &layout: tester.kLayouts) { args.layout = layout; + for (auto &a_transpose: tester.kTransposes) { args.a_transpose = a_transpose; + + // Creates the arguments vector for the regular tests + auto regular_test_vector = std::vector>{}; + for (auto &m: tester.kMatrixVectorDims) { args.m = m; + for (auto &n: tester.kMatrixVectorDims) { args.n = n; + for (auto &a_ld: tester.kMatrixVectorDims) { args.a_ld = a_ld; + for (auto &a_offset: tester.kOffsets) { args.a_offset = a_offset; + for (auto &x_inc: tester.kIncrements) { args.x_inc = x_inc; + for (auto &x_offset: tester.kOffsets) { args.x_offset = x_offset; + for (auto &y_inc: tester.kIncrements) { args.y_inc = y_inc; + for (auto &y_offset: tester.kOffsets) { args.y_offset = y_offset; + for (auto &alpha: tester.kAlphaValues) { args.alpha = alpha; + for (auto &beta: tester.kBetaValues) { args.beta = beta; + args.a_size = TestXgemv::GetSizeA(args); + args.x_size = TestXgemv::GetSizeX(args); + args.y_size = TestXgemv::GetSizeY(args); + if (args.a_size<1 || args.x_size<1 || args.y_size<1) { continue; } + regular_test_vector.push_back(args); + } + } + } + } + } + } + } + } + } + } + + // Creates the arguments vector for the invalid-buffer tests + auto invalid_test_vector = std::vector>{}; + args.m = args.n = tester.kBufferSize; + args.a_ld = tester.kBufferSize; + args.x_inc = args.y_inc = 1; + args.a_offset = args.x_offset = args.y_offset = 0; + for (auto &a_size: tester.kMatSizes) { args.a_size = a_size; + for (auto &x_size: tester.kVecSizes) { args.x_size = x_size; + for (auto &y_size: tester.kVecSizes) { args.y_size = y_size; + invalid_test_vector.push_back(args); + } + } + } // Runs the tests - tester.TestRegular(args, case_name); - tester.TestInvalidBufferSizes(args, case_name); + const auto case_name = ToString(layout)+" "+ToString(a_transpose); + tester.TestRegular(regular_test_vector, case_name); + tester.TestInvalid(invalid_test_vector, case_name); } } } @@ -78,10 +89,10 @@ void XgemvTest(int argc, char *argv[], const bool silent, const std::string &nam // Main function (not within the clblast namespace) int main(int argc, char *argv[]) { - clblast::XgemvTest(argc, argv, false, "SGEMV"); - clblast::XgemvTest(argc, argv, true, "DGEMV"); - clblast::XgemvTest(argc, argv, true, "CGEMV"); - clblast::XgemvTest(argc, argv, true, "ZGEMV"); + clblast::RunTest(argc, argv, false, "SGEMV"); + clblast::RunTest(argc, argv, true, "DGEMV"); + clblast::RunTest(argc, argv, true, "CGEMV"); + clblast::RunTest(argc, argv, true, "ZGEMV"); return 0; } diff --git a/test/correctness/routines/xsymm.cc b/test/correctness/routines/xsymm.cc index 0e02e9ca..e494b890 100644 --- a/test/correctness/routines/xsymm.cc +++ b/test/correctness/routines/xsymm.cc @@ -7,77 +7,79 @@ // Author(s): // Cedric Nugteren // -// This file implements the tests for the Xsymm routine. It is based on the TestABC class. +// This file implements the tests for the Xsymm routine. // // ================================================================================================= -#include "wrapper_clblas.h" -#include "correctness/testabc.h" +#include "correctness/testblas.h" +#include "routines/xsymm.h" namespace clblast { // ================================================================================================= -// The correctness tester, containing the function calls to CLBlast and to clBLAS for comparison. +// The correctness tester template -void XsymmTest(int argc, char *argv[], const bool silent, const std::string &name) { +void RunTest(int argc, char *argv[], const bool silent, const std::string &name) { - // Creates the CLBlast lambda - auto clblast_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - return Symm(args.layout, args.side, args.triangle, - args.m, args.n, - args.alpha, - a_mat(), args.a_offset, args.a_ld, - b_mat(), args.b_offset, args.b_ld, - args.beta, - c_mat(), args.c_offset, args.c_ld, - &queue_plain, &event); - }; - - // Creates the clBLAS lambda (for comparison) - auto clblas_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - auto status = clblasXsymm(static_cast(args.layout), - static_cast(args.side), - static_cast(args.triangle), - args.m, args.n, - args.alpha, - a_mat(), args.a_offset, args.a_ld, - b_mat(), args.b_offset, args.b_ld, - args.beta, - c_mat(), args.c_offset, args.c_ld, - 1, &queue_plain, 0, nullptr, &event); - return static_cast(status); - }; + // Creates a tester + TestBlas tester{argc, argv, silent, name, TestXsymm::GetOptions(), + TestXsymm::RunRoutine, TestXsymm::RunReference, + TestXsymm::DownloadResult, TestXsymm::GetResultIndex, + TestXsymm::ResultID1, TestXsymm::ResultID2}; - // Initializes the arguments relevant for this routine + // This variable holds the arguments relevant for this routine auto args = Arguments{}; - const auto options = std::vector{kArgM, kArgN, kArgLayout, - kArgSide, kArgTriangle, - kArgALeadDim, kArgBLeadDim, kArgCLeadDim, - kArgAOffset, kArgBOffset, kArgCOffset}; - - // Creates a tester - TestABC tester{argc, argv, silent, name, options, clblast_lambda, clblas_lambda}; // Loops over the test-cases from a data-layout point of view - for (auto &layout: tester.kLayouts) { - args.layout = layout; - for (auto &side: {Side::kLeft, Side::kRight}) { - args.side = side; - for (auto &triangle: {Triangle::kUpper, Triangle::kLower}) { - args.triangle = triangle; - const auto case_name = ToString(layout)+" "+ToString(side)+" "+ToString(triangle); + for (auto &layout: tester.kLayouts) { args.layout = layout; + for (auto &side: tester.kSides) { args.side = side; + for (auto &triangle: tester.kTriangles) { args.triangle = triangle; + + // Creates the arguments vector for the regular tests + auto regular_test_vector = std::vector>{}; + for (auto &m: tester.kMatrixDims) { args.m = m; + for (auto &n: tester.kMatrixDims) { args.n = n; + for (auto &a_ld: tester.kMatrixDims) { args.a_ld = a_ld; + for (auto &a_offset: tester.kOffsets) { args.a_offset = a_offset; + for (auto &b_ld: tester.kMatrixDims) { args.b_ld = b_ld; + for (auto &b_offset: tester.kOffsets) { args.b_offset = b_offset; + for (auto &c_ld: tester.kMatrixDims) { args.c_ld = c_ld; + for (auto &c_offset: tester.kOffsets) { args.c_offset = c_offset; + for (auto &alpha: tester.kAlphaValues) { args.alpha = alpha; + for (auto &beta: tester.kBetaValues) { args.beta = beta; + args.a_size = TestXsymm::GetSizeA(args); + args.b_size = TestXsymm::GetSizeB(args); + args.c_size = TestXsymm::GetSizeC(args); + if (args.a_size<1 || args.b_size<1 || args.c_size<1) { continue; } + regular_test_vector.push_back(args); + } + } + } + } + } + } + } + } + } + } + + // Creates the arguments vector for the invalid-buffer tests + auto invalid_test_vector = std::vector>{}; + args.m = args.n = tester.kBufferSize; + args.a_ld = args.b_ld = args.c_ld = tester.kBufferSize; + args.a_offset = args.b_offset = args.c_offset = 0; + for (auto &a_size: tester.kMatSizes) { args.a_size = a_size; + for (auto &b_size: tester.kMatSizes) { args.b_size = b_size; + for (auto &c_size: tester.kMatSizes) { args.c_size = c_size; + invalid_test_vector.push_back(args); + } + } + } // Runs the tests - tester.TestRegular(args, case_name, true); - tester.TestInvalidBufferSizes(args, case_name); + const auto case_name = ToString(layout)+" "+ToString(side)+" "+ToString(triangle); + tester.TestRegular(regular_test_vector, case_name); + tester.TestInvalid(invalid_test_vector, case_name); } } } @@ -88,10 +90,10 @@ void XsymmTest(int argc, char *argv[], const bool silent, const std::string &nam // Main function (not within the clblast namespace) int main(int argc, char *argv[]) { - clblast::XsymmTest(argc, argv, false, "SSYMM"); - clblast::XsymmTest(argc, argv, true, "DSYMM"); - clblast::XsymmTest(argc, argv, true, "CSYMM"); - clblast::XsymmTest(argc, argv, true, "ZSYMM"); + clblast::RunTest(argc, argv, false, "SSYMM"); + clblast::RunTest(argc, argv, true, "DSYMM"); + clblast::RunTest(argc, argv, true, "CSYMM"); + clblast::RunTest(argc, argv, true, "ZSYMM"); return 0; } diff --git a/test/correctness/routines/xsyr2k.cc b/test/correctness/routines/xsyr2k.cc index 3365e6a8..b4bf03d9 100644 --- a/test/correctness/routines/xsyr2k.cc +++ b/test/correctness/routines/xsyr2k.cc @@ -7,78 +7,81 @@ // Author(s): // Cedric Nugteren // -// This file implements the tests for the Xsyr2k routine. It is based on the TestABC class. +// This file implements the tests for the Xsyr2k routine. // // ================================================================================================= -#include "wrapper_clblas.h" -#include "correctness/testabc.h" +#include "correctness/testblas.h" +#include "routines/xsyr2k.h" namespace clblast { // ================================================================================================= -// The correctness tester, containing the function calls to CLBlast and to clBLAS for comparison. +// The correctness tester template -void Xsyr2kTest(int argc, char *argv[], const bool silent, const std::string &name) { +void RunTest(int argc, char *argv[], const bool silent, const std::string &name) { - // Creates the CLBlast lambda - auto clblast_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - return Syr2k(args.layout, args.triangle, args.a_transpose, - args.n, args.k, - args.alpha, - a_mat(), args.a_offset, args.a_ld, - b_mat(), args.b_offset, args.b_ld, - args.beta, - c_mat(), args.c_offset, args.c_ld, - &queue_plain, &event); - }; - - // Creates the clBLAS lambda (for comparison) - auto clblas_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - auto status = clblasXsyr2k(static_cast(args.layout), - static_cast(args.triangle), - static_cast(args.a_transpose), - args.n, args.k, - args.alpha, - a_mat(), args.a_offset, args.a_ld, - b_mat(), args.b_offset, args.b_ld, - args.beta, - c_mat(), args.c_offset, args.c_ld, - 1, &queue_plain, 0, nullptr, &event); - return static_cast(status); - }; + // Creates a tester + TestBlas tester{argc, argv, silent, name, TestXsyr2k::GetOptions(), + TestXsyr2k::RunRoutine, TestXsyr2k::RunReference, + TestXsyr2k::DownloadResult, TestXsyr2k::GetResultIndex, + TestXsyr2k::ResultID1, TestXsyr2k::ResultID2}; - // Initializes the arguments relevant for this routine + // This variable holds the arguments relevant for this routine auto args = Arguments{}; - const auto options = std::vector{kArgN, kArgK, kArgLayout, - kArgTriangle, kArgATransp, - kArgALeadDim, kArgBLeadDim, kArgCLeadDim, - kArgAOffset, kArgBOffset, kArgCOffset}; - - // Creates a tester - TestABC tester{argc, argv, silent, name, options, clblast_lambda, clblas_lambda}; // Loops over the test-cases from a data-layout point of view - for (auto &layout: tester.kLayouts) { - args.layout = layout; - for (auto &triangle: {Triangle::kUpper, Triangle::kLower}) { - args.triangle = triangle; - for (auto &ab_transpose: {Transpose::kNo, Transpose::kYes}) { // No conjugate here since it is - args.a_transpose = ab_transpose; // not supported by clBLAS + for (auto &layout: tester.kLayouts) { args.layout = layout; + for (auto &triangle: tester.kTriangles) { args.triangle = triangle; + for (auto &ab_transpose: {Transpose::kNo, Transpose::kYes}) { // No conjugate here since it + args.a_transpose = ab_transpose; // is not supported by clBLAS args.b_transpose = ab_transpose; - const auto case_name = ToString(layout)+" "+ToString(triangle)+" "+ToString(ab_transpose); + + // Creates the arguments vector for the regular tests + auto regular_test_vector = std::vector>{}; + for (auto &n: tester.kMatrixDims) { args.n = n; + for (auto &k: tester.kMatrixDims) { args.k = k; + for (auto &a_ld: tester.kMatrixDims) { args.a_ld = a_ld; + for (auto &a_offset: tester.kOffsets) { args.a_offset = a_offset; + for (auto &b_ld: tester.kMatrixDims) { args.b_ld = b_ld; + for (auto &b_offset: tester.kOffsets) { args.b_offset = b_offset; + for (auto &c_ld: tester.kMatrixDims) { args.c_ld = c_ld; + for (auto &c_offset: tester.kOffsets) { args.c_offset = c_offset; + for (auto &alpha: tester.kAlphaValues) { args.alpha = alpha; + for (auto &beta: tester.kBetaValues) { args.beta = beta; + args.a_size = TestXsyr2k::GetSizeA(args); + args.b_size = TestXsyr2k::GetSizeB(args); + args.c_size = TestXsyr2k::GetSizeC(args); + if (args.a_size<1 || args.b_size<1 || args.c_size<1) { continue; } + regular_test_vector.push_back(args); + } + } + } + } + } + } + } + } + } + } + + // Creates the arguments vector for the invalid-buffer tests + auto invalid_test_vector = std::vector>{}; + args.n = args.k = tester.kBufferSize; + args.a_ld = args.b_ld = args.c_ld = tester.kBufferSize; + args.a_offset = args.b_offset = args.c_offset = 0; + for (auto &a_size: tester.kMatSizes) { args.a_size = a_size; + for (auto &b_size: tester.kMatSizes) { args.b_size = b_size; + for (auto &c_size: tester.kMatSizes) { args.c_size = c_size; + invalid_test_vector.push_back(args); + } + } + } // Runs the tests - tester.TestRegular(args, case_name, true); - tester.TestInvalidBufferSizes(args, case_name); + const auto case_name = ToString(layout)+" "+ToString(triangle)+" "+ToString(ab_transpose); + tester.TestRegular(regular_test_vector, case_name); + tester.TestInvalid(invalid_test_vector, case_name); } } } @@ -89,10 +92,10 @@ void Xsyr2kTest(int argc, char *argv[], const bool silent, const std::string &na // Main function (not within the clblast namespace) int main(int argc, char *argv[]) { - clblast::Xsyr2kTest(argc, argv, false, "SSYR2K"); - clblast::Xsyr2kTest(argc, argv, true, "DSYR2K"); - clblast::Xsyr2kTest(argc, argv, true, "CSYR2K"); - clblast::Xsyr2kTest(argc, argv, true, "ZSYR2K"); + clblast::RunTest(argc, argv, false, "SSYR2K"); + clblast::RunTest(argc, argv, true, "DSYR2K"); + clblast::RunTest(argc, argv, true, "CSYR2K"); + clblast::RunTest(argc, argv, true, "ZSYR2K"); return 0; } diff --git a/test/correctness/routines/xsyrk.cc b/test/correctness/routines/xsyrk.cc index 8d3bd82e..899d3b77 100644 --- a/test/correctness/routines/xsyrk.cc +++ b/test/correctness/routines/xsyrk.cc @@ -7,75 +7,73 @@ // Author(s): // Cedric Nugteren // -// This file implements the tests for the Xsyrk routine. It is based on the TestAC class. +// This file implements the tests for the Xsyrk routine. // // ================================================================================================= -#include "wrapper_clblas.h" -#include "correctness/testac.h" +#include "correctness/testblas.h" +#include "routines/xsyrk.h" namespace clblast { // ================================================================================================= -// The correctness tester, containing the function calls to CLBlast and to clBLAS for comparison. +// The correctness tester template -void XsyrkTest(int argc, char *argv[], const bool silent, const std::string &name) { +void RunTest(int argc, char *argv[], const bool silent, const std::string &name) { - // Creates the CLBlast lambda - auto clblast_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &c_mat, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - return Syrk(args.layout, args.triangle, args.a_transpose, - args.n, args.k, - args.alpha, - a_mat(), args.a_offset, args.a_ld, - args.beta, - c_mat(), args.c_offset, args.c_ld, - &queue_plain, &event); - }; - - // Creates the clBLAS lambda (for comparison) - auto clblas_lambda = [](const Arguments &args, - const Buffer &a_mat, const Buffer &c_mat, - CommandQueue &queue) -> StatusCode { - auto queue_plain = queue(); - auto event = cl_event{}; - auto status = clblasXsyrk(static_cast(args.layout), - static_cast(args.triangle), - static_cast(args.a_transpose), - args.n, args.k, - args.alpha, - a_mat(), args.a_offset, args.a_ld, - args.beta, - c_mat(), args.c_offset, args.c_ld, - 1, &queue_plain, 0, nullptr, &event); - return static_cast(status); - }; + // Creates a tester + TestBlas tester{argc, argv, silent, name, TestXsyrk::GetOptions(), + TestXsyrk::RunRoutine, TestXsyrk::RunReference, + TestXsyrk::DownloadResult, TestXsyrk::GetResultIndex, + TestXsyrk::ResultID1, TestXsyrk::ResultID2}; - // Initializes the arguments relevant for this routine + // This variable holds the arguments relevant for this routine auto args = Arguments{}; - const auto options = std::vector{kArgN, kArgK, kArgLayout, - kArgTriangle, kArgATransp, - kArgALeadDim, kArgCLeadDim, - kArgAOffset, kArgCOffset}; - - // Creates a tester - TestAC tester{argc, argv, silent, name, options, clblast_lambda, clblas_lambda}; // Loops over the test-cases from a data-layout point of view - for (auto &layout: tester.kLayouts) { - args.layout = layout; - for (auto &triangle: {Triangle::kUpper, Triangle::kLower}) { - args.triangle = triangle; - for (auto &a_transpose: {Transpose::kNo, Transpose::kYes}) { // No conjugate here since it is - args.a_transpose = a_transpose; // not supported by clBLAS - const auto case_name = ToString(layout)+" "+ToString(triangle)+" "+ToString(a_transpose); + for (auto &layout: tester.kLayouts) { args.layout = layout; + for (auto &triangle: tester.kTriangles) { args.triangle = triangle; + for (auto &a_transpose: {Transpose::kNo, Transpose::kYes}) { // No conjugate here since it + args.a_transpose = a_transpose; // is not supported by clBLAS + + // Creates the arguments vector for the regular tests + auto regular_test_vector = std::vector>{}; + for (auto &n: tester.kMatrixDims) { args.n = n; + for (auto &k: tester.kMatrixDims) { args.k = k; + for (auto &a_ld: tester.kMatrixDims) { args.a_ld = a_ld; + for (auto &a_offset: tester.kOffsets) { args.a_offset = a_offset; + for (auto &c_ld: tester.kMatrixDims) { args.c_ld = c_ld; + for (auto &c_offset: tester.kOffsets) { args.c_offset = c_offset; + for (auto &alpha: tester.kAlphaValues) { args.alpha = alpha; + for (auto &beta: tester.kBetaValues) { args.beta = beta; + args.a_size = TestXsyrk::GetSizeA(args); + args.c_size = TestXsyrk::GetSizeC(args); + if (args.a_size<1 || args.c_size<1) { continue; } + regular_test_vector.push_back(args); + } + } + } + } + } + } + } + } + + // Creates the arguments vector for the invalid-buffer tests + auto invalid_test_vector = std::vector>{}; + args.n = args.k = tester.kBufferSize; + args.a_ld = args.c_ld = tester.kBufferSize; + args.a_offset = args.c_offset = 0; + for (auto &a_size: tester.kMatSizes) { args.a_size = a_size; + for (auto &c_size: tester.kMatSizes) { args.c_size = c_size; + invalid_test_vector.push_back(args); + } + } // Runs the tests - tester.TestRegular(args, case_name); - tester.TestInvalidBufferSizes(args, case_name); + const auto case_name = ToString(layout)+" "+ToString(triangle)+" "+ToString(a_transpose); + tester.TestRegular(regular_test_vector, case_name); + tester.TestInvalid(invalid_test_vector, case_name); } } } @@ -86,10 +84,10 @@ void XsyrkTest(int argc, char *argv[], const bool silent, const std::string &nam // Main function (not within the clblast namespace) int main(int argc, char *argv[]) { - clblast::XsyrkTest(argc, argv, false, "SSYRK"); - clblast::XsyrkTest(argc, argv, true, "DSYRK"); - clblast::XsyrkTest(argc, argv, true, "CSYRK"); - clblast::XsyrkTest(argc, argv, true, "ZSYRK"); + clblast::RunTest(argc, argv, false, "SSYRK"); + clblast::RunTest(argc, argv, true, "DSYRK"); + clblast::RunTest(argc, argv, true, "CSYRK"); + clblast::RunTest(argc, argv, true, "ZSYRK"); return 0; } diff --git a/test/correctness/testab.cc b/test/correctness/testab.cc deleted file mode 100644 index ef03f32f..00000000 --- a/test/correctness/testab.cc +++ /dev/null @@ -1,192 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file implements the TestAB class (see the header for information about the class). -// -// ================================================================================================= - -#include - -#include "correctness/testab.h" - -namespace clblast { -// ================================================================================================= - -// Constructor, initializes the base class tester and input data -template -TestAB::TestAB(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda): - Tester{argc, argv, silent, name, options}, - clblast_lambda_(clblast_lambda), - clblas_lambda_(clblas_lambda) { - - // Computes the maximum sizes. This allows for a single set of input/output buffers. - auto max_dim = *std::max_element(kMatrixDims.begin(), kMatrixDims.end()); - auto max_ld = *std::max_element(kMatrixDims.begin(), kMatrixDims.end()); - auto max_offset = *std::max_element(kOffsets.begin(), kOffsets.end()); - - // Creates test input data - a_source_.resize(max_dim*max_ld + max_offset); - b_source_.resize(max_dim*max_ld + max_offset); - PopulateVector(a_source_); - PopulateVector(b_source_); -} - -// =============================================================================================== - -// Tests the routine for a wide variety of parameters -template -void TestAB::TestRegular(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("regular behaviour", name); - - // Computes whether or not the matrices are transposed. Note that we assume a default of - // column-major and no-transpose. If one of them is different (but not both), then rotated - // is considered true. - auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) || - (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo); - auto b_rotated = (args.layout == Layout::kRowMajor); - - // Iterates over the matrix dimensions - for (auto &m: kMatrixDims) { - args.m = m; - for (auto &n: kMatrixDims) { - args.n = n; - - // Computes the second dimensions of the matrices taking the rotation into account - auto a_two = (a_rotated) ? n : n; - auto b_two = (b_rotated) ? m : n; - - // Iterates over the leading-dimension values and the offsets - for (auto &a_ld: kMatrixDims) { - args.a_ld = a_ld; - for (auto &a_offset: kOffsets) { - args.a_offset = a_offset; - for (auto &b_ld: kMatrixDims) { - args.b_ld = b_ld; - for (auto &b_offset: kOffsets) { - args.b_offset = b_offset; - - // Computes the buffer sizes - auto a_size = a_two * a_ld + a_offset; - auto b_size = b_two * b_ld + b_offset; - if (a_size < 1 || b_size < 1) { continue; } - - // Creates the OpenCL buffers - auto a_mat = Buffer(context_, CL_MEM_READ_WRITE, a_size*sizeof(T)); - auto r_mat = Buffer(context_, CL_MEM_READ_WRITE, b_size*sizeof(T)); - auto s_mat = Buffer(context_, CL_MEM_READ_WRITE, b_size*sizeof(T)); - - // Iterates over the values for alpha and beta - for (auto &alpha: kAlphaValues) { - args.alpha = alpha; - for (auto &beta: kBetaValues) { - args.beta = beta; - - // Runs the reference clBLAS code - a_mat.WriteBuffer(queue_, a_size*sizeof(T), a_source_); - r_mat.WriteBuffer(queue_, b_size*sizeof(T), b_source_); - auto status1 = clblas_lambda_(args, a_mat, r_mat, queue_); - - // Runs the CLBlast code - a_mat.WriteBuffer(queue_, a_size*sizeof(T), a_source_); - s_mat.WriteBuffer(queue_, b_size*sizeof(T), b_source_); - auto status2 = clblast_lambda_(args, a_mat, s_mat, queue_); - - // Tests for equality of the two status codes - if (status1 != StatusCode::kSuccess || status2 != StatusCode::kSuccess) { - TestErrorCodes(status1, status2, args); - continue; - } - - // Downloads the results - std::vector r_result(b_size, static_cast(0)); - std::vector s_result(b_size, static_cast(0)); - r_mat.ReadBuffer(queue_, b_size*sizeof(T), r_result); - s_mat.ReadBuffer(queue_, b_size*sizeof(T), s_result); - - // Checks for differences in the output - auto errors = size_t{0}; - for (auto idm=size_t{0}; idm -void TestAB::TestInvalidBufferSizes(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("invalid buffer sizes", name); - - // Sets example test parameters - args.m = kBufferSize; - args.n = kBufferSize; - args.a_ld = kBufferSize; - args.b_ld = kBufferSize; - args.a_offset = 0; - args.b_offset = 0; - - // Iterates over test buffer sizes - const std::vector kBufferSizes = {0, kBufferSize*kBufferSize-1, kBufferSize*kBufferSize}; - for (auto &a_size: kBufferSizes) { - for (auto &b_size: kBufferSizes) { - - // Creates the OpenCL buffers. Note: we are not using the C++ version since we explicitly - // want to be able to create invalid buffers (no error checking here). - auto a = clCreateBuffer(context_(), CL_MEM_READ_WRITE, a_size*sizeof(T), nullptr, nullptr); - auto a_mat = Buffer(a); - auto r = clCreateBuffer(context_(), CL_MEM_READ_WRITE, b_size*sizeof(T), nullptr, nullptr); - auto r_mat = Buffer(r); - auto s = clCreateBuffer(context_(), CL_MEM_READ_WRITE, b_size*sizeof(T), nullptr, nullptr); - auto s_mat = Buffer(s); - - // Runs the two routines - auto status1 = clblas_lambda_(args, a_mat, r_mat, queue_); - auto status2 = clblast_lambda_(args, a_mat, s_mat, queue_); - - // Tests for equality of the two status codes - TestErrorCodes(status1, status2, args); - } - } - TestEnd(); -} - -// ================================================================================================= - -// Compiles the templated class -template class TestAB; -template class TestAB; -template class TestAB; -template class TestAB; - -// ================================================================================================= -} // namespace clblast diff --git a/test/correctness/testab.h b/test/correctness/testab.h deleted file mode 100644 index 24a9db7c..00000000 --- a/test/correctness/testab.h +++ /dev/null @@ -1,85 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file tests any mat-mat (A,B) routine. It contains two types of tests: one testing -// all sorts of input combinations, and one deliberatly testing with invalid values. -// -// ================================================================================================= - -#ifndef CLBLAST_TEST_CORRECTNESS_TESTAB_H_ -#define CLBLAST_TEST_CORRECTNESS_TESTAB_H_ - -#include -#include - -#include "correctness/tester.h" - -namespace clblast { -// ================================================================================================= - -// See comment at top of file for a description of the class -template -class TestAB: public Tester { - public: - - // Uses several variables from the Tester class - using Tester::context_; - using Tester::queue_; - using Tester::kLayouts; - using Tester::kTransposes; - - // Uses several helper functions from the Tester class - using Tester::TestStart; - using Tester::TestEnd; - using Tester::TestSimilarity; - using Tester::TestErrorCount; - using Tester::TestErrorCodes; - using Tester::GetExampleScalars; - using Tester::GetOffsets; - using Tester::PrecisionSupported; - - // Test settings for the regular test. Append to this list in case more tests are required. - const std::vector kMatrixDims = { 7, 64 }; - const std::vector kOffsets = GetOffsets(); - const std::vector kAlphaValues = GetExampleScalars(); - const std::vector kBetaValues = GetExampleScalars(); - - // Test settings for the invalid test - const size_t kBufferSize = 64; - - // Shorthand for a BLAS routine - using Routine = std::function&, - const Buffer&, const Buffer&, - CommandQueue&)>; - - // Constructor, initializes the base class tester and input data - TestAB(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda); - - // The test functions, taking no inputs - void TestRegular(Arguments &args, const std::string &name); - void TestInvalidBufferSizes(Arguments &args, const std::string &name); - - private: - - // Source data to test with - std::vector a_source_; - std::vector b_source_; - - // The routines to test - Routine clblast_lambda_; - Routine clblas_lambda_; -}; - -// ================================================================================================= -} // namespace clblast - -// CLBLAST_TEST_CORRECTNESS_TESTAB_H_ -#endif diff --git a/test/correctness/testabc.cc b/test/correctness/testabc.cc deleted file mode 100644 index 64e02523..00000000 --- a/test/correctness/testabc.cc +++ /dev/null @@ -1,218 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file implements the TestABC class (see the header for information about the class). -// -// ================================================================================================= - -#include - -#include "correctness/testabc.h" - -namespace clblast { -// ================================================================================================= - -// Constructor, initializes the base class tester and input data -template -TestABC::TestABC(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda): - Tester{argc, argv, silent, name, options}, - clblast_lambda_(clblast_lambda), - clblas_lambda_(clblas_lambda) { - - // Computes the maximum sizes. This allows for a single set of input/output buffers. - auto max_dim = *std::max_element(kMatrixDims.begin(), kMatrixDims.end()); - auto max_ld = *std::max_element(kMatrixDims.begin(), kMatrixDims.end()); - auto max_offset = *std::max_element(kOffsets.begin(), kOffsets.end()); - - // Creates test input data - a_source_.resize(max_dim*max_ld + max_offset); - b_source_.resize(max_dim*max_ld + max_offset); - c_source_.resize(max_dim*max_ld + max_offset); - PopulateVector(a_source_); - PopulateVector(b_source_); - PopulateVector(c_source_); -} - -// =============================================================================================== - -// Tests the routine for a wide variety of parameters -template -void TestABC::TestRegular(Arguments &args, const std::string &name, const bool symmetric) { - if (!PrecisionSupported()) { return; } - TestStart("regular behaviour", name); - - // Computes whether or not the matrices are transposed. Note that we assume a default of - // column-major and no-transpose. If one of them is different (but not both), then rotated - // is considered true. - auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) || - (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo); - auto b_rotated = (args.layout == Layout::kColMajor && args.b_transpose != Transpose::kNo) || - (args.layout == Layout::kRowMajor && args.b_transpose == Transpose::kNo); - auto c_rotated = (args.layout == Layout::kRowMajor); - - // Iterates over the matrix dimensions - for (auto &m: kMatrixDims) { - args.m = m; - for (auto &n: kMatrixDims) { - args.n = n; - if (symmetric && m != n) { continue; } - for (auto &k: kMatrixDims) { - args.k = k; - - // Computes the second dimensions of the matrices taking the rotation into account - auto a_two = (a_rotated) ? m : k; - auto b_two = (b_rotated) ? k : n; - auto c_two = (c_rotated) ? m : n; - - // Iterates over the leading-dimension values and the offsets - for (auto &a_ld: kMatrixDims) { - args.a_ld = a_ld; - for (auto &a_offset: kOffsets) { - args.a_offset = a_offset; - for (auto &b_ld: kMatrixDims) { - args.b_ld = b_ld; - for (auto &b_offset: kOffsets) { - args.b_offset = b_offset; - for (auto &c_ld: kMatrixDims) { - args.c_ld = c_ld; - for (auto &c_offset: kOffsets) { - args.c_offset = c_offset; - - // Computes the buffer sizes - auto a_size = a_two * a_ld + a_offset; - auto b_size = b_two * b_ld + b_offset; - auto c_size = c_two * c_ld + c_offset; - if (a_size < 1 || b_size < 1 || c_size < 1) { continue; } - - // Creates the OpenCL buffers - auto a_mat = Buffer(context_, CL_MEM_READ_WRITE, a_size*sizeof(T)); - auto b_mat = Buffer(context_, CL_MEM_READ_WRITE, b_size*sizeof(T)); - auto r_mat = Buffer(context_, CL_MEM_READ_WRITE, c_size*sizeof(T)); - auto s_mat = Buffer(context_, CL_MEM_READ_WRITE, c_size*sizeof(T)); - - // Iterates over the values for alpha and beta - for (auto &alpha: kAlphaValues) { - args.alpha = alpha; - for (auto &beta: kBetaValues) { - args.beta = beta; - - // Runs the reference clBLAS code - a_mat.WriteBuffer(queue_, a_size*sizeof(T), a_source_); - b_mat.WriteBuffer(queue_, b_size*sizeof(T), b_source_); - r_mat.WriteBuffer(queue_, c_size*sizeof(T), c_source_); - auto status1 = clblas_lambda_(args, a_mat, b_mat, r_mat, queue_); - - // Runs the CLBlast code - a_mat.WriteBuffer(queue_, a_size*sizeof(T), a_source_); - b_mat.WriteBuffer(queue_, b_size*sizeof(T), b_source_); - s_mat.WriteBuffer(queue_, c_size*sizeof(T), c_source_); - auto status2 = clblast_lambda_(args, a_mat, b_mat, s_mat, queue_); - - // Tests for equality of the two status codes - if (status1 != StatusCode::kSuccess || status2 != StatusCode::kSuccess) { - TestErrorCodes(status1, status2, args); - continue; - } - - // Downloads the results - std::vector r_result(c_size, static_cast(0)); - std::vector s_result(c_size, static_cast(0)); - r_mat.ReadBuffer(queue_, c_size*sizeof(T), r_result); - s_mat.ReadBuffer(queue_, c_size*sizeof(T), s_result); - - // Checks for differences in the output - auto errors = size_t{0}; - for (auto idm=size_t{0}; idm -void TestABC::TestInvalidBufferSizes(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("invalid buffer sizes", name); - - // Sets example test parameters - args.m = kBufferSize; - args.n = kBufferSize; - args.k = kBufferSize; - args.a_ld = kBufferSize; - args.b_ld = kBufferSize; - args.c_ld = kBufferSize; - args.a_offset = 0; - args.b_offset = 0; - args.c_offset = 0; - - // Iterates over test buffer sizes - const std::vector kBufferSizes = {0, kBufferSize*kBufferSize-1, kBufferSize*kBufferSize}; - for (auto &a_size: kBufferSizes) { - for (auto &b_size: kBufferSizes) { - for (auto &c_size: kBufferSizes) { - - // Creates the OpenCL buffers. Note: we are not using the C++ version since we explicitly - // want to be able to create invalid buffers (no error checking here). - auto a = clCreateBuffer(context_(), CL_MEM_READ_WRITE, a_size*sizeof(T), nullptr, nullptr); - auto a_mat = Buffer(a); - auto b = clCreateBuffer(context_(), CL_MEM_READ_WRITE, b_size*sizeof(T), nullptr, nullptr); - auto b_mat = Buffer(b); - auto r = clCreateBuffer(context_(), CL_MEM_READ_WRITE, c_size*sizeof(T), nullptr, nullptr); - auto r_mat = Buffer(r); - auto s = clCreateBuffer(context_(), CL_MEM_READ_WRITE, c_size*sizeof(T), nullptr, nullptr); - auto s_mat = Buffer(s); - - // Runs the two routines - auto status1 = clblas_lambda_(args, a_mat, b_mat, r_mat, queue_); - auto status2 = clblast_lambda_(args, a_mat, b_mat, s_mat, queue_); - - // Tests for equality of the two status codes - TestErrorCodes(status1, status2, args); - } - } - } - TestEnd(); -} - -// ================================================================================================= - -// Compiles the templated class -template class TestABC; -template class TestABC; -template class TestABC; -template class TestABC; - -// ================================================================================================= -} // namespace clblast diff --git a/test/correctness/testabc.h b/test/correctness/testabc.h deleted file mode 100644 index 41100db7..00000000 --- a/test/correctness/testabc.h +++ /dev/null @@ -1,86 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file tests any mat-mat-mat (A,B,C) routine. It contains two types of tests: one testing -// all sorts of input combinations, and one deliberatly testing with invalid values. -// -// ================================================================================================= - -#ifndef CLBLAST_TEST_CORRECTNESS_TESTABC_H_ -#define CLBLAST_TEST_CORRECTNESS_TESTABC_H_ - -#include -#include - -#include "correctness/tester.h" - -namespace clblast { -// ================================================================================================= - -// See comment at top of file for a description of the class -template -class TestABC: public Tester { - public: - - // Uses several variables from the Tester class - using Tester::context_; - using Tester::queue_; - using Tester::kLayouts; - using Tester::kTransposes; - - // Uses several helper functions from the Tester class - using Tester::TestStart; - using Tester::TestEnd; - using Tester::TestSimilarity; - using Tester::TestErrorCount; - using Tester::TestErrorCodes; - using Tester::GetExampleScalars; - using Tester::GetOffsets; - using Tester::PrecisionSupported; - - // Test settings for the regular test. Append to this list in case more tests are required. - const std::vector kMatrixDims = { 7, 64 }; - const std::vector kOffsets = GetOffsets(); - const std::vector kAlphaValues = GetExampleScalars(); - const std::vector kBetaValues = GetExampleScalars(); - - // Test settings for the invalid test - const size_t kBufferSize = 64; - - // Shorthand for a BLAS routine - using Routine = std::function&, - const Buffer&, const Buffer&, const Buffer&, - CommandQueue&)>; - - // Constructor, initializes the base class tester and input data - TestABC(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda); - - // The test functions, taking no inputs - void TestRegular(Arguments &args, const std::string &name, const bool symmetric); - void TestInvalidBufferSizes(Arguments &args, const std::string &name); - - private: - - // Source data to test with - std::vector a_source_; - std::vector b_source_; - std::vector c_source_; - - // The routines to test - Routine clblast_lambda_; - Routine clblas_lambda_; -}; - -// ================================================================================================= -} // namespace clblast - -// CLBLAST_TEST_CORRECTNESS_TESTABC_H_ -#endif diff --git a/test/correctness/testac.cc b/test/correctness/testac.cc deleted file mode 100644 index e16186d9..00000000 --- a/test/correctness/testac.cc +++ /dev/null @@ -1,191 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file implements the TestAC class (see the header for information about the class). -// -// ================================================================================================= - -#include - -#include "correctness/testac.h" - -namespace clblast { -// ================================================================================================= - -// Constructor, initializes the base class tester and input data -template -TestAC::TestAC(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda): - Tester{argc, argv, silent, name, options}, - clblast_lambda_(clblast_lambda), - clblas_lambda_(clblas_lambda) { - - // Computes the maximum sizes. This allows for a single set of input/output buffers. - auto max_dim = *std::max_element(kMatrixDims.begin(), kMatrixDims.end()); - auto max_ld = *std::max_element(kMatrixDims.begin(), kMatrixDims.end()); - auto max_offset = *std::max_element(kOffsets.begin(), kOffsets.end()); - - // Creates test input data - a_source_.resize(max_dim*max_ld + max_offset); - c_source_.resize(max_dim*max_ld + max_offset); - PopulateVector(a_source_); - PopulateVector(c_source_); -} - -// =============================================================================================== - -// Tests the routine for a wide variety of parameters -template -void TestAC::TestRegular(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("regular behaviour", name); - - // Computes whether or not the matrices are transposed. Note that we assume a default of - // column-major and no-transpose. If one of them is different (but not both), then rotated - // is considered true. - auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) || - (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo); - auto c_rotated = (args.layout == Layout::kRowMajor); - - // Iterates over the matrix dimensions - for (auto &n: kMatrixDims) { - args.n = n; - for (auto &k: kMatrixDims) { - args.k = k; - - // Computes the second dimensions of the matrices taking the rotation into account - auto a_two = (a_rotated) ? n : k; - auto c_two = (c_rotated) ? n : n; - - // Iterates over the leading-dimension values and the offsets - for (auto &a_ld: kMatrixDims) { - args.a_ld = a_ld; - for (auto &a_offset: kOffsets) { - args.a_offset = a_offset; - for (auto &c_ld: kMatrixDims) { - args.c_ld = c_ld; - for (auto &c_offset: kOffsets) { - args.c_offset = c_offset; - - // Computes the buffer sizes - auto a_size = a_two * a_ld + a_offset; - auto c_size = c_two * c_ld + c_offset; - if (a_size < 1 || c_size < 1) { continue; } - - // Creates the OpenCL buffers - auto a_mat = Buffer(context_, CL_MEM_READ_WRITE, a_size*sizeof(T)); - auto r_mat = Buffer(context_, CL_MEM_READ_WRITE, c_size*sizeof(T)); - auto s_mat = Buffer(context_, CL_MEM_READ_WRITE, c_size*sizeof(T)); - - // Iterates over the values for alpha and beta - for (auto &alpha: kAlphaValues) { - args.alpha = alpha; - for (auto &beta: kBetaValues) { - args.beta = beta; - - // Runs the reference clBLAS code - a_mat.WriteBuffer(queue_, a_size*sizeof(T), a_source_); - r_mat.WriteBuffer(queue_, c_size*sizeof(T), c_source_); - auto status1 = clblas_lambda_(args, a_mat, r_mat, queue_); - - // Runs the CLBlast code - a_mat.WriteBuffer(queue_, a_size*sizeof(T), a_source_); - s_mat.WriteBuffer(queue_, c_size*sizeof(T), c_source_); - auto status2 = clblast_lambda_(args, a_mat, s_mat, queue_); - - // Tests for equality of the two status codes - if (status1 != StatusCode::kSuccess || status2 != StatusCode::kSuccess) { - TestErrorCodes(status1, status2, args); - continue; - } - - // Downloads the results - std::vector r_result(c_size, static_cast(0)); - std::vector s_result(c_size, static_cast(0)); - r_mat.ReadBuffer(queue_, c_size*sizeof(T), r_result); - s_mat.ReadBuffer(queue_, c_size*sizeof(T), s_result); - - // Checks for differences in the output - auto errors = size_t{0}; - for (auto idn0=size_t{0}; idn0 -void TestAC::TestInvalidBufferSizes(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("invalid buffer sizes", name); - - // Sets example test parameters - args.m = kBufferSize; - args.n = kBufferSize; - args.k = kBufferSize; - args.a_ld = kBufferSize; - args.c_ld = kBufferSize; - args.a_offset = 0; - args.c_offset = 0; - - // Iterates over test buffer sizes - const std::vector kBufferSizes = {0, kBufferSize*kBufferSize-1, kBufferSize*kBufferSize}; - for (auto &a_size: kBufferSizes) { - for (auto &c_size: kBufferSizes) { - - // Creates the OpenCL buffers. Note: we are not using the C++ version since we explicitly - // want to be able to create invalid buffers (no error checking here). - auto a = clCreateBuffer(context_(), CL_MEM_READ_WRITE, a_size*sizeof(T), nullptr, nullptr); - auto a_mat = Buffer(a); - auto r = clCreateBuffer(context_(), CL_MEM_READ_WRITE, c_size*sizeof(T), nullptr, nullptr); - auto r_mat = Buffer(r); - auto s = clCreateBuffer(context_(), CL_MEM_READ_WRITE, c_size*sizeof(T), nullptr, nullptr); - auto s_mat = Buffer(s); - - // Runs the two routines - auto status1 = clblas_lambda_(args, a_mat, r_mat, queue_); - auto status2 = clblast_lambda_(args, a_mat, s_mat, queue_); - - // Tests for equality of the two status codes - TestErrorCodes(status1, status2, args); - } - } - TestEnd(); -} - -// ================================================================================================= - -// Compiles the templated class -template class TestAC; -template class TestAC; -template class TestAC; -template class TestAC; - -// ================================================================================================= -} // namespace clblast diff --git a/test/correctness/testac.h b/test/correctness/testac.h deleted file mode 100644 index 4ab21e23..00000000 --- a/test/correctness/testac.h +++ /dev/null @@ -1,85 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file tests any mat-mat (A,C) routine. It contains two types of tests: one testing -// all sorts of input combinations, and one deliberatly testing with invalid values. -// -// ================================================================================================= - -#ifndef CLBLAST_TEST_CORRECTNESS_TESTAC_H_ -#define CLBLAST_TEST_CORRECTNESS_TESTAC_H_ - -#include -#include - -#include "correctness/tester.h" - -namespace clblast { -// ================================================================================================= - -// See comment at top of file for a description of the class -template -class TestAC: public Tester { - public: - - // Uses several variables from the Tester class - using Tester::context_; - using Tester::queue_; - using Tester::kLayouts; - using Tester::kTransposes; - - // Uses several helper functions from the Tester class - using Tester::TestStart; - using Tester::TestEnd; - using Tester::TestSimilarity; - using Tester::TestErrorCount; - using Tester::TestErrorCodes; - using Tester::GetExampleScalars; - using Tester::GetOffsets; - using Tester::PrecisionSupported; - - // Test settings for the regular test. Append to this list in case more tests are required. - const std::vector kMatrixDims = { 7, 64 }; - const std::vector kOffsets = GetOffsets(); - const std::vector kAlphaValues = GetExampleScalars(); - const std::vector kBetaValues = GetExampleScalars(); - - // Test settings for the invalid test - const size_t kBufferSize = 64; - - // Shorthand for a BLAS routine - using Routine = std::function&, - const Buffer&, const Buffer&, - CommandQueue&)>; - - // Constructor, initializes the base class tester and input data - TestAC(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda); - - // The test functions, taking no inputs - void TestRegular(Arguments &args, const std::string &name); - void TestInvalidBufferSizes(Arguments &args, const std::string &name); - - private: - - // Source data to test with - std::vector a_source_; - std::vector c_source_; - - // The routines to test - Routine clblast_lambda_; - Routine clblas_lambda_; -}; - -// ================================================================================================= -} // namespace clblast - -// CLBLAST_TEST_CORRECTNESS_TESTAC_H_ -#endif diff --git a/test/correctness/testaxy.cc b/test/correctness/testaxy.cc deleted file mode 100644 index cb5e9923..00000000 --- a/test/correctness/testaxy.cc +++ /dev/null @@ -1,213 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file implements the TestAXY class (see the header for information about the class). -// -// ================================================================================================= - -#include - -#include "correctness/testaxy.h" - -namespace clblast { -// ================================================================================================= - -// Constructor, initializes the base class tester and input data -template -TestAXY::TestAXY(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda): - Tester{argc, argv, silent, name, options}, - clblast_lambda_(clblast_lambda), - clblas_lambda_(clblas_lambda) { - - // Computes the maximum sizes. This allows for a single set of input/output buffers. - auto max_dim = *std::max_element(kMatrixVectorDims.begin(), kMatrixVectorDims.end()); - auto max_ld = *std::max_element(kMatrixVectorDims.begin(), kMatrixVectorDims.end()); - auto max_inc = *std::max_element(kIncrements.begin(), kIncrements.end()); - auto max_offset = *std::max_element(kOffsets.begin(), kOffsets.end()); - - // Creates test input data - a_source_.resize(max_dim*max_ld + max_offset); - x_source_.resize(max_dim*max_inc + max_offset); - y_source_.resize(max_dim*max_inc + max_offset); - PopulateVector(a_source_); - PopulateVector(x_source_); - PopulateVector(y_source_); -} - -// =============================================================================================== - -// Tests the routine for a wide variety of parameters -template -void TestAXY::TestRegular(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("regular behaviour", name); - - // Iterates over the dimension for the matrix and vectors - for (auto &m: kMatrixVectorDims) { - args.m = m; - for (auto &n: kMatrixVectorDims) { - args.n = n; - - // Computes the second dimension of the matrix taking the rotation into account - auto a_two = (args.layout == Layout::kRowMajor) ? args.m : args.n; - - // Computes the vector sizes in case the matrix is transposed - auto a_transposed = (args.a_transpose == Transpose::kYes); - auto m_real = (a_transposed) ? n : m; - auto n_real = (a_transposed) ? m : n; - - // Iterates over the leading-dimension values and the offsets of the matrix - for (auto &a_ld: kMatrixVectorDims) { - args.a_ld = a_ld; - for (auto &a_offset: kOffsets) { - args.a_offset = a_offset; - - // Iterates over the increment-values and the offsets of the vectors - for (auto &x_inc: kIncrements) { - args.x_inc = x_inc; - for (auto &x_offset: kOffsets) { - args.x_offset = x_offset; - for (auto &y_inc: kIncrements) { - args.y_inc = y_inc; - for (auto &y_offset: kOffsets) { - args.y_offset = y_offset; - - // Computes the buffer sizes - auto a_size = a_two * a_ld + a_offset; - auto x_size = n_real * x_inc + x_offset; - auto y_size = m_real * y_inc + y_offset; - if (a_size < 1 || x_size < 1 || y_size < 1) { continue; } - - // Creates the OpenCL buffers - auto a_mat = Buffer(context_, CL_MEM_READ_WRITE, a_size*sizeof(T)); - auto x_vec = Buffer(context_, CL_MEM_READ_WRITE, x_size*sizeof(T)); - auto r_vec = Buffer(context_, CL_MEM_READ_WRITE, y_size*sizeof(T)); - auto s_vec = Buffer(context_, CL_MEM_READ_WRITE, y_size*sizeof(T)); - - // Iterates over the values for alpha and beta - for (auto &alpha: kAlphaValues) { - args.alpha = alpha; - for (auto &beta: kBetaValues) { - args.beta = beta; - - // Runs the reference clBLAS code - a_mat.WriteBuffer(queue_, a_size*sizeof(T), a_source_); - x_vec.WriteBuffer(queue_, x_size*sizeof(T), x_source_); - r_vec.WriteBuffer(queue_, y_size*sizeof(T), y_source_); - auto status1 = clblas_lambda_(args, a_mat, x_vec, r_vec, queue_); - - // Runs the CLBlast code - a_mat.WriteBuffer(queue_, a_size*sizeof(T), a_source_); - x_vec.WriteBuffer(queue_, x_size*sizeof(T), x_source_); - s_vec.WriteBuffer(queue_, y_size*sizeof(T), y_source_); - auto status2 = clblast_lambda_(args, a_mat, x_vec, s_vec, queue_); - - // Tests for equality of the two status codes - if (status1 != StatusCode::kSuccess || status2 != StatusCode::kSuccess) { - TestErrorCodes(status1, status2, args); - continue; - } - - // Downloads the results - std::vector r_result(y_size, static_cast(0)); - std::vector s_result(y_size, static_cast(0)); - r_vec.ReadBuffer(queue_, y_size*sizeof(T), r_result); - s_vec.ReadBuffer(queue_, y_size*sizeof(T), s_result); - - // Checks for differences in the output - auto errors = size_t{0}; - for (auto idm=size_t{0}; idm -void TestAXY::TestInvalidBufferSizes(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("invalid buffer sizes", name); - - // Sets example test parameters - args.m = kBufferSize; - args.n = kBufferSize; - args.a_ld = kBufferSize; - args.a_offset = 0; - args.x_offset = 0; - args.y_offset = 0; - - // Iterates over test buffer sizes - const std::vector kMatrixSizes = {0, kBufferSize*kBufferSize-1, kBufferSize*kBufferSize}; - const std::vector kVectorSizes = {0, kBufferSize - 1, kBufferSize}; - for (auto &a_size: kMatrixSizes) { - for (auto &x_size: kVectorSizes) { - for (auto &y_size: kVectorSizes) { - - // Iterates over test increments - for (auto &x_inc: kInvalidIncrements) { - args.x_inc = x_inc; - for (auto &y_inc: kInvalidIncrements) { - args.y_inc = y_inc; - - // Creates the OpenCL buffers. Note: we are not using the C++ version since we - // explicitly want to be able to create invalid buffers (no error checking here). - auto a = clCreateBuffer(context_(), CL_MEM_READ_WRITE, a_size*sizeof(T), nullptr, nullptr); - auto a_mat = Buffer(a); - auto x = clCreateBuffer(context_(), CL_MEM_READ_WRITE, x_size*sizeof(T), nullptr, nullptr); - auto x_vec = Buffer(x); - auto r = clCreateBuffer(context_(), CL_MEM_READ_WRITE, y_size*sizeof(T), nullptr, nullptr); - auto r_vec = Buffer(r); - auto s = clCreateBuffer(context_(), CL_MEM_READ_WRITE, y_size*sizeof(T), nullptr, nullptr); - auto s_vec = Buffer(s); - - // Runs the two routines - auto status1 = clblas_lambda_(args, a_mat, x_vec, r_vec, queue_); - auto status2 = clblast_lambda_(args, a_mat, x_vec, s_vec, queue_); - - // Tests for equality of the two status codes - TestErrorCodes(status1, status2, args); - } - } - } - } - } - TestEnd(); -} - -// ================================================================================================= - -// Compiles the templated class -template class TestAXY; -template class TestAXY; -template class TestAXY; -template class TestAXY; - -// ================================================================================================= -} // namespace clblast diff --git a/test/correctness/testaxy.h b/test/correctness/testaxy.h deleted file mode 100644 index fa2c4a98..00000000 --- a/test/correctness/testaxy.h +++ /dev/null @@ -1,88 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file tests any mat-vec-vec (A,X,Y) routine. It contains two types of tests: one testing -// all sorts of input combinations, and one deliberatly testing with invalid values. -// -// ================================================================================================= - -#ifndef CLBLAST_TEST_CORRECTNESS_TESTAXY_H_ -#define CLBLAST_TEST_CORRECTNESS_TESTAXY_H_ - -#include -#include - -#include "correctness/tester.h" - -namespace clblast { -// ================================================================================================= - -// See comment at top of file for a description of the class -template -class TestAXY: public Tester { - public: - - // Uses several variables from the Tester class - using Tester::context_; - using Tester::queue_; - using Tester::kLayouts; - using Tester::kTransposes; - - // Uses several helper functions from the Tester class - using Tester::TestStart; - using Tester::TestEnd; - using Tester::TestSimilarity; - using Tester::TestErrorCount; - using Tester::TestErrorCodes; - using Tester::GetExampleScalars; - using Tester::GetOffsets; - using Tester::PrecisionSupported; - - // Test settings for the regular test. Append to this list in case more tests are required. - const std::vector kMatrixVectorDims = { 61, 512 }; - const std::vector kOffsets = GetOffsets(); - const std::vector kIncrements = { 1, 2 }; - const std::vector kAlphaValues = GetExampleScalars(); - const std::vector kBetaValues = GetExampleScalars(); - - // Test settings for the invalid test - const std::vector kInvalidIncrements = { 0, 1 }; - const size_t kBufferSize = 64; - - // Shorthand for a BLAS routine - using Routine = std::function&, - const Buffer&, const Buffer&, const Buffer&, - CommandQueue&)>; - - // Constructor, initializes the base class tester and input data - TestAXY(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda); - - // The test functions, taking no inputs - void TestRegular(Arguments &args, const std::string &name); - void TestInvalidBufferSizes(Arguments &args, const std::string &name); - - private: - - // Source data to test with - std::vector a_source_; - std::vector x_source_; - std::vector y_source_; - - // The routines to test - Routine clblast_lambda_; - Routine clblas_lambda_; -}; - -// ================================================================================================= -} // namespace clblast - -// CLBLAST_TEST_CORRECTNESS_TESTAXY_H_ -#endif diff --git a/test/correctness/testblas.cc b/test/correctness/testblas.cc new file mode 100644 index 00000000..019d93ee --- /dev/null +++ b/test/correctness/testblas.cc @@ -0,0 +1,185 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under the MIT license. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file implements the TestBlas class (see the header for information about the class). +// +// ================================================================================================= + +#include + +#include "correctness/testblas.h" + +namespace clblast { +// ================================================================================================= + +// The transpose-options to test with (data-type dependent) +template <> const std::vector TestBlas::kTransposes = {Transpose::kNo, Transpose::kYes}; +template <> const std::vector TestBlas::kTransposes = {Transpose::kNo, Transpose::kYes}; +template <> const std::vector TestBlas::kTransposes = {Transpose::kNo, Transpose::kYes, Transpose::kConjugate}; +template <> const std::vector TestBlas::kTransposes = {Transpose::kNo, Transpose::kYes, Transpose::kConjugate}; + +// ================================================================================================= + +// Constructor, initializes the base class tester and input data +template +TestBlas::TestBlas(int argc, char *argv[], const bool silent, + const std::string &name, const std::vector &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): + Tester{argc, argv, silent, name, options}, + run_routine_(run_routine), + run_reference_(run_reference), + get_result_(get_result), + get_index_(get_index), + get_id1_(get_id1), + get_id2_(get_id2) { + + // Computes the maximum sizes. This allows for a single set of input/output buffers. + auto max_vec = *std::max_element(kVectorDims.begin(), kVectorDims.end()); + auto max_inc = *std::max_element(kIncrements.begin(), kIncrements.end()); + auto max_mat = *std::max_element(kMatrixDims.begin(), kMatrixDims.end()); + auto max_ld = *std::max_element(kMatrixDims.begin(), kMatrixDims.end()); + auto max_matvec = *std::max_element(kMatrixVectorDims.begin(), kMatrixVectorDims.end()); + auto max_offset = *std::max_element(kOffsets.begin(), kOffsets.end()); + + // Creates test input data + x_source_.resize(std::max(max_vec, max_matvec)*max_inc + max_offset); + y_source_.resize(std::max(max_vec, max_matvec)*max_inc + max_offset); + a_source_.resize(std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset); + b_source_.resize(std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset); + c_source_.resize(std::max(max_mat, max_matvec)*std::max(max_ld, max_matvec) + max_offset); + PopulateVector(x_source_); + PopulateVector(y_source_); + PopulateVector(a_source_); + PopulateVector(b_source_); + PopulateVector(c_source_); +} + +// =============================================================================================== + +// Tests the routine for a wide variety of parameters +template +void TestBlas::TestRegular(std::vector> &test_vector, const std::string &name) { + if (!PrecisionSupported()) { return; } + TestStart("regular behaviour", name); + + // Iterates over all the to-be-tested combinations of arguments + for (auto &args: test_vector) { + + // Runs the reference clBLAS code + auto x_vec1 = Buffer(context_, CL_MEM_READ_WRITE, args.x_size*sizeof(T)); + auto y_vec1 = Buffer(context_, CL_MEM_READ_WRITE, args.y_size*sizeof(T)); + auto a_mat1 = Buffer(context_, CL_MEM_READ_WRITE, args.a_size*sizeof(T)); + auto b_mat1 = Buffer(context_, CL_MEM_READ_WRITE, args.b_size*sizeof(T)); + auto c_mat1 = Buffer(context_, CL_MEM_READ_WRITE, args.c_size*sizeof(T)); + x_vec1.WriteBuffer(queue_, args.x_size*sizeof(T), x_source_); + y_vec1.WriteBuffer(queue_, args.y_size*sizeof(T), y_source_); + a_mat1.WriteBuffer(queue_, args.a_size*sizeof(T), a_source_); + b_mat1.WriteBuffer(queue_, args.b_size*sizeof(T), b_source_); + c_mat1.WriteBuffer(queue_, args.c_size*sizeof(T), c_source_); + auto buffers1 = Buffers{x_vec1, y_vec1, a_mat1, b_mat1, c_mat1}; + auto status1 = run_reference_(args, buffers1, queue_); + + // Runs the CLBlast code + auto x_vec2 = Buffer(context_, CL_MEM_READ_WRITE, args.x_size*sizeof(T)); + auto y_vec2 = Buffer(context_, CL_MEM_READ_WRITE, args.y_size*sizeof(T)); + auto a_mat2 = Buffer(context_, CL_MEM_READ_WRITE, args.a_size*sizeof(T)); + auto b_mat2 = Buffer(context_, CL_MEM_READ_WRITE, args.b_size*sizeof(T)); + auto c_mat2 = Buffer(context_, CL_MEM_READ_WRITE, args.c_size*sizeof(T)); + x_vec2.WriteBuffer(queue_, args.x_size*sizeof(T), x_source_); + y_vec2.WriteBuffer(queue_, args.y_size*sizeof(T), y_source_); + a_mat2.WriteBuffer(queue_, args.a_size*sizeof(T), a_source_); + b_mat2.WriteBuffer(queue_, args.b_size*sizeof(T), b_source_); + c_mat2.WriteBuffer(queue_, args.c_size*sizeof(T), c_source_); + auto buffers2 = Buffers{x_vec2, y_vec2, a_mat2, b_mat2, c_mat2}; + auto status2 = run_routine_(args, buffers2, queue_); + + // Tests for equality of the two status codes + if (status1 != StatusCode::kSuccess || status2 != StatusCode::kSuccess) { + TestErrorCodes(status1, status2, args); + continue; + } + + // Downloads the results + auto result1 = get_result_(args, buffers1, queue_); + auto result2 = get_result_(args, buffers2, queue_); + + // Checks for differences in the output + auto errors = size_t{0}; + for (auto id1=size_t{0}; id1 +void TestBlas::TestInvalid(std::vector> &test_vector, const std::string &name) { + if (!PrecisionSupported()) { return; } + TestStart("invalid buffer sizes", name); + + // Iterates over all the to-be-tested combinations of arguments + for (auto &args: test_vector) { + + // Creates the OpenCL buffers. Note: we are not using the C++ version since we explicitly + // want to be able to create invalid buffers (no error checking here). + auto x1 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.x_size*sizeof(T), nullptr,nullptr); + auto y1 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.y_size*sizeof(T), nullptr,nullptr); + auto a1 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.a_size*sizeof(T), nullptr,nullptr); + auto b1 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.b_size*sizeof(T), nullptr,nullptr); + auto c1 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.c_size*sizeof(T), nullptr,nullptr); + auto x_vec1 = Buffer(x1); + auto y_vec1 = Buffer(y1); + auto a_mat1 = Buffer(a1); + auto b_mat1 = Buffer(b1); + auto c_mat1 = Buffer(c1); + auto x2 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.x_size*sizeof(T), nullptr,nullptr); + auto y2 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.y_size*sizeof(T), nullptr,nullptr); + auto a2 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.a_size*sizeof(T), nullptr,nullptr); + auto b2 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.b_size*sizeof(T), nullptr,nullptr); + auto c2 = clCreateBuffer(context_(), CL_MEM_READ_WRITE, args.c_size*sizeof(T), nullptr,nullptr); + auto x_vec2 = Buffer(x2); + auto y_vec2 = Buffer(y2); + auto a_mat2 = Buffer(a2); + auto b_mat2 = Buffer(b2); + auto c_mat2 = Buffer(c2); + + // Runs the two routines + auto status1 = run_reference_(args, Buffers{x_vec1, y_vec1, a_mat1, b_mat1, c_mat1}, queue_); + auto status2 = run_routine_(args, Buffers{x_vec2, y_vec2, a_mat2, b_mat2, c_mat2}, queue_); + + // Tests for equality of the two status codes + TestErrorCodes(status1, status2, args); + } + TestEnd(); +} + +// ================================================================================================= + +// Compiles the templated class +template class TestBlas; +template class TestBlas; +template class TestBlas; +template class TestBlas; + +// ================================================================================================= +} // namespace clblast diff --git a/test/correctness/testblas.h b/test/correctness/testblas.h new file mode 100644 index 00000000..0593aaee --- /dev/null +++ b/test/correctness/testblas.h @@ -0,0 +1,104 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under the MIT license. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file tests any CLBlast routine. It contains two types of tests: one testing all sorts of +// input combinations, and one deliberatly testing with invalid values. +// +// ================================================================================================= + +#ifndef CLBLAST_TEST_CORRECTNESS_TESTBLAS_H_ +#define CLBLAST_TEST_CORRECTNESS_TESTBLAS_H_ + +#include +#include + +#include "correctness/tester.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template +class TestBlas: public Tester { + public: + + // Uses several variables from the Tester class + using Tester::context_; + using Tester::queue_; + + // Uses several helper functions from the Tester class + using Tester::TestStart; + using Tester::TestEnd; + using Tester::TestSimilarity; + using Tester::TestErrorCount; + using Tester::TestErrorCodes; + using Tester::GetExampleScalars; + using Tester::GetOffsets; + using Tester::PrecisionSupported; + + // Test settings for the regular test. Append to these lists in case more tests are required. + const std::vector kVectorDims = { 7, 93, 4096 }; + const std::vector kIncrements = { 1, 2, 7 }; + const std::vector kMatrixDims = { 7, 64 }; + const std::vector kMatrixVectorDims = { 61, 512 }; + const std::vector kOffsets = GetOffsets(); + const std::vector kAlphaValues = GetExampleScalars(); + const std::vector kBetaValues = GetExampleScalars(); + + // Test settings for the invalid tests + const std::vector kInvalidIncrements = { 0, 1 }; + const size_t kBufferSize = 64; + const std::vector kMatSizes = {0, kBufferSize*kBufferSize-1, kBufferSize*kBufferSize}; + const std::vector kVecSizes = {0, kBufferSize - 1, kBufferSize}; + + // The layout/transpose/triangle options to test with + const std::vector kLayouts = {Layout::kRowMajor, Layout::kColMajor}; + const std::vector kTriangles = {Triangle::kUpper, Triangle::kLower}; + const std::vector kSides = {Side::kLeft, Side::kRight}; + static const std::vector kTransposes; // Data-type dependent, see .cc-file + + // Shorthand for the routine-specific functions passed to the tester + using Routine = std::function&, const Buffers&, CommandQueue&)>; + using ResultGet = std::function(const Arguments&, Buffers&, CommandQueue&)>; + using ResultIndex = std::function&, const size_t, const size_t)>; + using ResultIterator = std::function&)>; + + // Constructor, initializes the base class tester and input data + TestBlas(int argc, char *argv[], const bool silent, + const std::string &name, const std::vector &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); + + // The test functions, taking no inputs + void TestRegular(std::vector> &test_vector, const std::string &name); + void TestInvalid(std::vector> &test_vector, const std::string &name); + + private: + + // Source data to test with + std::vector x_source_; + std::vector y_source_; + std::vector a_source_; + std::vector b_source_; + std::vector c_source_; + + // The routine-specific functions passed to the tester + Routine run_routine_; + Routine run_reference_; + ResultGet get_result_; + ResultIndex get_index_; + ResultIterator get_id1_; + ResultIterator get_id2_; +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_CORRECTNESS_TESTBLAS_H_ +#endif diff --git a/test/correctness/tester.cc b/test/correctness/tester.cc index 501f1906..4a179718 100644 --- a/test/correctness/tester.cc +++ b/test/correctness/tester.cc @@ -21,16 +21,6 @@ namespace clblast { // ================================================================================================= -// The layouts and transpose-options to test with (data-type dependent) -template -const std::vector Tester::kLayouts = {Layout::kRowMajor, Layout::kColMajor}; -template <> const std::vector Tester::kTransposes = {Transpose::kNo, Transpose::kYes}; -template <> const std::vector Tester::kTransposes = {Transpose::kNo, Transpose::kYes}; -template <> const std::vector Tester::kTransposes = {Transpose::kNo, Transpose::kYes, Transpose::kConjugate}; -template <> const std::vector Tester::kTransposes = {Transpose::kNo, Transpose::kYes, Transpose::kConjugate}; - -// ================================================================================================= - // General constructor for all CLBlast testers. It prints out the test header to stdout and sets-up // the clBLAS library for reference. template diff --git a/test/correctness/tester.h b/test/correctness/tester.h index 3b6fa059..9c4a9e86 100644 --- a/test/correctness/tester.h +++ b/test/correctness/tester.h @@ -62,10 +62,6 @@ class Tester { const std::string kSkippedCompilation{kPrintWarning + "\\" + kPrintEnd}; const std::string kUnsupportedPrecision{kPrintWarning + "o" + kPrintEnd}; - // The layouts and transpose-options to test with - static const std::vector kLayouts; - static const std::vector kTransposes; - // This structure combines the above log-entry with a status code an error percentage struct ErrorLogEntry { StatusCode status_expect; diff --git a/test/correctness/testxy.cc b/test/correctness/testxy.cc deleted file mode 100644 index 5c86182c..00000000 --- a/test/correctness/testxy.cc +++ /dev/null @@ -1,176 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file implements the TestXY class (see the header for information about the class). -// -// ================================================================================================= - -#include - -#include "correctness/testxy.h" - -namespace clblast { -// ================================================================================================= - -// Constructor, initializes the base class tester and input data -template -TestXY::TestXY(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda): - Tester{argc, argv, silent, name, options}, - clblast_lambda_(clblast_lambda), - clblas_lambda_(clblas_lambda) { - - // Computes the maximum sizes. This allows for a single set of input/output buffers. - auto max_dim = *std::max_element(kVectorDims.begin(), kVectorDims.end()); - auto max_inc = *std::max_element(kIncrements.begin(), kIncrements.end()); - auto max_offset = *std::max_element(kOffsets.begin(), kOffsets.end()); - - // Creates test input data - x_source_.resize(max_dim*max_inc + max_offset); - y_source_.resize(max_dim*max_inc + max_offset); - PopulateVector(x_source_); - PopulateVector(y_source_); -} - -// =============================================================================================== - -// Tests the routine for a wide variety of parameters -template -void TestXY::TestRegular(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("regular behaviour", name); - - // Iterates over the vector dimension - for (auto &n: kVectorDims) { - args.n = n; - - // Iterates over the increment-values and the offsets - for (auto &x_inc: kIncrements) { - args.x_inc = x_inc; - for (auto &x_offset: kOffsets) { - args.x_offset = x_offset; - for (auto &y_inc: kIncrements) { - args.y_inc = y_inc; - for (auto &y_offset: kOffsets) { - args.y_offset = y_offset; - - // Computes the buffer sizes - auto x_size = n * x_inc + x_offset; - auto y_size = n * y_inc + y_offset; - if (x_size < 1 || y_size < 1) { continue; } - - // Creates the OpenCL buffers - auto x_vec = Buffer(context_, CL_MEM_READ_WRITE, x_size*sizeof(T)); - auto r_vec = Buffer(context_, CL_MEM_READ_WRITE, y_size*sizeof(T)); - auto s_vec = Buffer(context_, CL_MEM_READ_WRITE, y_size*sizeof(T)); - - // Iterates over the values for alpha - for (auto &alpha: kAlphaValues) { - args.alpha = alpha; - - // Runs the reference clBLAS code - x_vec.WriteBuffer(queue_, x_size*sizeof(T), x_source_); - r_vec.WriteBuffer(queue_, y_size*sizeof(T), y_source_); - auto status1 = clblas_lambda_(args, x_vec, r_vec, queue_); - - // Runs the CLBlast code - x_vec.WriteBuffer(queue_, x_size*sizeof(T), x_source_); - s_vec.WriteBuffer(queue_, y_size*sizeof(T), y_source_); - auto status2 = clblast_lambda_(args, x_vec, s_vec, queue_); - - // Tests for equality of the two status codes - if (status1 != StatusCode::kSuccess || status2 != StatusCode::kSuccess) { - TestErrorCodes(status1, status2, args); - continue; - } - - // Downloads the results - std::vector r_result(y_size, static_cast(0)); - std::vector s_result(y_size, static_cast(0)); - r_vec.ReadBuffer(queue_, y_size*sizeof(T), r_result); - s_vec.ReadBuffer(queue_, y_size*sizeof(T), s_result); - - // Checks for differences in the output - auto errors = size_t{0}; - for (auto idn=size_t{0}; idn -void TestXY::TestInvalidBufferSizes(Arguments &args, const std::string &name) { - if (!PrecisionSupported()) { return; } - TestStart("invalid buffer sizes", name); - - // Sets example test parameters - args.n = kBufferSize; - args.x_offset = 0; - args.y_offset = 0; - - // Iterates over test buffer sizes - const std::vector kBufferSizes = {0, kBufferSize - 1, kBufferSize}; - for (auto &x_size: kBufferSizes) { - for (auto &y_size: kBufferSizes) { - - // Iterates over test increments - for (auto &x_inc: kInvalidIncrements) { - args.x_inc = x_inc; - for (auto &y_inc: kInvalidIncrements) { - args.y_inc = y_inc; - - // Creates the OpenCL buffers. Note: we are not using the C++ version since we explicitly - // want to be able to create invalid buffers (no error checking here). - auto x = clCreateBuffer(context_(), CL_MEM_READ_WRITE, x_size*sizeof(T), nullptr, nullptr); - auto x_vec = Buffer(x); - auto r = clCreateBuffer(context_(), CL_MEM_READ_WRITE, y_size*sizeof(T), nullptr, nullptr); - auto r_vec = Buffer(r); - auto s = clCreateBuffer(context_(), CL_MEM_READ_WRITE, y_size*sizeof(T), nullptr, nullptr); - auto s_vec = Buffer(s); - - // Runs the two routines - auto status1 = clblas_lambda_(args, x_vec, r_vec, queue_); - auto status2 = clblast_lambda_(args, x_vec, s_vec, queue_); - - // Tests for equality of the two status codes - TestErrorCodes(status1, status2, args); - } - } - } - } - TestEnd(); -} - -// ================================================================================================= - -// Compiles the templated class -template class TestXY; -template class TestXY; -template class TestXY; -template class TestXY; - -// ================================================================================================= -} // namespace clblast diff --git a/test/correctness/testxy.h b/test/correctness/testxy.h deleted file mode 100644 index ec2cbcc7..00000000 --- a/test/correctness/testxy.h +++ /dev/null @@ -1,84 +0,0 @@ - -// ================================================================================================= -// This file is part of the CLBlast project. The project is licensed under the MIT license. This -// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- -// width of 100 characters per line. -// -// Author(s): -// Cedric Nugteren -// -// This file tests any vector-vector (X,Y) routine. It contains two types of tests: one testing -// all sorts of input combinations, and one deliberatly testing with invalid values. -// -// ================================================================================================= - -#ifndef CLBLAST_TEST_CORRECTNESS_TESTXY_H_ -#define CLBLAST_TEST_CORRECTNESS_TESTXY_H_ - -#include -#include - -#include "correctness/tester.h" - -namespace clblast { -// ================================================================================================= - -// See comment at top of file for a description of the class -template -class TestXY: public Tester { - public: - - // Uses several variables from the Tester class - using Tester::context_; - using Tester::queue_; - - // Uses several helper functions from the Tester class - using Tester::TestStart; - using Tester::TestEnd; - using Tester::TestSimilarity; - using Tester::TestErrorCount; - using Tester::TestErrorCodes; - using Tester::GetExampleScalars; - using Tester::GetOffsets; - using Tester::PrecisionSupported; - - // Test settings for the regular test. Append to this list in case more tests are required. - const std::vector kVectorDims = { 7, 93, 4096 }; - const std::vector kOffsets = GetOffsets(); - const std::vector kIncrements = { 1, 2, 7 }; - const std::vector kAlphaValues = GetExampleScalars(); - - // Test settings for the invalid test - const std::vector kInvalidIncrements = { 0, 1 }; - const size_t kBufferSize = 512; - - // Shorthand for a BLAS routine - using Routine = std::function&, - const Buffer&, const Buffer&, - CommandQueue&)>; - - // Constructor, initializes the base class tester and input data - TestXY(int argc, char *argv[], const bool silent, - const std::string &name, const std::vector &options, - const Routine clblast_lambda, const Routine clblas_lambda); - - // The test functions, taking no inputs - void TestRegular(Arguments &args, const std::string &name); - void TestInvalidBufferSizes(Arguments &args, const std::string &name); - - private: - - // Source data to test with - std::vector x_source_; - std::vector y_source_; - - // The routines to test - Routine clblast_lambda_; - Routine clblas_lambda_; -}; - -// ================================================================================================= -} // namespace clblast - -// CLBLAST_TEST_CORRECTNESS_TESTXY_H_ -#endif diff --git a/test/routines/xaxpy.h b/test/routines/xaxpy.h new file mode 100644 index 00000000..b61dd3b5 --- /dev/null +++ b/test/routines/xaxpy.h @@ -0,0 +1,94 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under the MIT license. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file implements a class with static methods to describe the Xaxpy routine. Examples of +// such 'descriptions' are how to calculate the size a of buffer or how to run the routine. These +// static methods are used by the correctness tester and the performance tester. +// +// ================================================================================================= + +#ifndef CLBLAST_TEST_ROUTINES_XAXPY_H_ +#define CLBLAST_TEST_ROUTINES_XAXPY_H_ + +#include +#include + +#include "wrapper_clblas.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template +class TestXaxpy { + public: + + // The list of arguments relevant for this routine + static std::vector GetOptions() { + return {kArgN, + kArgXInc, kArgYInc, + kArgXOffset, kArgYOffset, + kArgAlpha}; + } + + // Describes how to obtain the sizes of the buffers + static size_t GetSizeX(const Arguments &args) { + return args.n * args.x_inc + args.x_offset; + } + static size_t GetSizeY(const Arguments &args) { + return args.n * args.y_inc + args.y_offset; + } + + // Describes how to run the CLBlast routine + static StatusCode RunRoutine(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = Axpy(args.n, args.alpha, + buffers.x_vec(), args.x_offset, args.x_inc, + buffers.y_vec(), args.y_offset, args.y_inc, + &queue_plain, &event); + clWaitForEvents(1, &event); + return status; + } + + // Describes how to run the clBLAS routine (for correctness/performance comparison) + static StatusCode RunReference(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = clblasXaxpy(args.n, args.alpha, + buffers.x_vec(), args.x_offset, args.x_inc, + buffers.y_vec(), args.y_offset, args.y_inc, + 1, &queue_plain, 0, nullptr, &event); + clWaitForEvents(1, &event); + return static_cast(status); + } + + // Describes how to download the results of the computation (more importantly: which buffer) + static std::vector DownloadResult(const Arguments &args, Buffers &buffers, + CommandQueue &queue) { + std::vector result(args.y_size, static_cast(0)); + buffers.y_vec.ReadBuffer(queue, args.y_size*sizeof(T), result); + return result; + } + + // Describes how to compute the indices of the result buffer + static size_t ResultID1(const Arguments &args) { return args.n; } + static size_t ResultID2(const Arguments &args) { return 1; } // N/A for this routine + static size_t GetResultIndex(const Arguments &args, const size_t id1, const size_t id2) { + return id1*args.y_inc + args.y_offset; + } +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_ROUTINES_XAXPY_H_ +#endif diff --git a/test/routines/xgemm.h b/test/routines/xgemm.h new file mode 100644 index 00000000..c93fa774 --- /dev/null +++ b/test/routines/xgemm.h @@ -0,0 +1,114 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under the MIT license. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file implements a class with static methods to describe the Xgemm routine. Examples of +// such 'descriptions' are how to calculate the size a of buffer or how to run the routine. These +// static methods are used by the correctness tester and the performance tester. +// +// ================================================================================================= + +#ifndef CLBLAST_TEST_ROUTINES_XGEMM_H_ +#define CLBLAST_TEST_ROUTINES_XGEMM_H_ + +#include +#include + +#include "wrapper_clblas.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template +class TestXgemm { + public: + + // The list of arguments relevant for this routine + static std::vector GetOptions() { + return {kArgM, kArgN, kArgK, + kArgLayout, kArgATransp, kArgBTransp, + kArgALeadDim, kArgBLeadDim, kArgCLeadDim, + kArgAOffset, kArgBOffset, kArgCOffset, + kArgAlpha, kArgBeta}; + } + + // Describes how to obtain the sizes of the buffers + static size_t GetSizeA(const Arguments &args) { + auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) || + (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo); + auto a_two = (a_rotated) ? args.m : args.k; + return a_two * args.a_ld + args.a_offset; + } + static size_t GetSizeB(const Arguments &args) { + auto b_rotated = (args.layout == Layout::kColMajor && args.b_transpose != Transpose::kNo) || + (args.layout == Layout::kRowMajor && args.b_transpose == Transpose::kNo); + auto b_two = (b_rotated) ? args.k : args.n; + return b_two * args.b_ld + args.b_offset; + } + static size_t GetSizeC(const Arguments &args) { + auto c_rotated = (args.layout == Layout::kRowMajor); + auto c_two = (c_rotated) ? args.m : args.n; + return c_two * args.c_ld + args.c_offset; + } + + // Describes how to run the CLBlast routine + static StatusCode RunRoutine(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = Gemm(args.layout, args.a_transpose, args.b_transpose, + args.m, args.n, args.k, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, + buffers.b_mat(), args.b_offset, args.b_ld, args.beta, + buffers.c_mat(), args.c_offset, args.c_ld, + &queue_plain, &event); + clWaitForEvents(1, &event); + return status; + } + + // Describes how to run the clBLAS routine (for correctness/performance comparison) + static StatusCode RunReference(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = clblasXgemm(static_cast(args.layout), + static_cast(args.a_transpose), + static_cast(args.b_transpose), + args.m, args.n, args.k, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, + buffers.b_mat(), args.b_offset, args.b_ld, args.beta, + buffers.c_mat(), args.c_offset, args.c_ld, + 1, &queue_plain, 0, nullptr, &event); + clWaitForEvents(1, &event); + return static_cast(status); + } + + // Describes how to download the results of the computation (more importantly: which buffer) + static std::vector DownloadResult(const Arguments &args, Buffers &buffers, + CommandQueue &queue) { + std::vector result(args.c_size, static_cast(0)); + buffers.c_mat.ReadBuffer(queue, args.c_size*sizeof(T), result); + return result; + } + + // Describes how to compute the indices of the result buffer + static size_t ResultID1(const Arguments &args) { return args.m; } + static size_t ResultID2(const Arguments &args) { return args.n; } + static size_t GetResultIndex(const Arguments &args, const size_t id1, const size_t id2) { + return (args.layout == Layout::kRowMajor) ? + id1*args.c_ld + id2 + args.c_offset: + id2*args.c_ld + id1 + args.c_offset; + } +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_ROUTINES_XGEMM_H_ +#endif diff --git a/test/routines/xgemv.h b/test/routines/xgemv.h new file mode 100644 index 00000000..ada3d6f4 --- /dev/null +++ b/test/routines/xgemv.h @@ -0,0 +1,112 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under the MIT license. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file implements a class with static methods to describe the Xgemv routine. Examples of +// such 'descriptions' are how to calculate the size a of buffer or how to run the routine. These +// static methods are used by the correctness tester and the performance tester. +// +// ================================================================================================= + +#ifndef CLBLAST_TEST_ROUTINES_XGEMV_H_ +#define CLBLAST_TEST_ROUTINES_XGEMV_H_ + +#include +#include + +#include "wrapper_clblas.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template +class TestXgemv { + public: + + // The list of arguments relevant for this routine + static std::vector GetOptions() { + return {kArgM, kArgN, + kArgLayout, kArgATransp, + kArgALeadDim, kArgXInc, kArgYInc, + kArgAOffset, kArgXOffset, kArgYOffset, + kArgAlpha, kArgBeta}; + } + + // Describes how to obtain the sizes of the buffers + static size_t GetSizeA(const Arguments &args) { + auto a_rotated = (args.layout == Layout::kRowMajor); + auto a_two = (a_rotated) ? args.m : args.n; + return a_two * args.a_ld + args.a_offset; + } + static size_t GetSizeX(const Arguments &args) { + auto a_transposed = (args.a_transpose != Transpose::kNo); + auto n_real = (a_transposed) ? args.m : args.n; + return n_real * args.x_inc + args.x_offset; + } + static size_t GetSizeY(const Arguments &args) { + auto a_transposed = (args.a_transpose != Transpose::kNo); + auto m_real = (a_transposed) ? args.n : args.m; + return m_real * args.y_inc + args.y_offset; + } + + // Describes how to run the CLBlast routine + static StatusCode RunRoutine(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = Gemv(args.layout, args.a_transpose, + args.m, args.n, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, + buffers.x_vec(), args.x_offset, args.x_inc, args.beta, + buffers.y_vec(), args.y_offset, args.y_inc, + &queue_plain, &event); + clWaitForEvents(1, &event); + return status; + } + + // Describes how to run the clBLAS routine (for correctness/performance comparison) + static StatusCode RunReference(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = clblasXgemv(static_cast(args.layout), + static_cast(args.a_transpose), + args.m, args.n, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, + buffers.x_vec(), args.x_offset, args.x_inc, args.beta, + buffers.y_vec(), args.y_offset, args.y_inc, + 1, &queue_plain, 0, nullptr, &event); + clWaitForEvents(1, &event); + return static_cast(status); + } + + // Describes how to download the results of the computation (more importantly: which buffer) + static std::vector DownloadResult(const Arguments &args, Buffers &buffers, + CommandQueue &queue) { + std::vector result(args.y_size, static_cast(0)); + buffers.y_vec.ReadBuffer(queue, args.y_size*sizeof(T), result); + return result; + } + + // Describes how to compute the indices of the result buffer + static size_t ResultID1(const Arguments &args) { + auto a_transposed = (args.a_transpose != Transpose::kNo); + return (a_transposed) ? args.n : args.m; + } + static size_t ResultID2(const Arguments &args) { return 1; } // N/A for this routine + static size_t GetResultIndex(const Arguments &args, const size_t id1, const size_t id2) { + return id1*args.y_inc + args.y_offset; + } +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_ROUTINES_XGEMV_H_ +#endif diff --git a/test/routines/xsymm.h b/test/routines/xsymm.h new file mode 100644 index 00000000..93b4d30c --- /dev/null +++ b/test/routines/xsymm.h @@ -0,0 +1,114 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under the MIT license. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file implements a class with static methods to describe the Xsymm routine. Examples of +// such 'descriptions' are how to calculate the size a of buffer or how to run the routine. These +// static methods are used by the correctness tester and the performance tester. +// +// ================================================================================================= + +#ifndef CLBLAST_TEST_ROUTINES_XSYMM_H_ +#define CLBLAST_TEST_ROUTINES_XSYMM_H_ + +#include +#include + +#include "wrapper_clblas.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template +class TestXsymm { + public: + + // The list of arguments relevant for this routine + static std::vector GetOptions() { + return {kArgM, kArgN, + kArgLayout, kArgSide, kArgTriangle, + kArgALeadDim, kArgBLeadDim, kArgCLeadDim, + kArgAOffset, kArgBOffset, kArgCOffset, + kArgAlpha, kArgBeta}; + } + + // Describes how to obtain the sizes of the buffers + static size_t GetSizeA(const Arguments &args) { + size_t k_value = (args.side == Side::kLeft) ? args.m : args.n; + auto a_rotated = (args.layout == Layout::kRowMajor); + auto a_two = (a_rotated) ? args.m : k_value; + return a_two * args.a_ld + args.a_offset; + } + static size_t GetSizeB(const Arguments &args) { + size_t k_value = (args.side == Side::kLeft) ? args.m : args.n; + auto b_rotated = (args.layout == Layout::kRowMajor); + auto b_two = (b_rotated) ? k_value : args.n; + return b_two * args.b_ld + args.b_offset; + } + static size_t GetSizeC(const Arguments &args) { + auto c_rotated = (args.layout == Layout::kRowMajor); + auto c_two = (c_rotated) ? args.m : args.n; + return c_two * args.c_ld + args.c_offset; + } + + // Describes how to run the CLBlast routine + static StatusCode RunRoutine(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = Symm(args.layout, args.side, args.triangle, + args.m, args.n, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, + buffers.b_mat(), args.b_offset, args.b_ld, args.beta, + buffers.c_mat(), args.c_offset, args.c_ld, + &queue_plain, &event); + clWaitForEvents(1, &event); + return status; + } + + // Describes how to run the clBLAS routine (for correctness/performance comparison) + static StatusCode RunReference(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = clblasXsymm(static_cast(args.layout), + static_cast(args.side), + static_cast(args.triangle), + args.m, args.n, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, + buffers.b_mat(), args.b_offset, args.b_ld, args.beta, + buffers.c_mat(), args.c_offset, args.c_ld, + 1, &queue_plain, 0, nullptr, &event); + clWaitForEvents(1, &event); + return static_cast(status); + } + + // Describes how to download the results of the computation (more importantly: which buffer) + static std::vector DownloadResult(const Arguments &args, Buffers &buffers, + CommandQueue &queue) { + std::vector result(args.c_size, static_cast(0)); + buffers.c_mat.ReadBuffer(queue, args.c_size*sizeof(T), result); + return result; + } + + // Describes how to compute the indices of the result buffer + static size_t ResultID1(const Arguments &args) { return args.m; } + static size_t ResultID2(const Arguments &args) { return args.n; } + static size_t GetResultIndex(const Arguments &args, const size_t id1, const size_t id2) { + return (args.layout == Layout::kRowMajor) ? + id1*args.c_ld + id2 + args.c_offset: + id2*args.c_ld + id1 + args.c_offset; + } +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_ROUTINES_XSYMM_H_ +#endif diff --git a/test/routines/xsyr2k.h b/test/routines/xsyr2k.h new file mode 100644 index 00000000..4f2def74 --- /dev/null +++ b/test/routines/xsyr2k.h @@ -0,0 +1,110 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under the MIT license. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file implements a class with static methods to describe the Xsyr2k routine. Examples of +// such 'descriptions' are how to calculate the size a of buffer or how to run the routine. These +// static methods are used by the correctness tester and the performance tester. +// +// ================================================================================================= + +#ifndef CLBLAST_TEST_ROUTINES_XSYR2K_H_ +#define CLBLAST_TEST_ROUTINES_XSYR2K_H_ + +#include +#include + +#include "wrapper_clblas.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template +class TestXsyr2k { + public: + + // The list of arguments relevant for this routine + static std::vector GetOptions() { + return {kArgN, kArgK, + kArgLayout, kArgTriangle, kArgATransp, + kArgALeadDim, kArgBLeadDim, kArgCLeadDim, + kArgAOffset, kArgBOffset, kArgCOffset, + kArgAlpha, kArgBeta}; + } + + // Describes how to obtain the sizes of the buffers + static size_t GetSizeA(const Arguments &args) { + auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) || + (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo); + auto a_two = (a_rotated) ? args.n : args.k; + return a_two * args.a_ld + args.a_offset; + } + static size_t GetSizeB(const Arguments &args) { + auto b_rotated = (args.layout == Layout::kColMajor && args.b_transpose != Transpose::kNo) || + (args.layout == Layout::kRowMajor && args.b_transpose == Transpose::kNo); + auto b_two = (b_rotated) ? args.k : args.n; + return b_two * args.b_ld + args.b_offset; + } + static size_t GetSizeC(const Arguments &args) { + return args.n * args.c_ld + args.c_offset; + } + + // Describes how to run the CLBlast routine + static StatusCode RunRoutine(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = Syr2k(args.layout, args.triangle, args.a_transpose, + args.n, args.k, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, + buffers.b_mat(), args.b_offset, args.b_ld, args.beta, + buffers.c_mat(), args.c_offset, args.c_ld, + &queue_plain, &event); + clWaitForEvents(1, &event); + return status; + } + + // Describes how to run the clBLAS routine (for correctness/performance comparison) + static StatusCode RunReference(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = clblasXsyr2k(static_cast(args.layout), + static_cast(args.triangle), + static_cast(args.a_transpose), + args.n, args.k, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, + buffers.b_mat(), args.b_offset, args.b_ld, args.beta, + buffers.c_mat(), args.c_offset, args.c_ld, + 1, &queue_plain, 0, nullptr, &event); + clWaitForEvents(1, &event); + return static_cast(status); + } + + // Describes how to download the results of the computation (more importantly: which buffer) + static std::vector DownloadResult(const Arguments &args, Buffers &buffers, + CommandQueue &queue) { + std::vector result(args.c_size, static_cast(0)); + buffers.c_mat.ReadBuffer(queue, args.c_size*sizeof(T), result); + return result; + } + + // Describes how to compute the indices of the result buffer + static size_t ResultID1(const Arguments &args) { return args.n; } + static size_t ResultID2(const Arguments &args) { return args.n; } + static size_t GetResultIndex(const Arguments &args, const size_t id1, const size_t id2) { + return id1*args.c_ld + id2 + args.c_offset; + } +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_ROUTINES_XSYR2K_H_ +#endif diff --git a/test/routines/xsyrk.h b/test/routines/xsyrk.h new file mode 100644 index 00000000..19a77749 --- /dev/null +++ b/test/routines/xsyrk.h @@ -0,0 +1,102 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under the MIT license. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file implements a class with static methods to describe the Xsyrk routine. Examples of +// such 'descriptions' are how to calculate the size a of buffer or how to run the routine. These +// static methods are used by the correctness tester and the performance tester. +// +// ================================================================================================= + +#ifndef CLBLAST_TEST_ROUTINES_XSYRK_H_ +#define CLBLAST_TEST_ROUTINES_XSYRK_H_ + +#include +#include + +#include "wrapper_clblas.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template +class TestXsyrk { + public: + + // The list of arguments relevant for this routine + static std::vector GetOptions() { + return {kArgN, kArgK, + kArgLayout, kArgTriangle, kArgATransp, + kArgALeadDim, kArgCLeadDim, + kArgAOffset, kArgCOffset, + kArgAlpha, kArgBeta}; + } + + // Describes how to obtain the sizes of the buffers + static size_t GetSizeA(const Arguments &args) { + auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) || + (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo); + auto a_two = (a_rotated) ? args.n : args.k; + return a_two * args.a_ld + args.a_offset; + } + static size_t GetSizeC(const Arguments &args) { + return args.n * args.c_ld + args.c_offset; + } + + // Describes how to run the CLBlast routine + static StatusCode RunRoutine(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = Syrk(args.layout, args.triangle, args.a_transpose, + args.n, args.k, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, args.beta, + buffers.c_mat(), args.c_offset, args.c_ld, + &queue_plain, &event); + clWaitForEvents(1, &event); + return status; + } + + // Describes how to run the clBLAS routine (for correctness/performance comparison) + static StatusCode RunReference(const Arguments &args, const Buffers &buffers, + CommandQueue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = clblasXsyrk(static_cast(args.layout), + static_cast(args.triangle), + static_cast(args.a_transpose), + args.n, args.k, args.alpha, + buffers.a_mat(), args.a_offset, args.a_ld, args.beta, + buffers.c_mat(), args.c_offset, args.c_ld, + 1, &queue_plain, 0, nullptr, &event); + clWaitForEvents(1, &event); + return static_cast(status); + } + + // Describes how to download the results of the computation (more importantly: which buffer) + static std::vector DownloadResult(const Arguments &args, Buffers &buffers, + CommandQueue &queue) { + std::vector result(args.c_size, static_cast(0)); + buffers.c_mat.ReadBuffer(queue, args.c_size*sizeof(T), result); + return result; + } + + // Describes how to compute the indices of the result buffer + static size_t ResultID1(const Arguments &args) { return args.n; } + static size_t ResultID2(const Arguments &args) { return args.n; } + static size_t GetResultIndex(const Arguments &args, const size_t id1, const size_t id2) { + return id1*args.c_ld + id2 + args.c_offset; + } +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_ROUTINES_XSYRK_H_ +#endif -- cgit v1.2.3