summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCNugteren <web@cedricnugteren.nl>2015-09-19 17:40:38 +0200
committerCNugteren <web@cedricnugteren.nl>2015-09-19 17:40:38 +0200
commit80da67d28bbcff958071befb48ccacac05ebbe49 (patch)
tree04d25eaeefb6302871dd1fd32db866bcad33977b
parentc32c4a973928536850aab594239000ce6ddc2c5a (diff)
Added the HPMV routine
-rw-r--r--CHANGELOG1
-rw-r--r--CMakeLists.txt2
-rw-r--r--README.md2
-rw-r--r--include/internal/routines/level2/xgemv.h4
-rw-r--r--include/internal/routines/level2/xhpmv.h49
-rw-r--r--scripts/generator/generator.py4
-rw-r--r--src/clblast.cc30
-rw-r--r--src/kernels/level2/xgemv.opencl23
-rw-r--r--src/routines/level2/xgbmv.cc2
-rw-r--r--src/routines/level2/xgemv.cc9
-rw-r--r--src/routines/level2/xhbmv.cc2
-rw-r--r--src/routines/level2/xhemv.cc2
-rw-r--r--src/routines/level2/xhpmv.cc64
-rw-r--r--src/routines/level2/xsymv.cc2
-rw-r--r--test/routines/level2/xhpmv.h130
15 files changed, 305 insertions, 21 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c1207023..70a49360 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -11,6 +11,7 @@ Development version (next release)
- Added level-2 routines:
* SGBMV/DGBMV/CGBMV/ZGBMV
* CHBMV/ZHBMV
+ * CHPMV/ZHPMV
Version 0.4.0
- Now using the Claduc C++11 interface to OpenCL
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bfd75a1f..ba173fdc 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 xsymv)
+set(LEVEL2_ROUTINES xgemv xgbmv xhemv xhbmv xhpmv 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)
diff --git a/README.md b/README.md
index 92d344c2..000a2501 100644
--- a/README.md
+++ b/README.md
@@ -156,7 +156,7 @@ CLBlast is in active development and currently does not support the full set of
| xGBMV | ✔ | ✔ | ✔ | ✔ | |
| xHEMV | - | - | ✔ | ✔ | |
| xHBMV | - | - | ✔ | ✔ | |
-| xHPMV | - | - | | | |
+| xHPMV | - | - | ✔ | ✔ | |
| xSYMV | ✔ | ✔ | - | - | |
| xSBMV | | | - | - | |
| xSPMV | | | - | - | |
diff --git a/include/internal/routines/level2/xgemv.h b/include/internal/routines/level2/xgemv.h
index 47da5494..b31565ec 100644
--- a/include/internal/routines/level2/xgemv.h
+++ b/include/internal/routines/level2/xgemv.h
@@ -32,6 +32,7 @@ class Xgemv: public Routine<T> {
using Routine<T>::TestVectorX;
using Routine<T>::TestVectorY;
using Routine<T>::TestMatrixA;
+ using Routine<T>::TestMatrixAP;
using Routine<T>::RunKernel;
using Routine<T>::ErrorIn;
@@ -55,7 +56,8 @@ 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, const size_t parameter,
+ bool fast_kernel, bool fast_kernel_rot,
+ const size_t parameter, const bool packed,
const size_t kl, const size_t ku);
private:
diff --git a/include/internal/routines/level2/xhpmv.h b/include/internal/routines/level2/xhpmv.h
new file mode 100644
index 00000000..48f1ed3f
--- /dev/null
+++ b/include/internal/routines/level2/xhpmv.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 Xhpmv routine. It is based on the generalized mat-vec multiplication
+// routine (Xgemv). The Xhpmv class inherits from the templated class Xgemv, allowing it to call the
+// "MatVec" function directly.
+//
+// =================================================================================================
+
+#ifndef CLBLAST_ROUTINES_XHPMV_H_
+#define CLBLAST_ROUTINES_XHPMV_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 Xhpmv: public Xgemv<T> {
+ public:
+
+ // Uses the generic matrix-vector routine
+ using Xgemv<T>::MatVec;
+
+ // Constructor
+ Xhpmv(Queue &queue, Event &event, const std::string &name = "HPMV");
+
+ // Templated-precision implementation of the routine
+ StatusCode DoHpmv(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_XHPMV_H_
+#endif
diff --git a/scripts/generator/generator.py b/scripts/generator/generator.py
index cecaf960..5d01f26b 100644
--- a/scripts/generator/generator.py
+++ b/scripts/generator/generator.py
@@ -67,7 +67,7 @@ routines = [
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(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", "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"),
@@ -237,7 +237,7 @@ files = [
path_clblast+"/src/clblast_c.cc",
path_clblast+"/test/wrapper_clblas.h",
]
-header_lines = [84, 46, 80, 24, 22]
+header_lines = [84, 47, 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 3453312f..85c63442 100644
--- a/src/clblast.cc
+++ b/src/clblast.cc
@@ -31,6 +31,7 @@
#include "internal/routines/level2/xgbmv.h"
#include "internal/routines/level2/xhemv.h"
#include "internal/routines/level2/xhbmv.h"
+#include "internal/routines/level2/xhpmv.h"
#include "internal/routines/level2/xsymv.h"
// BLAS level-3 includes
@@ -465,15 +466,26 @@ template StatusCode Hbmv<double2>(const Layout, const Triangle,
// Hermitian packed matrix-vector multiplication: CHPMV/ZHPMV
template <typename T>
-StatusCode Hpmv(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 Hpmv(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 = Xhpmv<T>(queue_cpp, event_cpp);
+ auto status = routine.SetUp();
+ if (status != StatusCode::kSuccess) { return status; }
+ return routine.DoHpmv(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 Hpmv<float2>(const Layout, const Triangle,
const size_t,
diff --git a/src/kernels/level2/xgemv.opencl b/src/kernels/level2/xgemv.opencl
index f0bf4405..f6c4476e 100644
--- a/src/kernels/level2/xgemv.opencl
+++ b/src/kernels/level2/xgemv.opencl
@@ -134,6 +134,29 @@ inline real LoadMatrixA(const __global real* restrict agm, const int x, const in
}
}
+ // For hermitian packed matrices
+ #elif defined(ROUTINE_HPMV)
+ if (parameter == 1) {
+ if (x <= y) {
+ result = agm[((y+1)*y)/2 + x + a_offset];
+ if (x == y) { result.y = ZERO; }
+ }
+ else {
+ result = agm[((x+1)*x)/2 + y + a_offset];
+ COMPLEX_CONJUGATE(result);
+ }
+ }
+ else {
+ if (x >= y) {
+ result = agm[((2*a_ld-(y+1))*y)/2 + x + a_offset];
+ if (x == y) { result.y = ZERO; }
+ }
+ else {
+ result = agm[((2*a_ld-(x+1))*x)/2 + y + a_offset];
+ COMPLEX_CONJUGATE(result);
+ }
+ }
+
// For symmetric matrices
#elif defined(ROUTINE_SYMV)
if ((parameter == 0 && y <= x) || (parameter == 1 && x <= y)) {
diff --git a/src/routines/level2/xgbmv.cc b/src/routines/level2/xgbmv.cc
index d8815542..14d391ca 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,
- 0, kl_real, ku_real);
+ 0, false, kl_real, ku_real);
}
// =================================================================================================
diff --git a/src/routines/level2/xgemv.cc b/src/routines/level2/xgemv.cc
index 0c312756..1b768dcd 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,
- 0, 0, 0); // N/A for this routine
+ 0, false, 0, 0); // N/A for this routine
}
// =================================================================================================
@@ -69,7 +69,8 @@ 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, const size_t parameter,
+ bool fast_kernel, bool fast_kernel_rot,
+ const size_t parameter, const bool packed,
const size_t kl, const size_t ku) {
// Makes sure all dimensions are larger than zero
@@ -97,7 +98,9 @@ StatusCode Xgemv<T>::MatVec(const Layout layout, const Transpose a_transpose,
auto a_conjugate = (a_transpose == Transpose::kConjugate);
// Tests the matrix and the vectors for validity
- auto status = TestMatrixA(a_one, a_two, a_buffer, a_offset, a_ld, sizeof(T));
+ auto status = StatusCode::kSuccess;
+ if (packed) { status = TestMatrixAP(n, a_buffer, a_offset, sizeof(T)); }
+ else { status = TestMatrixA(a_one, a_two, a_buffer, a_offset, a_ld, sizeof(T)); }
if (ErrorIn(status)) { return status; }
status = TestVectorX(n_real, x_buffer, x_offset, x_inc, sizeof(T));
if (ErrorIn(status)) { return status; }
diff --git a/src/routines/level2/xhbmv.cc b/src/routines/level2/xhbmv.cc
index 90c0c787..f59a7cb3 100644
--- a/src/routines/level2/xhbmv.cc
+++ b/src/routines/level2/xhbmv.cc
@@ -51,7 +51,7 @@ StatusCode Xhbmv<T>::DoHbmv(const Layout layout, const Triangle triangle,
x_buffer, x_offset, x_inc, beta,
y_buffer, y_offset, y_inc,
fast_kernels, fast_kernels,
- is_upper, k, 0);
+ is_upper, false, k, 0);
}
// =================================================================================================
diff --git a/src/routines/level2/xhemv.cc b/src/routines/level2/xhemv.cc
index efad829b..5a58b28b 100644
--- a/src/routines/level2/xhemv.cc
+++ b/src/routines/level2/xhemv.cc
@@ -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,
- is_upper, 0, 0);
+ is_upper, false, 0, 0);
}
// =================================================================================================
diff --git a/src/routines/level2/xhpmv.cc b/src/routines/level2/xhpmv.cc
new file mode 100644
index 00000000..2269255d
--- /dev/null
+++ b/src/routines/level2/xhpmv.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 Xhpmv class (see the header for information about the class).
+//
+// =================================================================================================
+
+#include "internal/routines/level2/xhpmv.h"
+
+#include <string>
+#include <vector>
+
+namespace clblast {
+// =================================================================================================
+
+// Constructor: forwards to base class constructor
+template <typename T>
+Xhpmv<T>::Xhpmv(Queue &queue, Event &event, const std::string &name):
+ Xgemv<T>(queue, event, name) {
+}
+
+// =================================================================================================
+
+// The main routine
+template <typename T>
+StatusCode Xhpmv<T>::DoHpmv(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 hermitian packed matrix-accesses are implemented in the kernel guarded by the
+ // ROUTINE_HPMV 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 Xhpmv<float2>;
+template class Xhpmv<double2>;
+
+// =================================================================================================
+} // namespace clblast
diff --git a/src/routines/level2/xsymv.cc b/src/routines/level2/xsymv.cc
index 458d7385..ec12324b 100644
--- a/src/routines/level2/xsymv.cc
+++ b/src/routines/level2/xsymv.cc
@@ -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,
- is_upper, 0, 0);
+ is_upper, false, 0, 0);
}
// =================================================================================================
diff --git a/test/routines/level2/xhpmv.h b/test/routines/level2/xhpmv.h
new file mode 100644
index 00000000..efee7882
--- /dev/null
+++ b/test/routines/level2/xhpmv.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 Xhpmv 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_XHEMV_H_
+#define CLBLAST_TEST_ROUTINES_XHEMV_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 TestXhpmv {
+ 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 = Hpmv(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 = clblasXhpmv(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_XHEMV_H_
+#endif