| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
#ifndef KOKKOSBATCHED_APPLY_PIVOT_IMPL_HPP |
| 17 |
#define KOKKOSBATCHED_APPLY_PIVOT_IMPL_HPP |
| 18 |
|
| 19 |
/// \author Kyungjoo Kim ([email protected]) |
| 20 |
|
| 21 |
#include "KokkosBatched_Util.hpp" |
| 22 |
#include "KokkosBatched_ApplyPivot_Internal.hpp" |
| 23 |
|
| 24 |
namespace KokkosBatched { |
| 25 |
|
| 26 |
/// |
| 27 |
/// TeamVector Internal Impl |
| 28 |
/// ======================== |
| 29 |
|
| 30 |
/// |
| 31 |
/// Forward pivot apply |
| 32 |
/// |
| 33 |
|
| 34 |
/// row swap |
| 35 |
template <typename MemberType> |
| 36 |
struct TeamVectorApplyPivot<MemberType, Side::Left, Direct::Forward> { |
| 37 |
template <typename AViewType> |
| 38 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int piv, const AViewType &A) { |
| 39 |
if (AViewType::rank == 1) { |
| 40 |
const int as0 = A.stride(0); |
| 41 |
TeamVectorApplyPivotVectorForwardInternal::invoke(member, piv, A.data(), as0); |
| 42 |
} else if (AViewType::rank == 2) { |
| 43 |
const int n = A.extent(1), as0 = A.stride(0), as1 = A.stride(1); |
| 44 |
TeamVectorApplyPivotMatrixForwardInternal::invoke(member, n, piv, A.data(), as0, as1); |
| 45 |
} |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
template <typename PivViewType, typename AViewType> |
| 50 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const PivViewType piv, const AViewType &A) { |
| 51 |
if (AViewType::rank == 1) { |
| 52 |
const int plen = piv.extent(0), ps0 = piv.stride(0), as0 = A.stride(0); |
| 53 |
TeamVectorApplyPivotVectorForwardInternal::invoke(member, plen, piv.data(), ps0, A.data(), as0); |
| 54 |
} else if (AViewType::rank == 2) { |
| 55 |
// row permutation |
| 56 |
const int plen = piv.extent(0), ps0 = piv.stride(0), n = A.extent(1), as0 = A.stride(0), as1 = A.stride(1); |
| 57 |
TeamVectorApplyPivotMatrixForwardInternal::invoke(member, n, plen, piv.data(), ps0, A.data(), as0, as1); |
| 58 |
} |
| 59 |
return 0; |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
/// column swap |
| 64 |
template <typename MemberType> |
| 65 |
struct TeamVectorApplyPivot<MemberType, Side::Right, Direct::Forward> { |
| 66 |
template <typename AViewType> |
| 67 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int piv, const AViewType &A) { |
| 68 |
if (AViewType::rank == 1) { |
| 69 |
const int as0 = A.stride(0); |
| 70 |
TeamVectorApplyPivotVectorForwardInternal::invoke(member, piv, A.data(), as0); |
| 71 |
} else if (AViewType::rank == 2) { |
| 72 |
const int m = A.extent(0), as0 = A.stride(0), as1 = A.stride(1); |
| 73 |
TeamVectorApplyPivotMatrixForwardInternal::invoke(member, m, piv, A.data(), as1, as0); |
| 74 |
} |
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
template <typename PivViewType, typename AViewType> |
| 79 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const PivViewType &piv, const AViewType &A) { |
| 80 |
if (AViewType::rank == 1) { |
| 81 |
const int plen = piv.extent(0), as0 = A.stride(0); |
| 82 |
TeamVectorApplyPivotVectorForwardInternal ::invoke(member, plen, piv.data(), A.data(), as0); |
| 83 |
} else if (AViewType::rank == 2) { |
| 84 |
// column permutation |
| 85 |
const int plen = piv.extent(0), ps = piv.stride(0), m = A.extent(0), as0 = A.stride(0), as1 = A.stride(1); |
| 86 |
TeamVectorApplyPivotMatrixForwardInternal ::invoke(member, m, plen, piv.data(), ps, A.data(), as1, as0); |
| 87 |
} |
| 88 |
return 0; |
| 89 |
} |
| 90 |
}; |
| 91 |
|
| 92 |
/// |
| 93 |
/// Backward pivot apply |
| 94 |
/// |
| 95 |
|
| 96 |
/// row swap |
| 97 |
template <typename MemberType> |
| 98 |
struct TeamVectorApplyPivot<MemberType, Side::Left, Direct::Backward> { |
| 99 |
template <typename AViewType> |
| 100 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int piv, const AViewType &A) { |
| 101 |
if (AViewType::rank == 1) { |
| 102 |
const int as0 = A.stride(0); |
| 103 |
TeamVectorApplyPivotVectorBackwardInternal::invoke(member, piv, A.data(), as0); |
| 104 |
} else if (AViewType::rank == 2) { |
| 105 |
const int n = A.extent(1), as0 = A.stride(0), as1 = A.stride(1); |
| 106 |
TeamVectorApplyPivotMatrixBackwardInternal::invoke(member, n, piv, A.data(), as0, as1); |
| 107 |
} |
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
template <typename PivViewType, typename AViewType> |
| 112 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const PivViewType piv, const AViewType &A) { |
| 113 |
if (AViewType::rank == 1) { |
| 114 |
const int plen = piv.extent(0), ps0 = piv.stride(0), as0 = A.stride(0); |
| 115 |
TeamVectorApplyPivotVectorBackwardInternal::invoke(member, plen, piv.data(), ps0, A.data(), as0); |
| 116 |
} else if (AViewType::rank == 2) { |
| 117 |
// row permutation |
| 118 |
const int plen = piv.extent(0), ps0 = piv.stride(0), n = A.extent(1), as0 = A.stride(0), as1 = A.stride(1); |
| 119 |
TeamVectorApplyPivotMatrixBackwardInternal::invoke(member, n, plen, piv.data(), ps0, A.data(), as0, as1); |
| 120 |
} |
| 121 |
return 0; |
| 122 |
} |
| 123 |
}; |
| 124 |
|
| 125 |
/// column swap |
| 126 |
template <typename MemberType> |
| 127 |
struct TeamVectorApplyPivot<MemberType, Side::Right, Direct::Backward> { |
| 128 |
template <typename AViewType> |
| 129 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int piv, const AViewType &A) { |
| 130 |
if (AViewType::rank == 1) { |
| 131 |
const int as0 = A.stride(0); |
| 132 |
TeamVectorApplyPivotVectorBackwardInternal::invoke(member, piv, A.data(), as0); |
| 133 |
} else if (AViewType::rank == 2) { |
| 134 |
const int m = A.extent(0), as0 = A.stride(0), as1 = A.stride(1); |
| 135 |
TeamVectorApplyPivotMatrixBackwardInternal::invoke(member, m, piv, A.data(), as1, as0); |
| 136 |
} |
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
template <typename PivViewType, typename AViewType> |
| 141 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const PivViewType &piv, const AViewType &A) { |
| 142 |
if (AViewType::rank == 1) { |
| 143 |
const int plen = piv.extent(0), as0 = A.stride(0); |
| 144 |
TeamVectorApplyPivotVectorBackwardInternal ::invoke(member, plen, piv.data(), A.data(), as0); |
| 145 |
} else if (AViewType::rank == 2) { |
| 146 |
// column permutation |
| 147 |
const int plen = piv.extent(0), ps = piv.stride(0), m = A.extent(0), as0 = A.stride(0), as1 = A.stride(1); |
| 148 |
TeamVectorApplyPivotMatrixBackwardInternal ::invoke(member, m, plen, piv.data(), ps, A.data(), as1, as0); |
| 149 |
} |
| 150 |
return 0; |
| 151 |
} |
| 152 |
}; |
| 153 |
|
| 154 |
} // namespace KokkosBatched |
| 155 |
|
| 156 |
#endif |