summaryrefslogtreecommitdiff
path: root/src/routines/level3/xher2k.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/routines/level3/xher2k.cpp')
-rw-r--r--src/routines/level3/xher2k.cpp286
1 files changed, 133 insertions, 153 deletions
diff --git a/src/routines/level3/xher2k.cpp b/src/routines/level3/xher2k.cpp
index ba770065..a326dfbe 100644
--- a/src/routines/level3/xher2k.cpp
+++ b/src/routines/level3/xher2k.cpp
@@ -39,16 +39,16 @@ Xher2k<T,U>::Xher2k(Queue &queue, EventPointer event, const std::string &name):
// The main routine
template <typename T, typename U>
-StatusCode Xher2k<T,U>::DoHer2k(const Layout layout, const Triangle triangle, const Transpose ab_transpose,
- 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> &b_buffer, const size_t b_offset, const size_t b_ld,
- const U beta,
- const Buffer<T> &c_buffer, const size_t c_offset, const size_t c_ld) {
+void Xher2k<T,U>::DoHer2k(const Layout layout, const Triangle triangle, const Transpose ab_transpose,
+ 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> &b_buffer, const size_t b_offset, const size_t b_ld,
+ const U beta,
+ const Buffer<T> &c_buffer, const size_t c_offset, const size_t c_ld) {
// Makes sure all dimensions are larger than zero
- if ((n == 0) || (k == 0) ) { return StatusCode::kInvalidDimension; }
+ if ((n == 0) || (k == 0) ) { throw BLASError(StatusCode::kInvalidDimension); }
// Determines whether to apply the conjugate transpose to matrix B (argument: no transpose) or
// to matrix A (argument: conjugate transpose)
@@ -71,12 +71,9 @@ StatusCode Xher2k<T,U>::DoHer2k(const Layout layout, const Triangle triangle, co
// matrix A cannot be less than N when rotated, or less than K when not-rotated
// matrix B cannot be less than N when rotated, or less than K when not-rotated
// matrix C cannot be less than N
- auto status = TestMatrixA(ab_one, ab_two, a_buffer, a_offset, a_ld);
- if (ErrorIn(status)) { return status; }
- status = TestMatrixB(ab_one, ab_two, b_buffer, b_offset, b_ld);
- if (ErrorIn(status)) { return status; }
- status = TestMatrixC(n, n, c_buffer, c_offset, c_ld);
- if (ErrorIn(status)) { return status; }
+ TestMatrixA(ab_one, ab_two, a_buffer, a_offset, a_ld);
+ TestMatrixB(ab_one, ab_two, b_buffer, b_offset, b_ld);
+ TestMatrixC(n, n, c_buffer, c_offset, c_ld);
// Calculates the ceiled versions of n and k
auto n_ceiled = Ceil(n, db_["NWG"]);
@@ -85,145 +82,128 @@ StatusCode Xher2k<T,U>::DoHer2k(const Layout layout, const Triangle triangle, co
// Decides which kernel to run: the upper-triangular or lower-triangular version
auto kernel_name = (triangle == Triangle::kUpper) ? "XgemmUpper" : "XgemmLower";
- // The padded/transposed input/output matrices: if memory allocation fails, throw an exception
- try {
-
- // Loads the program from the database
- const auto program = GetProgramFromCache(context_, PrecisionValue<T>(), routine_name_);
-
- // Determines whether or not temporary matrices are needed
- auto a1_no_temp = ab_one == n_ceiled && ab_two == k_ceiled && a_ld == n_ceiled && a_offset == 0 &&
- ab_rotated == false && ab_conjugate == false;
- auto a2_no_temp = ab_one == n_ceiled && ab_two == k_ceiled && a_ld == n_ceiled && a_offset == 0 &&
- ab_rotated == false && ab_conjugate == true;
- auto b1_no_temp = ab_one == n_ceiled && ab_two == k_ceiled && b_ld == n_ceiled && b_offset == 0 &&
- ab_rotated == false && ab_conjugate == false;
- auto b2_no_temp = ab_one == n_ceiled && ab_two == k_ceiled && b_ld == n_ceiled && b_offset == 0 &&
- ab_rotated == false && ab_conjugate == true;
-
- // Creates the temporary matrices
- auto a1_temp = (a1_no_temp) ? a_buffer : Buffer<T>(context_, k_ceiled*n_ceiled);
- auto a2_temp = (a2_no_temp) ? a_buffer : Buffer<T>(context_, k_ceiled*n_ceiled);
- auto b1_temp = (b1_no_temp) ? b_buffer : Buffer<T>(context_, k_ceiled*n_ceiled);
- auto b2_temp = (b2_no_temp) ? b_buffer : Buffer<T>(context_, k_ceiled*n_ceiled);
- auto c_temp = Buffer<T>(context_, n_ceiled*n_ceiled);
-
- // Convert the arguments to complex versions
- auto complex_beta = T{beta, static_cast<U>(0.0)};
-
- // Events of all kernels (including pre/post processing kernels)
- auto eventWaitList = std::vector<Event>();
- auto emptyEventList = std::vector<Event>();
-
- // Runs the pre-processing kernels. This transposes the matrices A and B, but also pads zeros to
- // to fill it up until it reaches a certain multiple of size (kernel parameter dependent). In
- // case nothing has to be done, these kernels can be skipped.
- if (!a1_no_temp) {
- auto eventProcessA1 = Event();
- status = PadCopyTransposeMatrix(queue_, device_, db_, eventProcessA1.pointer(), emptyEventList,
- ab_one, ab_two, a_ld, a_offset, a_buffer,
- n_ceiled, k_ceiled, n_ceiled, 0, a1_temp,
- ConstantOne<T>(), program,
- true, ab_rotated, ab_conjugate);
- eventWaitList.push_back(eventProcessA1);
- if (ErrorIn(status)) { return status; }
- }
- if (!a2_no_temp) {
- auto eventProcessA2 = Event();
- status = PadCopyTransposeMatrix(queue_, device_, db_, eventProcessA2.pointer(), emptyEventList,
- ab_one, ab_two, a_ld, a_offset, a_buffer,
- n_ceiled, k_ceiled, n_ceiled, 0, a2_temp,
- ConstantOne<T>(), program,
- true, ab_rotated, !ab_conjugate);
- eventWaitList.push_back(eventProcessA2);
- if (ErrorIn(status)) { return status; }
- }
- if (!b1_no_temp) {
- auto eventProcessB1 = Event();
- status = PadCopyTransposeMatrix(queue_, device_, db_, eventProcessB1.pointer(), emptyEventList,
- ab_one, ab_two, b_ld, b_offset, b_buffer,
- n_ceiled, k_ceiled, n_ceiled, 0, b1_temp,
- ConstantOne<T>(), program,
- true, ab_rotated, ab_conjugate);
- eventWaitList.push_back(eventProcessB1);
- if (ErrorIn(status)) { return status; }
- }
- if (!b2_no_temp) {
- auto eventProcessB2 = Event();
- status = PadCopyTransposeMatrix(queue_, device_, db_, eventProcessB2.pointer(), emptyEventList,
- ab_one, ab_two, b_ld, b_offset, b_buffer,
- n_ceiled, k_ceiled, n_ceiled, 0, b2_temp,
- ConstantOne<T>(), program,
- true, ab_rotated, !ab_conjugate);
- eventWaitList.push_back(eventProcessB2);
- if (ErrorIn(status)) { return status; }
- }
-
- // Furthermore, also creates a (possibly padded) copy of matrix C, since it is not allowed to
- // modify the other triangle.
- auto eventProcessC = Event();
- status = PadCopyTransposeMatrix(queue_, device_, db_, eventProcessC.pointer(), emptyEventList,
- n, n, c_ld, c_offset, c_buffer,
- n_ceiled, n_ceiled, n_ceiled, 0, c_temp,
- ConstantOne<T>(), program,
- true, c_rotated, false);
- eventWaitList.push_back(eventProcessC);
- if (ErrorIn(status)) { return status; }
-
- // Retrieves the XgemmUpper or XgemmLower kernel from the compiled binary
- try {
- auto kernel = Kernel(program, kernel_name);
-
- // Sets the kernel arguments
- kernel.SetArgument(0, static_cast<int>(n_ceiled));
- kernel.SetArgument(1, static_cast<int>(k_ceiled));
- kernel.SetArgument(2, GetRealArg(alpha));
- kernel.SetArgument(3, GetRealArg(complex_beta));
- kernel.SetArgument(4, a1_temp());
- kernel.SetArgument(5, b2_temp());
- kernel.SetArgument(6, c_temp());
-
- // Computes the global and local thread sizes
- auto global = std::vector<size_t>{
- (n_ceiled * db_["MDIMC"]) / db_["MWG"],
- (n_ceiled * db_["NDIMC"]) / db_["NWG"]
- };
- auto local = std::vector<size_t>{db_["MDIMC"], db_["NDIMC"]};
-
- // Launches the kernel
- auto eventKernel1 = Event();
- status = RunKernel(kernel, queue_, device_, global, local, eventKernel1.pointer(), eventWaitList);
- if (ErrorIn(status)) { return status; }
- eventWaitList.push_back(eventKernel1);
-
- // Swaps the arguments for matrices A and B, sets 'beta' to 1, and conjugate alpha
- auto conjugate_alpha = T{alpha.real(), -alpha.imag()};
- auto complex_one = T{static_cast<U>(1.0), static_cast<U>(0.0)};
- kernel.SetArgument(2, GetRealArg(conjugate_alpha));
- kernel.SetArgument(3, GetRealArg(complex_one));
- kernel.SetArgument(4, b1_temp());
- kernel.SetArgument(5, a2_temp());
-
- // Runs the kernel again
- auto eventKernel2 = Event();
- status = RunKernel(kernel, queue_, device_, global, local, eventKernel2.pointer(), eventWaitList);
- if (ErrorIn(status)) { return status; }
- eventWaitList.push_back(eventKernel2);
-
- // Runs the post-processing kernel
- auto upper = (triangle == Triangle::kUpper);
- auto lower = (triangle == Triangle::kLower);
- status = PadCopyTransposeMatrix(queue_, device_, db_, event_, eventWaitList,
- n_ceiled, n_ceiled, n_ceiled, 0, c_temp,
- n, n, c_ld, c_offset, c_buffer,
- ConstantOne<T>(), program,
- false, c_rotated, false, upper, lower, true);
- if (ErrorIn(status)) { return status; }
-
- // Successfully finished the computation
- return StatusCode::kSuccess;
- } catch (...) { return StatusCode::kInvalidKernel; }
- } catch (...) { return StatusCode::kTempBufferAllocFailure; }
+ // Loads the program from the database
+ const auto program = GetProgramFromCache(context_, PrecisionValue<T>(), routine_name_);
+
+ // Determines whether or not temporary matrices are needed
+ auto a1_no_temp = ab_one == n_ceiled && ab_two == k_ceiled && a_ld == n_ceiled && a_offset == 0 &&
+ ab_rotated == false && ab_conjugate == false;
+ auto a2_no_temp = ab_one == n_ceiled && ab_two == k_ceiled && a_ld == n_ceiled && a_offset == 0 &&
+ ab_rotated == false && ab_conjugate == true;
+ auto b1_no_temp = ab_one == n_ceiled && ab_two == k_ceiled && b_ld == n_ceiled && b_offset == 0 &&
+ ab_rotated == false && ab_conjugate == false;
+ auto b2_no_temp = ab_one == n_ceiled && ab_two == k_ceiled && b_ld == n_ceiled && b_offset == 0 &&
+ ab_rotated == false && ab_conjugate == true;
+
+ // Creates the temporary matrices
+ auto a1_temp = (a1_no_temp) ? a_buffer : Buffer<T>(context_, k_ceiled*n_ceiled);
+ auto a2_temp = (a2_no_temp) ? a_buffer : Buffer<T>(context_, k_ceiled*n_ceiled);
+ auto b1_temp = (b1_no_temp) ? b_buffer : Buffer<T>(context_, k_ceiled*n_ceiled);
+ auto b2_temp = (b2_no_temp) ? b_buffer : Buffer<T>(context_, k_ceiled*n_ceiled);
+ auto c_temp = Buffer<T>(context_, n_ceiled*n_ceiled);
+
+ // Convert the arguments to complex versions
+ auto complex_beta = T{beta, static_cast<U>(0.0)};
+
+ // Events of all kernels (including pre/post processing kernels)
+ auto eventWaitList = std::vector<Event>();
+ auto emptyEventList = std::vector<Event>();
+
+ // Runs the pre-processing kernels. This transposes the matrices A and B, but also pads zeros to
+ // to fill it up until it reaches a certain multiple of size (kernel parameter dependent). In
+ // case nothing has to be done, these kernels can be skipped.
+ if (!a1_no_temp) {
+ auto eventProcessA1 = Event();
+ PadCopyTransposeMatrix(queue_, device_, db_, eventProcessA1.pointer(), emptyEventList,
+ ab_one, ab_two, a_ld, a_offset, a_buffer,
+ n_ceiled, k_ceiled, n_ceiled, 0, a1_temp,
+ ConstantOne<T>(), program,
+ true, ab_rotated, ab_conjugate);
+ eventWaitList.push_back(eventProcessA1);
+ }
+ if (!a2_no_temp) {
+ auto eventProcessA2 = Event();
+ PadCopyTransposeMatrix(queue_, device_, db_, eventProcessA2.pointer(), emptyEventList,
+ ab_one, ab_two, a_ld, a_offset, a_buffer,
+ n_ceiled, k_ceiled, n_ceiled, 0, a2_temp,
+ ConstantOne<T>(), program,
+ true, ab_rotated, !ab_conjugate);
+ eventWaitList.push_back(eventProcessA2);
+ }
+ if (!b1_no_temp) {
+ auto eventProcessB1 = Event();
+ PadCopyTransposeMatrix(queue_, device_, db_, eventProcessB1.pointer(), emptyEventList,
+ ab_one, ab_two, b_ld, b_offset, b_buffer,
+ n_ceiled, k_ceiled, n_ceiled, 0, b1_temp,
+ ConstantOne<T>(), program,
+ true, ab_rotated, ab_conjugate);
+ eventWaitList.push_back(eventProcessB1);
+ }
+ if (!b2_no_temp) {
+ auto eventProcessB2 = Event();
+ PadCopyTransposeMatrix(queue_, device_, db_, eventProcessB2.pointer(), emptyEventList,
+ ab_one, ab_two, b_ld, b_offset, b_buffer,
+ n_ceiled, k_ceiled, n_ceiled, 0, b2_temp,
+ ConstantOne<T>(), program,
+ true, ab_rotated, !ab_conjugate);
+ eventWaitList.push_back(eventProcessB2);
+ }
+
+ // Furthermore, also creates a (possibly padded) copy of matrix C, since it is not allowed to
+ // modify the other triangle.
+ auto eventProcessC = Event();
+ PadCopyTransposeMatrix(queue_, device_, db_, eventProcessC.pointer(), emptyEventList,
+ n, n, c_ld, c_offset, c_buffer,
+ n_ceiled, n_ceiled, n_ceiled, 0, c_temp,
+ ConstantOne<T>(), program,
+ true, c_rotated, false);
+ eventWaitList.push_back(eventProcessC);
+
+ // Retrieves the XgemmUpper or XgemmLower kernel from the compiled binary
+ auto kernel = Kernel(program, kernel_name);
+
+ // Sets the kernel arguments
+ kernel.SetArgument(0, static_cast<int>(n_ceiled));
+ kernel.SetArgument(1, static_cast<int>(k_ceiled));
+ kernel.SetArgument(2, GetRealArg(alpha));
+ kernel.SetArgument(3, GetRealArg(complex_beta));
+ kernel.SetArgument(4, a1_temp());
+ kernel.SetArgument(5, b2_temp());
+ kernel.SetArgument(6, c_temp());
+
+ // Computes the global and local thread sizes
+ auto global = std::vector<size_t>{
+ (n_ceiled * db_["MDIMC"]) / db_["MWG"],
+ (n_ceiled * db_["NDIMC"]) / db_["NWG"]
+ };
+ auto local = std::vector<size_t>{db_["MDIMC"], db_["NDIMC"]};
+
+ // Launches the kernel
+ auto eventKernel1 = Event();
+ RunKernel(kernel, queue_, device_, global, local, eventKernel1.pointer(), eventWaitList);
+ eventWaitList.push_back(eventKernel1);
+
+ // Swaps the arguments for matrices A and B, sets 'beta' to 1, and conjugate alpha
+ auto conjugate_alpha = T{alpha.real(), -alpha.imag()};
+ auto complex_one = T{static_cast<U>(1.0), static_cast<U>(0.0)};
+ kernel.SetArgument(2, GetRealArg(conjugate_alpha));
+ kernel.SetArgument(3, GetRealArg(complex_one));
+ kernel.SetArgument(4, b1_temp());
+ kernel.SetArgument(5, a2_temp());
+
+ // Runs the kernel again
+ auto eventKernel2 = Event();
+ RunKernel(kernel, queue_, device_, global, local, eventKernel2.pointer(), eventWaitList);
+ eventWaitList.push_back(eventKernel2);
+
+ // Runs the post-processing kernel
+ auto upper = (triangle == Triangle::kUpper);
+ auto lower = (triangle == Triangle::kLower);
+ PadCopyTransposeMatrix(queue_, device_, db_, event_, eventWaitList,
+ n_ceiled, n_ceiled, n_ceiled, 0, c_temp,
+ n, n, c_ld, c_offset, c_buffer,
+ ConstantOne<T>(), program,
+ false, c_rotated, false, upper, lower, true);
}
// =================================================================================================