diff options
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | include/internal/routines/level2/xsbmv.h | 49 | ||||
-rw-r--r-- | include/internal/routines/level2/xspmv.h | 49 | ||||
-rw-r--r-- | scripts/generator/generator.py | 6 | ||||
-rw-r--r-- | src/clblast.cc | 60 | ||||
-rw-r--r-- | src/kernels/level2/xgemv.opencl | 61 | ||||
-rw-r--r-- | src/routines/level2/xsbmv.cc | 64 | ||||
-rw-r--r-- | src/routines/level2/xspmv.cc | 64 | ||||
-rw-r--r-- | test/routines/level2/xhpmv.h | 6 | ||||
-rw-r--r-- | test/routines/level2/xsbmv.h | 130 | ||||
-rw-r--r-- | test/routines/level2/xspmv.h | 130 |
13 files changed, 575 insertions, 52 deletions
@@ -12,6 +12,8 @@ Development version (next release) * SGBMV/DGBMV/CGBMV/ZGBMV * CHBMV/ZHBMV * CHPMV/ZHPMV + * SSBMV/DSBMV + * SSPMV/DSPMV Version 0.4.0 - Now using the Claduc C++11 interface to OpenCL diff --git a/CMakeLists.txt b/CMakeLists.txt index ba173fdc..7e670664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,7 +106,7 @@ set(KERNELS copy pad transpose padtranspose xaxpy xdot xgemv xgemm) set(SAMPLE_PROGRAMS_CPP sgemm) set(SAMPLE_PROGRAMS_C sgemm) set(LEVEL1_ROUTINES xswap xscal xcopy xaxpy xdot xdotu xdotc) -set(LEVEL2_ROUTINES xgemv xgbmv xhemv xhbmv xhpmv xsymv) +set(LEVEL2_ROUTINES xgemv xgbmv xhemv xhbmv xhpmv xsymv xsbmv xspmv) set(LEVEL3_ROUTINES xgemm xsymm xhemm xsyrk xherk xsyr2k xher2k xtrmm) set(ROUTINES ${LEVEL1_ROUTINES} ${LEVEL2_ROUTINES} ${LEVEL3_ROUTINES}) set(PRECISIONS 32 3232 64 6464) @@ -158,8 +158,8 @@ CLBlast is in active development and currently does not support the full set of | xHBMV | - | - | ✔ | ✔ | | | xHPMV | - | - | ✔ | ✔ | | | xSYMV | ✔ | ✔ | - | - | | -| xSBMV | | | - | - | | -| xSPMV | | | - | - | | +| xSBMV | ✔ | ✔ | - | - | | +| xSPMV | ✔ | ✔ | - | - | | | xTRMV | | | | | | | xTBMV | | | | | | | xTPMV | | | | | | diff --git a/include/internal/routines/level2/xsbmv.h b/include/internal/routines/level2/xsbmv.h new file mode 100644 index 00000000..bb24d8f4 --- /dev/null +++ b/include/internal/routines/level2/xsbmv.h @@ -0,0 +1,49 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. 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 <www.cedricnugteren.nl> +// +// This file implements the Xsbmv routine. It is based on the generalized mat-vec multiplication +// routine (Xgemv). The Xsbmv class inherits from the templated class Xgemv, allowing it to call the +// "MatVec" function directly. +// +// ================================================================================================= + +#ifndef CLBLAST_ROUTINES_XSBMV_H_ +#define CLBLAST_ROUTINES_XSBMV_H_ + +#include "internal/routines/level2/xgemv.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template <typename T> +class Xsbmv: public Xgemv<T> { + public: + + // Uses the generic matrix-vector routine + using Xgemv<T>::MatVec; + + // Constructor + Xsbmv(Queue &queue, Event &event, const std::string &name = "SBMV"); + + // Templated-precision implementation of the routine + StatusCode DoSbmv(const Layout layout, const Triangle triangle, + const size_t n, const size_t k, + const T alpha, + const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld, + const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc, + const T beta, + const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc); +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_ROUTINES_XSBMV_H_ +#endif diff --git a/include/internal/routines/level2/xspmv.h b/include/internal/routines/level2/xspmv.h new file mode 100644 index 00000000..88f02a2f --- /dev/null +++ b/include/internal/routines/level2/xspmv.h @@ -0,0 +1,49 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. 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 <www.cedricnugteren.nl> +// +// This file implements the Xspmv routine. It is based on the generalized mat-vec multiplication +// routine (Xgemv). The Xspmv class inherits from the templated class Xgemv, allowing it to call the +// "MatVec" function directly. +// +// ================================================================================================= + +#ifndef CLBLAST_ROUTINES_XSPMV_H_ +#define CLBLAST_ROUTINES_XSPMV_H_ + +#include "internal/routines/level2/xgemv.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template <typename T> +class Xspmv: public Xgemv<T> { + public: + + // Uses the generic matrix-vector routine + using Xgemv<T>::MatVec; + + // Constructor + Xspmv(Queue &queue, Event &event, const std::string &name = "SPMV"); + + // Templated-precision implementation of the routine + StatusCode DoSpmv(const Layout layout, const Triangle triangle, + const size_t n, + const T alpha, + const Buffer<T> &ap_buffer, const size_t ap_offset, + const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc, + const T beta, + const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc); +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_ROUTINES_XSPMV_H_ +#endif diff --git a/scripts/generator/generator.py b/scripts/generator/generator.py index 5d01f26b..338c8468 100644 --- a/scripts/generator/generator.py +++ b/scripts/generator/generator.py @@ -69,8 +69,8 @@ routines = [ Routine(True, "2a", "hbmv", T, [C,Z], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Hermitian banded matrix-vector multiplication"), Routine(True, "2a", "hpmv", T, [C,Z], ["n"], ["layout","triangle"], ["ap","x"], ["y"], ["alpha","beta"], False, "Hermitian packed matrix-vector multiplication"), Routine(True, "2a", "symv", T, [S,D], ["n"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Symmetric matrix-vector multiplication"), - Routine(False, "2a", "sbmv", T, [S,D], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Symmetric banded matrix-vector multiplication"), - Routine(False, "2a", "spmv", T, [S,D], ["n"], ["layout","triangle"], ["ap","x"], ["y"], ["alpha","beta"], False, "Symmetric packed matrix-vector multiplication"), + Routine(True, "2a", "sbmv", T, [S,D], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Symmetric banded matrix-vector multiplication"), + Routine(True, "2a", "spmv", T, [S,D], ["n"], ["layout","triangle"], ["ap","x"], ["y"], ["alpha","beta"], False, "Symmetric packed matrix-vector multiplication"), Routine(False, "2a", "trmv", T, [S,D,C,Z], ["n"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], True, "Triangular matrix-vector multiplication"), Routine(False, "2a", "tbmv", T, [S,D,C,Z], ["n","k"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], True, "Triangular banded matrix-vector multiplication"), Routine(False, "2a", "tpmv", T, [S,D,C,Z], ["n"], ["layout","triangle","a_transpose","diagonal"], ["ap"], ["x"], [], True, "Triangular packed matrix-vector multiplication"), @@ -237,7 +237,7 @@ files = [ path_clblast+"/src/clblast_c.cc", path_clblast+"/test/wrapper_clblas.h", ] -header_lines = [84, 47, 80, 24, 22] +header_lines = [84, 49, 80, 24, 22] footer_lines = [6, 3, 5, 2, 6] # Checks whether the command-line arguments are valid; exists otherwise diff --git a/src/clblast.cc b/src/clblast.cc index 85c63442..f7baf5e8 100644 --- a/src/clblast.cc +++ b/src/clblast.cc @@ -33,6 +33,8 @@ #include "internal/routines/level2/xhbmv.h" #include "internal/routines/level2/xhpmv.h" #include "internal/routines/level2/xsymv.h" +#include "internal/routines/level2/xsbmv.h" +#include "internal/routines/level2/xspmv.h" // BLAS level-3 includes #include "internal/routines/level3/xgemm.h" @@ -546,15 +548,26 @@ template StatusCode Symv<double>(const Layout, const Triangle, // Symmetric banded matrix-vector multiplication: SSBMV/DSBMV template <typename T> -StatusCode Sbmv(const Layout, const Triangle, - const size_t, const size_t, - const T, - const cl_mem, const size_t, const size_t, - const cl_mem, const size_t, const size_t, - const T, - cl_mem, const size_t, const size_t, - cl_command_queue*, cl_event*) { - return StatusCode::kNotImplemented; +StatusCode Sbmv(const Layout layout, const Triangle triangle, + const size_t n, const size_t k, + const T alpha, + const cl_mem a_buffer, const size_t a_offset, const size_t a_ld, + const cl_mem x_buffer, const size_t x_offset, const size_t x_inc, + const T beta, + cl_mem y_buffer, const size_t y_offset, const size_t y_inc, + cl_command_queue* queue, cl_event* event) { + auto queue_cpp = Queue(*queue); + auto event_cpp = Event(*event); + auto routine = Xsbmv<T>(queue_cpp, event_cpp); + auto status = routine.SetUp(); + if (status != StatusCode::kSuccess) { return status; } + return routine.DoSbmv(layout, triangle, + n, k, + alpha, + Buffer<T>(a_buffer), a_offset, a_ld, + Buffer<T>(x_buffer), x_offset, x_inc, + beta, + Buffer<T>(y_buffer), y_offset, y_inc); } template StatusCode Sbmv<float>(const Layout, const Triangle, const size_t, const size_t, @@ -575,15 +588,26 @@ template StatusCode Sbmv<double>(const Layout, const Triangle, // Symmetric packed matrix-vector multiplication: SSPMV/DSPMV template <typename T> -StatusCode Spmv(const Layout, const Triangle, - const size_t, - const T, - const cl_mem, const size_t, - const cl_mem, const size_t, const size_t, - const T, - cl_mem, const size_t, const size_t, - cl_command_queue*, cl_event*) { - return StatusCode::kNotImplemented; +StatusCode Spmv(const Layout layout, const Triangle triangle, + const size_t n, + const T alpha, + const cl_mem ap_buffer, const size_t ap_offset, + const cl_mem x_buffer, const size_t x_offset, const size_t x_inc, + const T beta, + cl_mem y_buffer, const size_t y_offset, const size_t y_inc, + cl_command_queue* queue, cl_event* event) { + auto queue_cpp = Queue(*queue); + auto event_cpp = Event(*event); + auto routine = Xspmv<T>(queue_cpp, event_cpp); + auto status = routine.SetUp(); + if (status != StatusCode::kSuccess) { return status; } + return routine.DoSpmv(layout, triangle, + n, + alpha, + Buffer<T>(ap_buffer), ap_offset, + Buffer<T>(x_buffer), x_offset, x_inc, + beta, + Buffer<T>(y_buffer), y_offset, y_inc); } template StatusCode Spmv<float>(const Layout, const Triangle, const size_t, diff --git a/src/kernels/level2/xgemv.opencl b/src/kernels/level2/xgemv.opencl index f6c4476e..ab7802e5 100644 --- a/src/kernels/level2/xgemv.opencl +++ b/src/kernels/level2/xgemv.opencl @@ -92,31 +92,39 @@ inline real LoadMatrixA(const __global real* restrict agm, const int x, const in if (x >= y-ku && x < y+kl+1) { result = agm[a_ld*y + k + x + a_offset]; } else { SetToZero(result); } - // For hermitian matrices - #elif defined(ROUTINE_HEMV) + // For symmetric/hermitian matrices + #elif defined(ROUTINE_HEMV) || defined(ROUTINE_SYMV) if ((parameter == 0 && y <= x) || (parameter == 1 && x <= y)) { result = agm[a_ld*y + x + a_offset]; - if (x == y) { result.y = ZERO; } + #if defined(ROUTINE_HEMV) + if (x == y) { result.y = ZERO; } + #endif } else { result = agm[a_ld*x + y + a_offset]; - COMPLEX_CONJUGATE(result); + #if defined(ROUTINE_HEMV) + COMPLEX_CONJUGATE(result); + #endif } - // For hermitian banded matrices - #elif defined(ROUTINE_HBMV) + // For symmetric/hermitian banded matrices + #elif defined(ROUTINE_HBMV) || defined(ROUTINE_SBMV) if (parameter == 1) { if (x <= y) { const int m = kl - y; if (x >= y-kl && x <= y) { result = agm[a_ld*y + m + x + a_offset]; } else { SetToZero(result); } - if (x == y) { result.y = ZERO; } + #if defined(ROUTINE_HBMV) + if (x == y) { result.y = ZERO; } + #endif } else { const int m = kl - x; if (y >= x-kl && y <= x) { result = agm[a_ld*x + m + y + a_offset]; } else { SetToZero(result); } - COMPLEX_CONJUGATE(result); + #if defined(ROUTINE_HBMV) + COMPLEX_CONJUGATE(result); + #endif } } else { @@ -124,48 +132,51 @@ inline real LoadMatrixA(const __global real* restrict agm, const int x, const in const int m = -y; if (x >= y && x < y+kl+1) { result = agm[a_ld*y + m + x + a_offset]; } else { SetToZero(result); } - if (x == y) { result.y = ZERO; } + #if defined(ROUTINE_HBMV) + if (x == y) { result.y = ZERO; } + #endif } else { const int m = -x; if (y >= x && y < x+kl+1) { result = agm[a_ld*x + m + y + a_offset]; } else { SetToZero(result); } - COMPLEX_CONJUGATE(result); + #if defined(ROUTINE_HBMV) + COMPLEX_CONJUGATE(result); + #endif } } - // For hermitian packed matrices - #elif defined(ROUTINE_HPMV) + // For symmetric/hermitian packed matrices + #elif defined(ROUTINE_HPMV) || defined(ROUTINE_SPMV) if (parameter == 1) { if (x <= y) { result = agm[((y+1)*y)/2 + x + a_offset]; - if (x == y) { result.y = ZERO; } + #if defined(ROUTINE_HPMV) + if (x == y) { result.y = ZERO; } + #endif } else { result = agm[((x+1)*x)/2 + y + a_offset]; - COMPLEX_CONJUGATE(result); + #if defined(ROUTINE_HPMV) + COMPLEX_CONJUGATE(result); + #endif } } else { if (x >= y) { result = agm[((2*a_ld-(y+1))*y)/2 + x + a_offset]; - if (x == y) { result.y = ZERO; } + #if defined(ROUTINE_HPMV) + if (x == y) { result.y = ZERO; } + #endif } else { result = agm[((2*a_ld-(x+1))*x)/2 + y + a_offset]; - COMPLEX_CONJUGATE(result); + #if defined(ROUTINE_HPMV) + COMPLEX_CONJUGATE(result); + #endif } } - // For symmetric matrices - #elif defined(ROUTINE_SYMV) - if ((parameter == 0 && y <= x) || (parameter == 1 && x <= y)) { - result = agm[y*a_ld + x + a_offset]; - } - else { - result = agm[x*a_ld + y + a_offset]; - } - // For general matrices #else result = agm[a_ld*y + x + a_offset]; diff --git a/src/routines/level2/xsbmv.cc b/src/routines/level2/xsbmv.cc new file mode 100644 index 00000000..457bd762 --- /dev/null +++ b/src/routines/level2/xsbmv.cc @@ -0,0 +1,64 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. 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 <www.cedricnugteren.nl> +// +// This file implements the Xsbmv class (see the header for information about the class). +// +// ================================================================================================= + +#include "internal/routines/level2/xsbmv.h" + +#include <string> +#include <vector> + +namespace clblast { +// ================================================================================================= + +// Constructor: forwards to base class constructor +template <typename T> +Xsbmv<T>::Xsbmv(Queue &queue, Event &event, const std::string &name): + Xgemv<T>(queue, event, name) { +} + +// ================================================================================================= + +// The main routine +template <typename T> +StatusCode Xsbmv<T>::DoSbmv(const Layout layout, const Triangle triangle, + const size_t n, const size_t k, + const T alpha, + const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld, + const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc, + const T beta, + const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc) { + + // The data is either in the upper or lower triangle + size_t is_upper = ((triangle == Triangle::kUpper && layout != Layout::kRowMajor) || + (triangle == Triangle::kLower && layout == Layout::kRowMajor)); + + // Runs the generic matrix-vector multiplication, disabling the use of fast vectorized kernels. + // The specific symmetric banded matrix-accesses are implemented in the kernel guarded by the + // ROUTINE_SBMV define. + bool fast_kernels = false; + return MatVec(layout, Transpose::kNo, + n, n, alpha, + a_buffer, a_offset, a_ld, + x_buffer, x_offset, x_inc, beta, + y_buffer, y_offset, y_inc, + fast_kernels, fast_kernels, + is_upper, false, k, 0); +} + +// ================================================================================================= + +// Compiles the templated class +template class Xsbmv<float>; +template class Xsbmv<double>; + +// ================================================================================================= +} // namespace clblast diff --git a/src/routines/level2/xspmv.cc b/src/routines/level2/xspmv.cc new file mode 100644 index 00000000..4f1a9c61 --- /dev/null +++ b/src/routines/level2/xspmv.cc @@ -0,0 +1,64 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. 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 <www.cedricnugteren.nl> +// +// This file implements the Xspmv class (see the header for information about the class). +// +// ================================================================================================= + +#include "internal/routines/level2/xspmv.h" + +#include <string> +#include <vector> + +namespace clblast { +// ================================================================================================= + +// Constructor: forwards to base class constructor +template <typename T> +Xspmv<T>::Xspmv(Queue &queue, Event &event, const std::string &name): + Xgemv<T>(queue, event, name) { +} + +// ================================================================================================= + +// The main routine +template <typename T> +StatusCode Xspmv<T>::DoSpmv(const Layout layout, const Triangle triangle, + const size_t n, + const T alpha, + const Buffer<T> &ap_buffer, const size_t ap_offset, + const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc, + const T beta, + const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc) { + + // The data is either in the upper or lower triangle + size_t is_upper = ((triangle == Triangle::kUpper && layout != Layout::kRowMajor) || + (triangle == Triangle::kLower && layout == Layout::kRowMajor)); + + // Runs the generic matrix-vector multiplication, disabling the use of fast vectorized kernels. + // The specific symmetric packed matrix-accesses are implemented in the kernel guarded by the + // ROUTINE_SPMV define. + bool fast_kernels = false; + return MatVec(layout, Transpose::kNo, + n, n, alpha, + ap_buffer, ap_offset, n, + x_buffer, x_offset, x_inc, beta, + y_buffer, y_offset, y_inc, + fast_kernels, fast_kernels, + is_upper, true, 0, 0); +} + +// ================================================================================================= + +// Compiles the templated class +template class Xspmv<float>; +template class Xspmv<double>; + +// ================================================================================================= +} // namespace clblast diff --git a/test/routines/level2/xhpmv.h b/test/routines/level2/xhpmv.h index efee7882..8fd85b62 100644 --- a/test/routines/level2/xhpmv.h +++ b/test/routines/level2/xhpmv.h @@ -13,8 +13,8 @@ // // ================================================================================================= -#ifndef CLBLAST_TEST_ROUTINES_XHEMV_H_ -#define CLBLAST_TEST_ROUTINES_XHEMV_H_ +#ifndef CLBLAST_TEST_ROUTINES_XHPMV_H_ +#define CLBLAST_TEST_ROUTINES_XHPMV_H_ #include <vector> #include <string> @@ -126,5 +126,5 @@ class TestXhpmv { // ================================================================================================= } // namespace clblast -// CLBLAST_TEST_ROUTINES_XHEMV_H_ +// CLBLAST_TEST_ROUTINES_XHPMV_H_ #endif diff --git a/test/routines/level2/xsbmv.h b/test/routines/level2/xsbmv.h new file mode 100644 index 00000000..5bc17e49 --- /dev/null +++ b/test/routines/level2/xsbmv.h @@ -0,0 +1,130 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. 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 <www.cedricnugteren.nl> +// +// This file implements a class with static methods to describe the Xsbmv 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_XSBMV_H_ +#define CLBLAST_TEST_ROUTINES_XSBMV_H_ + +#include <vector> +#include <string> + +#include "wrapper_clblas.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template <typename T> +class TestXsbmv { + public: + + // The BLAS level: 1, 2, or 3 + static size_t BLASLevel() { return 2; } + + // The list of arguments relevant for this routine + static std::vector<std::string> GetOptions() { + return {kArgN, kArgKL, + kArgLayout, kArgTriangle, + kArgALeadDim, kArgXInc, kArgYInc, + kArgAOffset, kArgXOffset, kArgYOffset, + kArgAlpha, kArgBeta}; + } + + // Describes how to obtain the sizes of the buffers + static size_t GetSizeX(const Arguments<T> &args) { + return args.n * args.x_inc + args.x_offset; + } + static size_t GetSizeY(const Arguments<T> &args) { + return args.n * args.y_inc + args.y_offset; + } + static size_t GetSizeA(const Arguments<T> &args) { + return args.n * args.a_ld + args.a_offset; + } + + // Describes how to set the sizes of all the buffers + static void SetSizes(Arguments<T> &args) { + args.a_size = GetSizeA(args); + args.x_size = GetSizeX(args); + args.y_size = GetSizeY(args); + } + + // Describes what the default values of the leading dimensions of the matrices are + static size_t DefaultLDA(const Arguments<T> &args) { return args.n; } + static size_t DefaultLDB(const Arguments<T> &) { return 1; } // N/A for this routine + static size_t DefaultLDC(const Arguments<T> &) { return 1; } // N/A for this routine + + // Describes which transpose options are relevant for this routine + using Transposes = std::vector<Transpose>; + static Transposes GetATransposes(const Transposes &) { return {}; } // N/A for this routine + static Transposes GetBTransposes(const Transposes &) { return {}; } // N/A for this routine + + // Describes how to run the CLBlast routine + static StatusCode RunRoutine(const Arguments<T> &args, const Buffers<T> &buffers, Queue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = Sbmv(args.layout, args.triangle, + args.n, args.kl, 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<T> &args, const Buffers<T> &buffers, Queue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = clblasXsbmv(static_cast<clblasOrder>(args.layout), + static_cast<clblasUplo>(args.triangle), + args.n, args.kl, 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<StatusCode>(status); + } + + // Describes how to download the results of the computation (more importantly: which buffer) + static std::vector<T> DownloadResult(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { + std::vector<T> result(args.y_size, static_cast<T>(0)); + buffers.y_vec.Read(queue, args.y_size, result); + return result; + } + + // Describes how to compute the indices of the result buffer + static size_t ResultID1(const Arguments<T> &args) { + return args.n; + } + static size_t ResultID2(const Arguments<T> &) { return 1; } // N/A for this routine + static size_t GetResultIndex(const Arguments<T> &args, const size_t id1, const size_t) { + return id1*args.y_inc + args.y_offset; + } + + // Describes how to compute performance metrics + static size_t GetFlops(const Arguments<T> &args) { + return 2 * args.n * args.n; + } + static size_t GetBytes(const Arguments<T> &args) { + return ((args.kl+args.kl+1)*args.n + 2*args.n + args.n) * sizeof(T); + } +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_ROUTINES_XSBMV_H_ +#endif diff --git a/test/routines/level2/xspmv.h b/test/routines/level2/xspmv.h new file mode 100644 index 00000000..e335da42 --- /dev/null +++ b/test/routines/level2/xspmv.h @@ -0,0 +1,130 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. 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 <www.cedricnugteren.nl> +// +// This file implements a class with static methods to describe the Xspmv 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_XSPMV_H_ +#define CLBLAST_TEST_ROUTINES_XSPMV_H_ + +#include <vector> +#include <string> + +#include "wrapper_clblas.h" + +namespace clblast { +// ================================================================================================= + +// See comment at top of file for a description of the class +template <typename T> +class TestXspmv { + public: + + // The BLAS level: 1, 2, or 3 + static size_t BLASLevel() { return 2; } + + // The list of arguments relevant for this routine + static std::vector<std::string> GetOptions() { + return {kArgN, + kArgLayout, kArgTriangle, + kArgXInc, kArgYInc, + kArgAPOffset, kArgXOffset, kArgYOffset, + kArgAlpha, kArgBeta}; + } + + // Describes how to obtain the sizes of the buffers + static size_t GetSizeX(const Arguments<T> &args) { + return args.n * args.x_inc + args.x_offset; + } + static size_t GetSizeY(const Arguments<T> &args) { + return args.n * args.y_inc + args.y_offset; + } + static size_t GetSizeAP(const Arguments<T> &args) { + return ((args.n*(args.n+1)) / 2) + args.ap_offset; + } + + // Describes how to set the sizes of all the buffers + static void SetSizes(Arguments<T> &args) { + args.ap_size = GetSizeAP(args); + args.x_size = GetSizeX(args); + args.y_size = GetSizeY(args); + } + + // Describes what the default values of the leading dimensions of the matrices are + static size_t DefaultLDA(const Arguments<T> &) { return 1; } // N/A for this routine + static size_t DefaultLDB(const Arguments<T> &) { return 1; } // N/A for this routine + static size_t DefaultLDC(const Arguments<T> &) { return 1; } // N/A for this routine + + // Describes which transpose options are relevant for this routine + using Transposes = std::vector<Transpose>; + static Transposes GetATransposes(const Transposes &) { return {}; } // N/A for this routine + static Transposes GetBTransposes(const Transposes &) { return {}; } // N/A for this routine + + // Describes how to run the CLBlast routine + static StatusCode RunRoutine(const Arguments<T> &args, const Buffers<T> &buffers, Queue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = Spmv(args.layout, args.triangle, + args.n, args.alpha, + buffers.ap_mat(), args.ap_offset, + 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<T> &args, const Buffers<T> &buffers, Queue &queue) { + auto queue_plain = queue(); + auto event = cl_event{}; + auto status = clblasXspmv(static_cast<clblasOrder>(args.layout), + static_cast<clblasUplo>(args.triangle), + args.n, args.alpha, + buffers.ap_mat(), args.ap_offset, + 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<StatusCode>(status); + } + + // Describes how to download the results of the computation (more importantly: which buffer) + static std::vector<T> DownloadResult(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) { + std::vector<T> result(args.y_size, static_cast<T>(0)); + buffers.y_vec.Read(queue, args.y_size, result); + return result; + } + + // Describes how to compute the indices of the result buffer + static size_t ResultID1(const Arguments<T> &args) { + return args.n; + } + static size_t ResultID2(const Arguments<T> &) { return 1; } // N/A for this routine + static size_t GetResultIndex(const Arguments<T> &args, const size_t id1, const size_t) { + return id1*args.y_inc + args.y_offset; + } + + // Describes how to compute performance metrics + static size_t GetFlops(const Arguments<T> &args) { + return 2 * args.n * args.n; + } + static size_t GetBytes(const Arguments<T> &args) { + return (((args.n*(args.n+1)) / 2) + 2*args.n + args.n) * sizeof(T); + } +}; + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TEST_ROUTINES_XSPMV_H_ +#endif |