summaryrefslogtreecommitdiff
path: root/src/routines/levelx/xomatcopy.cpp
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2016-06-28 22:32:25 +0200
committerGitHub <noreply@github.com>2016-06-28 22:32:25 +0200
commit7c13bacf129291e3e295ecb6e833788477085fa0 (patch)
treed114eeca418444d0b1c70cc9cce983de041235c9 /src/routines/levelx/xomatcopy.cpp
parent181eb20bbf15cf11baaf6112b6965050c49dd543 (diff)
parent577f0ee1179014ece853af39d6f0ff0c87316eb3 (diff)
Merge pull request #70 from CNugteren/development
Update to version 0.8.0
Diffstat (limited to 'src/routines/levelx/xomatcopy.cpp')
-rw-r--r--src/routines/levelx/xomatcopy.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/routines/levelx/xomatcopy.cpp b/src/routines/levelx/xomatcopy.cpp
new file mode 100644
index 00000000..e8593301
--- /dev/null
+++ b/src/routines/levelx/xomatcopy.cpp
@@ -0,0 +1,94 @@
+
+// =================================================================================================
+// 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 Xomatcopy class (see the header for information about the class).
+//
+// =================================================================================================
+
+#include "routines/levelx/xomatcopy.hpp"
+
+#include <string>
+#include <vector>
+
+namespace clblast {
+// =================================================================================================
+
+// Constructor: forwards to base class constructor
+template <typename T>
+Xomatcopy<T>::Xomatcopy(Queue &queue, EventPointer event, const std::string &name):
+ Routine(queue, event, name, {"Copy","Pad","Transpose","Padtranspose"}, PrecisionValue<T>()) {
+ source_string_ =
+ #include "../../kernels/level3/level3.opencl"
+ #include "../../kernels/level3/copy_fast.opencl"
+ #include "../../kernels/level3/copy_pad.opencl"
+ #include "../../kernels/level3/transpose_fast.opencl"
+ #include "../../kernels/level3/transpose_pad.opencl"
+ ;
+}
+
+// =================================================================================================
+
+// The main routine
+template <typename T>
+StatusCode Xomatcopy<T>::DoOmatcopy(const Layout layout, const Transpose a_transpose,
+ const size_t m, const size_t n, const T alpha,
+ const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
+ const Buffer<T> &b_buffer, const size_t b_offset, const size_t b_ld) {
+
+ // Makes sure all dimensions are larger than zero
+ if ((m == 0) || (n == 0)) { return StatusCode::kInvalidDimension; }
+
+ // Determines whether to transpose the matrix A
+ const auto transpose = (a_transpose != Transpose::kNo);
+
+ // In case of complex data-types, the transpose can also become a conjugate transpose
+ const auto conjugate = (a_transpose == Transpose::kConjugate);
+
+ // Computes the dimensions of the two matrices
+ const auto rotated = (layout == Layout::kRowMajor);
+ const auto a_one = (rotated) ? n : m;
+ const auto a_two = (rotated) ? m : n;
+ const auto b_one = (transpose) ? a_two : a_one;
+ const auto b_two = (transpose) ? a_one : a_two;
+
+ // Tests the matrices for validity, first from a perspective of the OpenCL buffers and their
+ // sizes, and then from a perspective of parameter values (e.g. m, n). Tests whether the OpenCL
+ // buffers are valid and non-zero and whether the OpenCL buffers have sufficient storage space.
+ // Also tests that the leading dimensions of:
+ // matrix A cannot be less than N when rotated, or less than M when not-rotated
+ // matrix B cannot be less than M when rotated, or less than N when not-rotated
+ auto status = TestMatrixA(a_one, a_two, a_buffer, a_offset, a_ld);
+ if (ErrorIn(status)) { return status; }
+ status = TestMatrixB(b_one, b_two, b_buffer, b_offset, b_ld);
+ if (ErrorIn(status)) { return status; }
+
+ // Loads the program from the database
+ const auto program = GetProgramFromCache(context_, PrecisionValue<T>(), routine_name_);
+
+ auto emptyEventList = std::vector<Event>();
+ status = PadCopyTransposeMatrix(queue_, device_, context_, db_, event_, emptyEventList,
+ a_one, a_two, a_ld, a_offset, a_buffer,
+ b_one, b_two, b_ld, b_offset, b_buffer,
+ alpha, program, false, transpose, conjugate);
+ if (ErrorIn(status)) { return status; }
+
+ return StatusCode::kSuccess;
+}
+
+// =================================================================================================
+
+// Compiles the templated class
+template class Xomatcopy<half>;
+template class Xomatcopy<float>;
+template class Xomatcopy<double>;
+template class Xomatcopy<float2>;
+template class Xomatcopy<double2>;
+
+// =================================================================================================
+} // namespace clblast