diff options
author | CNugteren <web@cedricnugteren.nl> | 2015-09-19 11:11:34 +0200 |
---|---|---|
committer | CNugteren <web@cedricnugteren.nl> | 2015-09-19 11:11:34 +0200 |
commit | aebd156869738f88c21a78a8df27e391e67da39b (patch) | |
tree | 77cad97ec255bd94fc3105979ba86ad2643e42d8 | |
parent | 93dddda63e4345961a779ee125d748c1eeef4769 (diff) |
Added the HBMV routine
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | include/internal/routines/level2/xgemv.h | 2 | ||||
-rw-r--r-- | include/internal/routines/level2/xhbmv.h | 49 | ||||
-rw-r--r-- | scripts/generator/generator.py | 4 | ||||
-rw-r--r-- | src/clblast.cc | 30 | ||||
-rw-r--r-- | src/kernels/level2/xgemv.opencl | 77 | ||||
-rw-r--r-- | src/routines/level2/xgbmv.cc | 2 | ||||
-rw-r--r-- | src/routines/level2/xgemv.cc | 10 | ||||
-rw-r--r-- | src/routines/level2/xhbmv.cc | 64 | ||||
-rw-r--r-- | src/routines/level2/xhemv.cc | 6 | ||||
-rw-r--r-- | src/routines/level2/xsymv.cc | 6 | ||||
-rw-r--r-- | test/routines/level2/xhbmv.h | 130 |
14 files changed, 334 insertions, 51 deletions
@@ -10,6 +10,7 @@ Development version (next release) * CDOTC/ZDOTC - Added level-2 routines: * SGBMV/DGBMV/CGBMV/ZGBMV + * CHBMV/ZHBMV Version 0.4.0 - Now using the Claduc C++11 interface to OpenCL diff --git a/CMakeLists.txt b/CMakeLists.txt index 988eb683..bfd75a1f 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 xsymv) +set(LEVEL2_ROUTINES xgemv xgbmv xhemv xhbmv xsymv) 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) @@ -155,7 +155,7 @@ CLBlast is in active development and currently does not support the full set of | xGEMV | ✔ | ✔ | ✔ | ✔ | | | xGBMV | ✔ | ✔ | ✔ | ✔ | | | xHEMV | - | - | ✔ | ✔ | | -| xHBMV | - | - | | | | +| xHBMV | - | - | ✔ | ✔ | | | xHPMV | - | - | | | | | xSYMV | ✔ | ✔ | - | - | | | xSBMV | | | - | - | | diff --git a/include/internal/routines/level2/xgemv.h b/include/internal/routines/level2/xgemv.h index d18f05b4..47da5494 100644 --- a/include/internal/routines/level2/xgemv.h +++ b/include/internal/routines/level2/xgemv.h @@ -55,7 +55,7 @@ class Xgemv: public Routine<T> { 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, - bool fast_kernel, bool fast_kernel_rot, bool reversed, + bool fast_kernel, bool fast_kernel_rot, const size_t parameter, const size_t kl, const size_t ku); private: diff --git a/include/internal/routines/level2/xhbmv.h b/include/internal/routines/level2/xhbmv.h new file mode 100644 index 00000000..65138424 --- /dev/null +++ b/include/internal/routines/level2/xhbmv.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 Xhbmv routine. It is based on the generalized mat-vec multiplication +// routine (Xgemv). The Xhbmv class inherits from the templated class Xgemv, allowing it to call the +// "MatVec" function directly. +// +// ================================================================================================= + +#ifndef CLBLAST_ROUTINES_XHBMV_H_ +#define CLBLAST_ROUTINES_XHBMV_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 Xhbmv: public Xgemv<T> { + public: + + // Uses the generic matrix-vector routine + using Xgemv<T>::MatVec; + + // Constructor + Xhbmv(Queue &queue, Event &event, const std::string &name = "HBMV"); + + // Templated-precision implementation of the routine + StatusCode DoHbmv(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_XHBMV_H_ +#endif diff --git a/scripts/generator/generator.py b/scripts/generator/generator.py index d1171bc0..cecaf960 100644 --- a/scripts/generator/generator.py +++ b/scripts/generator/generator.py @@ -66,7 +66,7 @@ routines = [ Routine(True, "2a", "gemv", T, [S,D,C,Z], ["m","n"], ["layout","a_transpose"], ["a","x"], ["y"], ["alpha","beta"], False, "General matrix-vector multiplication"), Routine(True, "2a", "gbmv", T, [S,D,C,Z], ["m","n","kl","ku"], ["layout","a_transpose"], ["a","x"], ["y"], ["alpha","beta"], False, "General banded matrix-vector multiplication"), Routine(True, "2a", "hemv", T, [C,Z], ["n"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Hermitian matrix-vector multiplication"), - Routine(False, "2a", "hbmv", T, [C,Z], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Hermitian banded matrix-vector multiplication"), + Routine(True, "2a", "hbmv", T, [C,Z], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Hermitian banded matrix-vector multiplication"), Routine(False, "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"), @@ -237,7 +237,7 @@ files = [ path_clblast+"/src/clblast_c.cc", path_clblast+"/test/wrapper_clblas.h", ] -header_lines = [84, 45, 80, 24, 22] +header_lines = [84, 46, 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 ad5e354d..3453312f 100644 --- a/src/clblast.cc +++ b/src/clblast.cc @@ -30,6 +30,7 @@ #include "internal/routines/level2/xgemv.h" #include "internal/routines/level2/xgbmv.h" #include "internal/routines/level2/xhemv.h" +#include "internal/routines/level2/xhbmv.h" #include "internal/routines/level2/xsymv.h" // BLAS level-3 includes @@ -424,15 +425,26 @@ template StatusCode Hemv<double2>(const Layout, const Triangle, // Hermitian banded matrix-vector multiplication: CHBMV/ZHBMV template <typename T> -StatusCode Hbmv(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 Hbmv(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 = Xhbmv<T>(queue_cpp, event_cpp); + auto status = routine.SetUp(); + if (status != StatusCode::kSuccess) { return status; } + return routine.DoHbmv(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 Hbmv<float2>(const Layout, const Triangle, const size_t, const size_t, diff --git a/src/kernels/level2/xgemv.opencl b/src/kernels/level2/xgemv.opencl index 0ecfc960..f0bf4405 100644 --- a/src/kernels/level2/xgemv.opencl +++ b/src/kernels/level2/xgemv.opencl @@ -82,38 +82,65 @@ R"( // Defines how to load the input matrix in the non-vectorized case inline real LoadMatrixA(const __global real* restrict agm, const int x, const int y, - const int a_ld, const int a_offset, const int reversed, + const int a_ld, const int a_offset, const int parameter, const int kl, const int ku) { real result; - // For symmetric matrices - #if defined(ROUTINE_SYMV) - if ((reversed == 0 && y <= x) || (reversed == 1 && x <= y)) { - result = agm[y*a_ld + x + a_offset]; - } - else { - result = agm[x*a_ld + y + a_offset]; - } + // For banded matrices + #if defined(ROUTINE_GBMV) + const int k = ku - y; + 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) - if ((reversed == 0 && y <= x) || (reversed == 1 && x <= y)) { - result = agm[y*a_ld + x + a_offset]; + if ((parameter == 0 && y <= x) || (parameter == 1 && x <= y)) { + result = agm[a_ld*y + x + a_offset]; if (x == y) { result.y = ZERO; } } else { - result = agm[x*a_ld + y + a_offset]; + result = agm[a_ld*x + y + a_offset]; COMPLEX_CONJUGATE(result); } - // For banded matrices - #elif defined(ROUTINE_GBMV) - const int k = ku-y+x; - if (x >= y-ku && x < y+kl+1) { - result = agm[a_ld*y + k + a_offset]; + // For hermitian banded matrices + #elif defined(ROUTINE_HBMV) + 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; } + } + 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); + } + } + else { + if (x >= y) { + 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; } + } + 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); + } + } + + // 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 { - SetToZero(result); + result = agm[x*a_ld + y + a_offset]; } // For general matrices @@ -145,7 +172,7 @@ __kernel void Xgemv(const int m, const int n, const real alpha, const real beta, const __global real* restrict agm, const int a_offset, const int a_ld, const __global real* restrict xgm, const int x_offset, const int x_inc, __global real* ygm, const int y_offset, const int y_inc, - const int do_conjugate, const int reversed, + const int do_conjugate, const int parameter, const int kl, const int ku) { // Local memory for the vector X @@ -183,7 +210,7 @@ __kernel void Xgemv(const int m, const int n, const real alpha, const real beta, #pragma unroll for (int kloop=0; kloop<WGS1; ++kloop) { const int k = kwg + kloop; - real value = LoadMatrixA(agm, gid, k, a_ld, a_offset, reversed, kl, ku); + real value = LoadMatrixA(agm, gid, k, a_ld, a_offset, parameter, kl, ku); if (do_conjugate == 1) { COMPLEX_CONJUGATE(value); } MultiplyAdd(acc[w], xlm[kloop], value); } @@ -192,7 +219,7 @@ __kernel void Xgemv(const int m, const int n, const real alpha, const real beta, #pragma unroll for (int kloop=0; kloop<WGS1; ++kloop) { const int k = kwg + kloop; - real value = LoadMatrixA(agm, k, gid, a_ld, a_offset, reversed, kl, ku); + real value = LoadMatrixA(agm, k, gid, a_ld, a_offset, parameter, kl, ku); if (do_conjugate == 1) { COMPLEX_CONJUGATE(value); } MultiplyAdd(acc[w], xlm[kloop], value); } @@ -214,7 +241,7 @@ __kernel void Xgemv(const int m, const int n, const real alpha, const real beta, if (a_rotated == 0) { // Not rotated #pragma unroll for (int k=n_floor; k<n; ++k) { - real value = LoadMatrixA(agm, gid, k, a_ld, a_offset, reversed, kl, ku); + real value = LoadMatrixA(agm, gid, k, a_ld, a_offset, parameter, kl, ku); if (do_conjugate == 1) { COMPLEX_CONJUGATE(value); } MultiplyAdd(acc[w], xgm[k*x_inc + x_offset], value); } @@ -222,7 +249,7 @@ __kernel void Xgemv(const int m, const int n, const real alpha, const real beta, else { // Transposed #pragma unroll for (int k=n_floor; k<n; ++k) { - real value = LoadMatrixA(agm, k, gid, a_ld, a_offset, reversed, kl, ku); + real value = LoadMatrixA(agm, k, gid, a_ld, a_offset, parameter, kl, ku); if (do_conjugate == 1) { COMPLEX_CONJUGATE(value); } MultiplyAdd(acc[w], xgm[k*x_inc + x_offset], value); } @@ -249,7 +276,7 @@ __kernel void XgemvFast(const int m, const int n, const real alpha, const real b const __global realVF* restrict agm, const int a_offset, const int a_ld, const __global real* restrict xgm, const int x_offset, const int x_inc, __global real* ygm, const int y_offset, const int y_inc, - const int do_conjugate, const int reversed, + const int do_conjugate, const int parameter, const int kl, const int ku) { // Local memory for the vector X __local real xlm[WGS2]; @@ -346,7 +373,7 @@ __kernel void XgemvFastRot(const int m, const int n, const real alpha, const rea const __global realVFR* restrict agm, const int a_offset, const int a_ld, const __global real* restrict xgm, const int x_offset, const int x_inc, __global real* ygm, const int y_offset, const int y_inc, - const int do_conjugate, const int reversed, + const int do_conjugate, const int parameter, const int kl, const int ku) { // Local memory for the vector X __local real xlm[WGS3]; diff --git a/src/routines/level2/xgbmv.cc b/src/routines/level2/xgbmv.cc index 8657c254..d8815542 100644 --- a/src/routines/level2/xgbmv.cc +++ b/src/routines/level2/xgbmv.cc @@ -52,7 +52,7 @@ StatusCode Xgbmv<T>::DoGbmv(const Layout layout, const Transpose a_transpose, x_buffer, x_offset, x_inc, beta, y_buffer, y_offset, y_inc, fast_kernels, fast_kernels, - false, kl_real, ku_real); + 0, kl_real, ku_real); } // ================================================================================================= diff --git a/src/routines/level2/xgemv.cc b/src/routines/level2/xgemv.cc index 6e2303c0..0c312756 100644 --- a/src/routines/level2/xgemv.cc +++ b/src/routines/level2/xgemv.cc @@ -55,7 +55,7 @@ StatusCode Xgemv<T>::DoGemv(const Layout layout, const Transpose a_transpose, x_buffer, x_offset, x_inc, beta, y_buffer, y_offset, y_inc, true, true, - false, 0, 0); // N/A for this routine + 0, 0, 0); // N/A for this routine } // ================================================================================================= @@ -69,7 +69,7 @@ StatusCode Xgemv<T>::MatVec(const Layout layout, const Transpose a_transpose, 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, - bool fast_kernel, bool fast_kernel_rot, bool reversed, + bool fast_kernel, bool fast_kernel_rot, const size_t parameter, const size_t kl, const size_t ku) { // Makes sure all dimensions are larger than zero @@ -151,9 +151,9 @@ StatusCode Xgemv<T>::MatVec(const Layout layout, const Transpose a_transpose, kernel.SetArgument(12, static_cast<int>(y_offset)); kernel.SetArgument(13, static_cast<int>(y_inc)); kernel.SetArgument(14, static_cast<int>(a_conjugate)); - kernel.SetArgument(15, static_cast<int>(reversed)); // only used for SYMV/HEMV routines - kernel.SetArgument(16, static_cast<int>(kl)); // only used for GBMV routines - kernel.SetArgument(17, static_cast<int>(ku)); // only used for GBMV routines + kernel.SetArgument(15, static_cast<int>(parameter)); // extra parameter used for symm/herm + kernel.SetArgument(16, static_cast<int>(kl)); // only used for banded matrices + kernel.SetArgument(17, static_cast<int>(ku)); // only used for banded matrices // Launches the kernel auto global = std::vector<size_t>{global_size}; diff --git a/src/routines/level2/xhbmv.cc b/src/routines/level2/xhbmv.cc new file mode 100644 index 00000000..90c0c787 --- /dev/null +++ b/src/routines/level2/xhbmv.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 Xhbmv class (see the header for information about the class). +// +// ================================================================================================= + +#include "internal/routines/level2/xhbmv.h" + +#include <string> +#include <vector> + +namespace clblast { +// ================================================================================================= + +// Constructor: forwards to base class constructor +template <typename T> +Xhbmv<T>::Xhbmv(Queue &queue, Event &event, const std::string &name): + Xgemv<T>(queue, event, name) { +} + +// ================================================================================================= + +// The main routine +template <typename T> +StatusCode Xhbmv<T>::DoHbmv(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 hermitian banded matrix-accesses are implemented in the kernel guarded by the + // ROUTINE_HBMV 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, k, 0); +} + +// ================================================================================================= + +// Compiles the templated class +template class Xhbmv<float2>; +template class Xhbmv<double2>; + +// ================================================================================================= +} // namespace clblast diff --git a/src/routines/level2/xhemv.cc b/src/routines/level2/xhemv.cc index 917bf9b6..efad829b 100644 --- a/src/routines/level2/xhemv.cc +++ b/src/routines/level2/xhemv.cc @@ -38,8 +38,8 @@ StatusCode Xhemv<T>::DoHemv(const Layout layout, const Triangle triangle, 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 - bool reversed = ((triangle == Triangle::kUpper && layout != Layout::kRowMajor) || - (triangle == Triangle::kLower && layout == Layout::kRowMajor)); + 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 hermitian matrix-accesses are implemented in the kernel guarded by the @@ -51,7 +51,7 @@ StatusCode Xhemv<T>::DoHemv(const Layout layout, const Triangle triangle, x_buffer, x_offset, x_inc, beta, y_buffer, y_offset, y_inc, fast_kernels, fast_kernels, - reversed, 0, 0); + is_upper, 0, 0); } // ================================================================================================= diff --git a/src/routines/level2/xsymv.cc b/src/routines/level2/xsymv.cc index 15c91f47..458d7385 100644 --- a/src/routines/level2/xsymv.cc +++ b/src/routines/level2/xsymv.cc @@ -38,8 +38,8 @@ StatusCode Xsymv<T>::DoSymv(const Layout layout, const Triangle triangle, 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 - bool reversed = ((triangle == Triangle::kUpper && layout != Layout::kRowMajor) || - (triangle == Triangle::kLower && layout == Layout::kRowMajor)); + 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 matrix-accesses are implemented in the kernel guarded by the @@ -51,7 +51,7 @@ StatusCode Xsymv<T>::DoSymv(const Layout layout, const Triangle triangle, x_buffer, x_offset, x_inc, beta, y_buffer, y_offset, y_inc, fast_kernels, fast_kernels, - reversed, 0, 0); + is_upper, 0, 0); } // ================================================================================================= diff --git a/test/routines/level2/xhbmv.h b/test/routines/level2/xhbmv.h new file mode 100644 index 00000000..34e1502f --- /dev/null +++ b/test/routines/level2/xhbmv.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 Xhbmv 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_XHBMV_H_ +#define CLBLAST_TEST_ROUTINES_XHBMV_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 TestXhbmv { + 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 = Hbmv(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 = clblasXhbmv(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_XHBMV_H_ +#endif |