From 306bf67660da4f1adacaedf9066925240abf4ea9 Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Sun, 6 Mar 2016 15:48:11 +0100 Subject: Added preliminary support for xHPR2 and xSPR2 routines --- src/clblast.cc | 54 ++++++++++++++++++++++++++++------------ src/kernels/level2/level2.opencl | 13 +++++++++- src/routines/level2/xhpr.cc | 3 ++- src/routines/level2/xhpr2.cc | 53 +++++++++++++++++++++++++++++++++++++++ src/routines/level2/xspr.cc | 3 ++- src/routines/level2/xspr2.cc | 53 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 160 insertions(+), 19 deletions(-) create mode 100644 src/routines/level2/xhpr2.cc create mode 100644 src/routines/level2/xspr2.cc (limited to 'src') diff --git a/src/clblast.cc b/src/clblast.cc index 6b8ac409..3695aa02 100644 --- a/src/clblast.cc +++ b/src/clblast.cc @@ -44,9 +44,11 @@ #include "internal/routines/level2/xher.h" #include "internal/routines/level2/xhpr.h" #include "internal/routines/level2/xher2.h" +#include "internal/routines/level2/xhpr2.h" #include "internal/routines/level2/xsyr.h" #include "internal/routines/level2/xspr.h" #include "internal/routines/level2/xsyr2.h" +#include "internal/routines/level2/xspr2.h" // BLAS level-3 includes #include "internal/routines/level3/xgemm.h" @@ -1052,14 +1054,24 @@ template StatusCode Her2(const Layout, const Triangle, // Hermitian packed rank-2 matrix update: CHPR2/ZHPR2 template -StatusCode Hpr2(const Layout, const Triangle, - const size_t, - const T, - const cl_mem, const size_t, const size_t, - const cl_mem, const size_t, const size_t, - cl_mem, const size_t, - cl_command_queue*, cl_event*) { - return StatusCode::kNotImplemented; +StatusCode Hpr2(const Layout layout, const Triangle triangle, + const size_t n, + const T alpha, + const cl_mem x_buffer, const size_t x_offset, const size_t x_inc, + const cl_mem y_buffer, const size_t y_offset, const size_t y_inc, + cl_mem ap_buffer, const size_t ap_offset, + cl_command_queue* queue, cl_event* event) { + auto queue_cpp = Queue(*queue); + auto event_cpp = Event(*event); + auto routine = Xhpr2(queue_cpp, event_cpp); + auto status = routine.SetUp(); + if (status != StatusCode::kSuccess) { return status; } + return routine.DoHpr2(layout, triangle, + n, + alpha, + Buffer(x_buffer), x_offset, x_inc, + Buffer(y_buffer), y_offset, y_inc, + Buffer(ap_buffer), ap_offset); } template StatusCode Hpr2(const Layout, const Triangle, const size_t, @@ -1178,14 +1190,24 @@ template StatusCode Syr2(const Layout, const Triangle, // Symmetric packed rank-2 matrix update: SSPR2/DSPR2 template -StatusCode Spr2(const Layout, const Triangle, - const size_t, - const T, - const cl_mem, const size_t, const size_t, - const cl_mem, const size_t, const size_t, - cl_mem, const size_t, - cl_command_queue*, cl_event*) { - return StatusCode::kNotImplemented; +StatusCode Spr2(const Layout layout, const Triangle triangle, + const size_t n, + const T alpha, + const cl_mem x_buffer, const size_t x_offset, const size_t x_inc, + const cl_mem y_buffer, const size_t y_offset, const size_t y_inc, + cl_mem ap_buffer, const size_t ap_offset, + cl_command_queue* queue, cl_event* event) { + auto queue_cpp = Queue(*queue); + auto event_cpp = Event(*event); + auto routine = Xspr2(queue_cpp, event_cpp); + auto status = routine.SetUp(); + if (status != StatusCode::kSuccess) { return status; } + return routine.DoSpr2(layout, triangle, + n, + alpha, + Buffer(x_buffer), x_offset, x_inc, + Buffer(y_buffer), y_offset, y_inc, + Buffer(ap_buffer), ap_offset); } template StatusCode Spr2(const Layout, const Triangle, const size_t, diff --git a/src/kernels/level2/level2.opencl b/src/kernels/level2/level2.opencl index 1b0efeab..be979766 100644 --- a/src/kernels/level2/level2.opencl +++ b/src/kernels/level2/level2.opencl @@ -109,7 +109,18 @@ inline void MatrixUpdate2(const int id1, const int id2, const int max1, const in // Bounds of a regular matrix if (id1 < max1 && id2 < max2) { - const int a_index = id2*a_ld + id1 + a_offset; + #if defined(ROUTINE_SPR2) || defined(ROUTINE_HPR2) + int a_index; + if (is_upper) { + a_index = (id1 <= id2) ? ((id2+1)*id2)/2 + id1 : ((id1+1)*id1)/2 + id2; + } + else { + a_index = (id1 >= id2) ? ((2*a_ld-(id2+1))*id2)/2 + id1 : ((2*a_ld-(id1+1))*id1)/2 + id2; + } + a_index += a_offset; + #else + const int a_index = id2*a_ld + id1 + a_offset; + #endif // Loads the current value of the A matrix const real avalue = agm[a_index]; diff --git a/src/routines/level2/xhpr.cc b/src/routines/level2/xhpr.cc index 24d7ae95..b0cea72f 100644 --- a/src/routines/level2/xhpr.cc +++ b/src/routines/level2/xhpr.cc @@ -37,7 +37,8 @@ StatusCode Xhpr::DoHpr(const Layout layout, const Triangle triangle, // Specific Xhpr functionality is implemented in the kernel using defines return DoHer(layout, triangle, n, alpha, x_buffer, x_offset, x_inc, - ap_buffer, ap_offset, n, true); + ap_buffer, ap_offset, n, + true); // packed matrix } // ================================================================================================= diff --git a/src/routines/level2/xhpr2.cc b/src/routines/level2/xhpr2.cc new file mode 100644 index 00000000..ded35e53 --- /dev/null +++ b/src/routines/level2/xhpr2.cc @@ -0,0 +1,53 @@ + +// ================================================================================================= +// 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 +// +// This file implements the Xhpr2 class (see the header for information about the class). +// +// ================================================================================================= + +#include "internal/routines/level2/xhpr2.h" + +#include + +namespace clblast { +// ================================================================================================= + +// Constructor: forwards to base class constructor +template +Xhpr2::Xhpr2(Queue &queue, Event &event, const std::string &name): + Xher2(queue, event, name) { +} + +// ================================================================================================= + +// The main routine +template +StatusCode Xhpr2::DoHpr2(const Layout layout, const Triangle triangle, + const size_t n, + const T alpha, + const Buffer &x_buffer, const size_t x_offset, const size_t x_inc, + const Buffer &y_buffer, const size_t y_offset, const size_t y_inc, + const Buffer &ap_buffer, const size_t ap_offset) { + + // Specific Xhpr2 functionality is implemented in the kernel using defines + return DoHer2(layout, triangle, n, alpha, + x_buffer, x_offset, x_inc, + y_buffer, y_offset, y_inc, + ap_buffer, ap_offset, n, + true); // packed matrix +} + +// ================================================================================================= + +// Compiles the templated class +template class Xhpr2; +template class Xhpr2; + +// ================================================================================================= +} // namespace clblast diff --git a/src/routines/level2/xspr.cc b/src/routines/level2/xspr.cc index 7ef41fba..2d998e0b 100644 --- a/src/routines/level2/xspr.cc +++ b/src/routines/level2/xspr.cc @@ -37,7 +37,8 @@ StatusCode Xspr::DoSpr(const Layout layout, const Triangle triangle, // Specific Xspr functionality is implemented in the kernel using defines return DoHer(layout, triangle, n, alpha, x_buffer, x_offset, x_inc, - ap_buffer, ap_offset, n, true); + ap_buffer, ap_offset, n, + true); // packed matrix } // ================================================================================================= diff --git a/src/routines/level2/xspr2.cc b/src/routines/level2/xspr2.cc new file mode 100644 index 00000000..fd5232da --- /dev/null +++ b/src/routines/level2/xspr2.cc @@ -0,0 +1,53 @@ + +// ================================================================================================= +// 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 +// +// This file implements the Xspr2 class (see the header for information about the class). +// +// ================================================================================================= + +#include "internal/routines/level2/xspr2.h" + +#include + +namespace clblast { +// ================================================================================================= + +// Constructor: forwards to base class constructor +template +Xspr2::Xspr2(Queue &queue, Event &event, const std::string &name): + Xher2(queue, event, name) { +} + +// ================================================================================================= + +// The main routine +template +StatusCode Xspr2::DoSpr2(const Layout layout, const Triangle triangle, + const size_t n, + const T alpha, + const Buffer &x_buffer, const size_t x_offset, const size_t x_inc, + const Buffer &y_buffer, const size_t y_offset, const size_t y_inc, + const Buffer &ap_buffer, const size_t ap_offset) { + + // Specific Xspr2 functionality is implemented in the kernel using defines + return DoHer2(layout, triangle, n, alpha, + x_buffer, x_offset, x_inc, + y_buffer, y_offset, y_inc, + ap_buffer, ap_offset, n, + true); // packed matrix +} + +// ================================================================================================= + +// Compiles the templated class +template class Xspr2; +template class Xspr2; + +// ================================================================================================= +} // namespace clblast -- cgit v1.2.3