| 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_SOLVELU_DECL_HPP |
| 17 |
#define KOKKOSBATCHED_SOLVELU_DECL_HPP |
| 18 |
|
| 19 |
/// \author Vinh Dang ([email protected]) |
| 20 |
|
| 21 |
#include "KokkosBatched_Util.hpp" |
| 22 |
#include "KokkosBatched_Vector.hpp" |
| 23 |
#include "KokkosBatched_Trsm_Decl.hpp" |
| 24 |
#include "KokkosBatched_Trsm_Serial_Impl.hpp" |
| 25 |
#include "KokkosBatched_Trsm_Team_Impl.hpp" |
| 26 |
|
| 27 |
namespace KokkosBatched { |
| 28 |
|
| 29 |
template <typename ArgTrans, typename ArgAlgo> |
| 30 |
struct SerialSolveLU { |
| 31 |
// no piv version |
| 32 |
template <typename AViewType, typename BViewType> |
| 33 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const BViewType &B) { |
| 34 |
int r_val[2] = {}; |
| 35 |
const typename AViewType::non_const_value_type one(1.0); |
| 36 |
if (std::is_same<ArgTrans, Trans::NoTranspose>::value) { |
| 37 |
// First, compute Y (= U*X) by solving the system L*Y = B for Y |
| 38 |
r_val[0] = SerialTrsm<Side::Left, Uplo::Lower, ArgTrans, Diag::Unit, ArgAlgo>::invoke(one, A, B); |
| 39 |
// Second, compute X by solving the system U*X = Y for X |
| 40 |
r_val[1] = SerialTrsm<Side::Left, Uplo::Upper, ArgTrans, Diag::NonUnit, ArgAlgo>::invoke(one, A, B); |
| 41 |
} else if (std::is_same<ArgTrans, Trans::Transpose>::value || std::is_same<ArgTrans, Trans::ConjTranspose>::value) { |
| 42 |
// First, compute Y (= L'*X) by solving the system U'*Y = B for Y |
| 43 |
r_val[0] = SerialTrsm<Side::Left, Uplo::Upper, ArgTrans, Diag::NonUnit, ArgAlgo>::invoke(one, A, B); |
| 44 |
// Second, compute X by solving the system L'*X = Y for X |
| 45 |
r_val[1] = SerialTrsm<Side::Left, Uplo::Lower, ArgTrans, Diag::Unit, ArgAlgo>::invoke(one, A, B); |
| 46 |
} |
| 47 |
return r_val[0] + r_val[1]; |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
template <typename MemberType, typename ArgTrans, typename ArgAlgo> |
| 52 |
struct TeamSolveLU { |
| 53 |
// no piv version |
| 54 |
template <typename AViewType, typename BViewType> |
| 55 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const AViewType &A, const BViewType &B) { |
| 56 |
int r_val[2] = {}; |
| 57 |
const typename AViewType::non_const_value_type one(1.0); |
| 58 |
if (std::is_same<ArgTrans, Trans::NoTranspose>::value) { |
| 59 |
// First, compute Y (= U*X) by solving the system L*Y = B for Y |
| 60 |
r_val[0] = |
| 61 |
TeamTrsm<MemberType, Side::Left, Uplo::Lower, ArgTrans, Diag::Unit, ArgAlgo>::invoke(member, one, A, B); |
| 62 |
// Second, compute X by solving the system U*X = Y for X |
| 63 |
r_val[1] = |
| 64 |
TeamTrsm<MemberType, Side::Left, Uplo::Upper, ArgTrans, Diag::NonUnit, ArgAlgo>::invoke(member, one, A, B); |
| 65 |
} else if (std::is_same<ArgTrans, Trans::Transpose>::value || std::is_same<ArgTrans, Trans::ConjTranspose>::value) { |
| 66 |
// First, compute Y (= L'*X) by solving the system U'*Y = B for Y |
| 67 |
r_val[0] = |
| 68 |
TeamTrsm<MemberType, Side::Left, Uplo::Upper, ArgTrans, Diag::NonUnit, ArgAlgo>::invoke(member, one, A, B); |
| 69 |
// Second, compute X by solving the system L'*X = Y for X |
| 70 |
r_val[1] = |
| 71 |
TeamTrsm<MemberType, Side::Left, Uplo::Lower, ArgTrans, Diag::Unit, ArgAlgo>::invoke(member, one, A, B); |
| 72 |
} |
| 73 |
return r_val[0] + r_val[1]; |
| 74 |
} |
| 75 |
}; |
| 76 |
|
| 77 |
/// |
| 78 |
/// Selective Interface |
| 79 |
/// |
| 80 |
template <typename MemberType, typename ArgTrans, typename ArgMode, typename ArgAlgo> |
| 81 |
struct SolveLU { |
| 82 |
// no piv version |
| 83 |
template <typename AViewType, typename BViewType> |
| 84 |
KOKKOS_FORCEINLINE_FUNCTION static int invoke(const MemberType &member, const AViewType &A, const BViewType &B) { |
| 85 |
int r_val = 0; |
| 86 |
if (std::is_same<ArgMode, Mode::Serial>::value) { |
| 87 |
r_val = SerialSolveLU<ArgTrans, ArgAlgo>::invoke(A, B); |
| 88 |
} else if (std::is_same<ArgMode, Mode::Team>::value) { |
| 89 |
r_val = TeamSolveLU<MemberType, ArgTrans, ArgAlgo>::invoke(member, A, B); |
| 90 |
} |
| 91 |
return r_val; |
| 92 |
} |
| 93 |
}; |
| 94 |
|
| 95 |
} // namespace KokkosBatched |
| 96 |
|
| 97 |
#endif |