| 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_IMPL_HPP_ |
| 17 |
#define KOKKOSBATCHED_PTTRS_SERIAL_IMPL_HPP_ |
| 18 |
|
| 19 |
#include <KokkosBatched_Util.hpp> |
| 20 |
#include <KokkosBlas1_scal.hpp> |
| 21 |
#include "KokkosBatched_Pttrs_Serial_Internal.hpp" |
| 22 |
|
| 23 |
/// \author Yuuichi Asahi ([email protected]) |
| 24 |
|
| 25 |
namespace KokkosBatched { |
| 26 |
|
| 27 |
template <typename DViewType, typename EViewType, typename BViewType> |
| 28 |
KOKKOS_INLINE_FUNCTION static int checkPttrsInput([[maybe_unused]] const DViewType &d, |
| 29 |
[[maybe_unused]] const EViewType &e, |
| 30 |
[[maybe_unused]] const BViewType &b) { |
| 31 |
static_assert(Kokkos::is_view_v<DViewType>, "KokkosBatched::pttrs: DViewType is not a Kokkos::View."); |
| 32 |
static_assert(Kokkos::is_view_v<EViewType>, "KokkosBatched::pttrs: EViewType is not a Kokkos::View."); |
| 33 |
static_assert(Kokkos::is_view_v<BViewType>, "KokkosBatched::pttrs: BViewType is not a Kokkos::View."); |
| 34 |
|
| 35 |
static_assert(DViewType::rank == 1, "KokkosBatched::pttrs: DViewType must have rank 1."); |
| 36 |
static_assert(EViewType::rank == 1, "KokkosBatched::pttrs: EViewType must have rank 1."); |
| 37 |
static_assert(BViewType::rank == 1, "KokkosBatched::pttrs: BViewType must have rank 1."); |
| 38 |
|
| 39 |
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0) |
| 40 |
const int nd = d.extent(0); |
| 41 |
const int ne = e.extent(0); |
| 42 |
const int ldb = b.extent(0); |
| 43 |
|
| 44 |
if (ne + 1 != nd) { |
| 45 |
Kokkos::printf( |
| 46 |
"KokkosBatched::pttrs: Dimensions of d and e do not match: d: %d, e: " |
| 47 |
"%d \n" |
| 48 |
"e.extent(0) must be equal to d.extent(0) - 1\n", |
| 49 |
nd, ne); |
| 50 |
return 1; |
| 51 |
} |
| 52 |
|
| 53 |
if (ldb < Kokkos::max(1, nd)) { |
| 54 |
Kokkos::printf( |
| 55 |
"KokkosBatched::pttrs: Dimensions of d and b do not match: d: %d, b: " |
| 56 |
"%d \n" |
| 57 |
"b.extent(0) must be larger or equal to d.extent(0) \n", |
| 58 |
ldb, nd); |
| 59 |
return 1; |
| 60 |
} |
| 61 |
#endif |
| 62 |
return 0; |
| 63 |
} |
| 64 |
|
| 65 |
template <typename ArgUplo> |
| 66 |
struct SerialPttrs<ArgUplo, Algo::Pttrs::Unblocked> { |
| 67 |
template <typename DViewType, typename EViewType, typename BViewType> |
| 68 |
KOKKOS_INLINE_FUNCTION static int invoke(const DViewType &d, const EViewType &e, const BViewType &b) { |
| 69 |
// Quick return if possible |
| 70 |
if (d.extent(0) == 0) return 0; |
| 71 |
|
| 72 |
auto info = checkPttrsInput(d, e, b); |
| 73 |
if (info) return info; |
| 74 |
|
| 75 |
using ScalarType = typename DViewType::non_const_value_type; |
| 76 |
int n = d.extent(0); |
| 77 |
|
| 78 |
if (n == 1) { |
| 79 |
const ScalarType alpha = 1.0 / d(0); |
| 80 |
return KokkosBlas::SerialScale::invoke(alpha, b); |
| 81 |
} |
| 82 |
|
| 83 |
// Solve A * X = B using the factorization A = L*D*L**T, |
| 84 |
// overwriting each right hand side vector with its solution. |
| 85 |
return SerialPttrsInternal<ArgUplo, Algo::Pttrs::Unblocked>::invoke(n, d.data(), d.stride(0), e.data(), e.stride(0), |
| 86 |
b.data(), b.stride(0)); |
| 87 |
} |
| 88 |
}; |
| 89 |
} // namespace KokkosBatched |
| 90 |
|
| 91 |
#endif // KOKKOSBATCHED_PTTRS_SERIAL_IMPL_HPP_ |