Skip to content

Commit

Permalink
Batched - Dense QR: applying clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Luc Berger-Vergiat <[email protected]>
  • Loading branch information
lucbv committed Dec 4, 2024
1 parent f173adf commit def21e7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ struct SerialApplyRightHouseholderInternal {

// A2 -= w1 * u2' (ger with conjugate)
for (int j = 0; j < n; ++j)
for (int i = 0; i < m; ++i) A2[i * as0 + j * as1] -= w1[i * ws0] * Kokkos::ArithTraits<ValueType>::conj(u2[j * u2s]);
for (int i = 0; i < m; ++i)
A2[i * as0 + j * as1] -= w1[i * ws0] * Kokkos::ArithTraits<ValueType>::conj(u2[j * u2s]);

return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions batched/dense/impl/KokkosBatched_SVD_Serial_Internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ struct SerialSVDInternal {
As0, As1, work, 1);
}
if (U) {
KokkosBatched::SerialApplyRightHouseholderInternal::invoke<value_type>(
m, m - i - 1, &tau, &SVDIND(A, i + 1, i), As0, &SVDIND(U, 0, i), Us0, &SVDIND(U, 0, i + 1), Us0, Us1, work, 1);
KokkosBatched::SerialApplyRightHouseholderInternal::invoke<value_type>(m, m - i - 1, &tau, &SVDIND(A, i + 1, i),
As0, &SVDIND(U, 0, i), Us0,
&SVDIND(U, 0, i + 1), Us0, Us1, work, 1);
}
// Zero out A subdiag explicitly (NOTE: may not be necessary...)
for (int j = i + 1; j < m; j++) {
Expand Down
48 changes: 30 additions & 18 deletions batched/dense/unit_test/Test_Batched_SerialQR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ struct qrFunctor {
}

// Call ApplyQ on Q
for(int idx = 0; idx < w.extent_int(0); ++idx) { w(idx) = 0.0; }
for (int idx = 0; idx < w.extent_int(0); ++idx) {
w(idx) = 0.0;
}
KokkosBatched::SerialApplyQ<Side::Left, Trans::NoTranspose, Algo::ApplyQ::Unblocked>::invoke(A, tau, Q, w);

// Now apply Q' to Q
for(int idx = 0; idx < w.extent_int(0); ++idx) { w(idx) = 0.0; }
for (int idx = 0; idx < w.extent_int(0); ++idx) {
w(idx) = 0.0;
}
KokkosBatched::SerialApplyQ<Side::Left, Trans::Transpose, Algo::ApplyQ::Unblocked>::invoke(A, tau, Q, w);

// At this point Q stores Q'Q
Expand Down Expand Up @@ -94,12 +98,14 @@ struct qrFunctor {
if (rowIdx <= colIdx) {
if (Kokkos::abs(B(rowIdx, colIdx) - A(rowIdx, colIdx)) > tol * Kokkos::abs(A(rowIdx, colIdx))) {
error += 1;
Kokkos::printf("B stores R\nmatIdx=%d, B(%d, %d)=%e instead of %e.\n", matIdx, rowIdx, colIdx, B(rowIdx, colIdx), A(rowIdx, colIdx));
Kokkos::printf("B stores R\nmatIdx=%d, B(%d, %d)=%e instead of %e.\n", matIdx, rowIdx, colIdx,
B(rowIdx, colIdx), A(rowIdx, colIdx));
}
} else {
if (Kokkos::abs(B(rowIdx, colIdx)) > 1000 * tol) {
error += 1;
Kokkos::printf("B stores R\nmatIdx=%d, B(%d, %d)=%e instead of 0.0.\n", matIdx, rowIdx, colIdx, B(rowIdx, colIdx));
Kokkos::printf("B stores R\nmatIdx=%d, B(%d, %d)=%e instead of 0.0.\n", matIdx, rowIdx, colIdx,
B(rowIdx, colIdx));
}
}
}
Expand Down Expand Up @@ -344,9 +350,9 @@ void test_QR_batch() {

using ExecutionSpace = typename Device::execution_space;

{ // Square matrix case
constexpr int numMat = 314; // 314
constexpr int maxMatSize = 36; // 36
{ // Square matrix case
constexpr int numMat = 314; // 314
constexpr int maxMatSize = 36; // 36
Kokkos::View<Scalar**, ExecutionSpace> tau("tau", numMat, maxMatSize);
Kokkos::View<Scalar**, ExecutionSpace> tmp("work buffer", numMat, maxMatSize);
Kokkos::View<Scalar***, ExecutionSpace> As("A matrices", numMat, maxMatSize, maxMatSize);
Expand All @@ -371,10 +377,10 @@ void test_QR_batch() {
EXPECT_EQ(global_error_h(), 0);
}

{ // Rectangular matrix case
constexpr int numMat = 2; // 314
constexpr int numRows = 3; // 42
constexpr int numCols = 2; // 36
{ // Rectangular matrix case
constexpr int numMat = 2; // 314
constexpr int numRows = 3; // 42
constexpr int numCols = 2; // 36
Kokkos::View<Scalar**, ExecutionSpace> tau("tau", numMat, numCols);
Kokkos::View<Scalar**, ExecutionSpace> tmp("work buffer", numMat, numCols);
Kokkos::View<Scalar***, ExecutionSpace> As("A matrices", numMat, numRows, numCols);
Expand All @@ -393,13 +399,19 @@ void test_QR_batch() {
{
typename Kokkos::View<Scalar***, ExecutionSpace>::HostMirror As_h = Kokkos::create_mirror_view(As);
Kokkos::deep_copy(As_h, As);
As_h(0, 0, 0) = 3.0; As_h(0, 0, 1) = 5.0;
As_h(0, 1, 0) = 4.0; As_h(0, 1, 1) = 0.0;
As_h(0, 2, 0) = 0.0; As_h(0, 2, 1) = -3.0;

As_h(1, 0, 0) = 3.0; As_h(1, 0, 1) = 5.0;
As_h(1, 1, 0) = 4.0; As_h(1, 1, 1) = 0.0;
As_h(1, 2, 0) = 0.0; As_h(1, 2, 1) = -3.0;
As_h(0, 0, 0) = 3.0;
As_h(0, 0, 1) = 5.0;
As_h(0, 1, 0) = 4.0;
As_h(0, 1, 1) = 0.0;
As_h(0, 2, 0) = 0.0;
As_h(0, 2, 1) = -3.0;

As_h(1, 0, 0) = 3.0;
As_h(1, 0, 1) = 5.0;
As_h(1, 1, 0) = 4.0;
As_h(1, 1, 1) = 0.0;
As_h(1, 2, 0) = 0.0;
As_h(1, 2, 1) = -3.0;

Kokkos::deep_copy(As, As_h);
}
Expand Down

0 comments on commit def21e7

Please sign in to comment.