| 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_PTTRS_SERIAL_INTERNAL_HPP_ |
| 17 |
#define KOKKOSBATCHED_PTTRS_SERIAL_INTERNAL_HPP_ |
| 18 |
|
| 19 |
#include <KokkosBatched_Util.hpp> |
| 20 |
|
| 21 |
/// \author Yuuichi Asahi ([email protected]) |
| 22 |
|
| 23 |
namespace KokkosBatched { |
| 24 |
|
| 25 |
template <typename ArgUplo, typename AlgoType> |
| 26 |
struct SerialPttrsInternal { |
| 27 |
template <typename ValueType> |
| 28 |
KOKKOS_INLINE_FUNCTION static int invoke(const int n, const ValueType *KOKKOS_RESTRICT d, const int ds0, |
| 29 |
const ValueType *KOKKOS_RESTRICT e, const int es0, |
| 30 |
ValueType *KOKKOS_RESTRICT b, const int bs0); |
| 31 |
|
| 32 |
template <typename ValueType> |
| 33 |
KOKKOS_INLINE_FUNCTION static int invoke(const int n, const ValueType *KOKKOS_RESTRICT d, const int ds0, |
| 34 |
const Kokkos::complex<ValueType> *KOKKOS_RESTRICT e, const int es0, |
| 35 |
Kokkos::complex<ValueType> *KOKKOS_RESTRICT b, const int bs0); |
| 36 |
}; |
| 37 |
|
| 38 |
/// |
| 39 |
/// Real matrix |
| 40 |
/// |
| 41 |
|
| 42 |
template <typename ArgUplo, typename AlgoType> |
| 43 |
template <typename ValueType> |
| 44 |
KOKKOS_INLINE_FUNCTION int SerialPttrsInternal<ArgUplo, AlgoType>::invoke( |
| 45 |
const int n, const ValueType *KOKKOS_RESTRICT d, const int ds0, const ValueType *KOKKOS_RESTRICT e, const int es0, |
| 46 |
ValueType *KOKKOS_RESTRICT b, const int bs0) { |
| 47 |
// Solve A * X = B using the factorization L * D * L**T |
| 48 |
for (int i = 1; i < n; i++) { |
| 49 |
b[i * bs0] -= e[(i - 1) * es0] * b[(i - 1) * bs0]; |
| 50 |
} |
| 51 |
|
| 52 |
b[(n - 1) * bs0] /= d[(n - 1) * ds0]; |
| 53 |
|
| 54 |
for (int i = n - 2; i >= 0; i--) { |
| 55 |
b[i * bs0] = b[i * bs0] / d[i * ds0] - b[(i + 1) * bs0] * e[i * es0]; |
| 56 |
} |
| 57 |
|
| 58 |
return 0; |
| 59 |
} |
| 60 |
|
| 61 |
/// |
| 62 |
/// Complex matrix |
| 63 |
/// |
| 64 |
|
| 65 |
template <typename ArgUplo, typename AlgoType> |
| 66 |
template <typename ValueType> |
| 67 |
KOKKOS_INLINE_FUNCTION int SerialPttrsInternal<ArgUplo, AlgoType>::invoke( |
| 68 |
const int n, const ValueType *KOKKOS_RESTRICT d, const int ds0, const Kokkos::complex<ValueType> *KOKKOS_RESTRICT e, |
| 69 |
const int es0, Kokkos::complex<ValueType> *KOKKOS_RESTRICT b, const int bs0) { |
| 70 |
// Solve A * X = B using the factorization L * D * L**H |
| 71 |
for (int i = 1; i < n; i++) { |
| 72 |
auto tmp_e = std::is_same_v<ArgUplo, Uplo::Upper> ? Kokkos::conj(e[(i - 1) * es0]) : e[(i - 1) * es0]; |
| 73 |
b[i * bs0] -= tmp_e * b[(i - 1) * bs0]; |
| 74 |
} |
| 75 |
|
| 76 |
b[(n - 1) * bs0] /= d[(n - 1) * ds0]; |
| 77 |
|
| 78 |
for (int i = n - 2; i >= 0; i--) { |
| 79 |
auto tmp_e = std::is_same_v<ArgUplo, Uplo::Lower> ? Kokkos::conj(e[i * es0]) : e[i * es0]; |
| 80 |
b[i * bs0] = b[i * bs0] / d[i * ds0] - b[(i + 1) * bs0] * tmp_e; |
| 81 |
} |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |
| 85 |
|
| 86 |
} // namespace KokkosBatched |
| 87 |
|
| 88 |
#endif // KOKKOSBATCHED_PTTRS_SERIAL_INTERNAL_HPP_ |