| 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_PBTRS_SERIAL_IMPL_HPP_ |
| 17 |
#define KOKKOSBATCHED_PBTRS_SERIAL_IMPL_HPP_ |
| 18 |
|
| 19 |
#include <KokkosBatched_Util.hpp> |
| 20 |
#include "KokkosBatched_Pbtrs_Serial_Internal.hpp" |
| 21 |
|
| 22 |
/// \author Yuuichi Asahi ([email protected]) |
| 23 |
|
| 24 |
namespace KokkosBatched { |
| 25 |
namespace Impl { |
| 26 |
|
| 27 |
template <typename AViewType, typename XViewType> |
| 28 |
KOKKOS_INLINE_FUNCTION static int checkPbtrsInput([[maybe_unused]] const AViewType &A, |
| 29 |
[[maybe_unused]] const XViewType &x) { |
| 30 |
static_assert(Kokkos::is_view_v<AViewType>, "KokkosBatched::pbtrs: AViewType is not a Kokkos::View."); |
| 31 |
static_assert(Kokkos::is_view_v<XViewType>, "KokkosBatched::pbtrs: XViewType is not a Kokkos::View."); |
| 32 |
static_assert(AViewType::rank == 2, "KokkosBatched::pbtrs: AViewType must have rank 2."); |
| 33 |
static_assert(XViewType::rank == 1, "KokkosBatched::pbtrs: XViewType must have rank 1."); |
| 34 |
|
| 35 |
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0) |
| 36 |
const int ldb = x.extent(0); |
| 37 |
const int lda = A.extent(0), n = A.extent(1); |
| 38 |
const int kd = lda - 1; |
| 39 |
if (kd < 0) { |
| 40 |
Kokkos::printf( |
| 41 |
"KokkosBatched::pbtrs: leading dimension of A must not be less than 1: %d, A: " |
| 42 |
"%d " |
| 43 |
"x %d \n", |
| 44 |
lda, n); |
| 45 |
return 1; |
| 46 |
} |
| 47 |
if (ldb < Kokkos::max(1, n)) { |
| 48 |
Kokkos::printf( |
| 49 |
"KokkosBatched::pbtrs: Dimensions of x and A do not match: x: %d, A: " |
| 50 |
"%d " |
| 51 |
"x %d \n" |
| 52 |
"x.extent(0) must be larger or equal to A.extent(1) \n", |
| 53 |
ldb, lda, n); |
| 54 |
return 1; |
| 55 |
} |
| 56 |
#endif |
| 57 |
return 0; |
| 58 |
} |
| 59 |
} // namespace Impl |
| 60 |
|
| 61 |
//// Lower //// |
| 62 |
template <> |
| 63 |
struct SerialPbtrs<Uplo::Lower, Algo::Pbtrs::Unblocked> { |
| 64 |
template <typename AViewType, typename XViewType> |
| 65 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const XViewType &x) { |
| 66 |
// Quick return if possible |
| 67 |
if (A.extent(1) == 0) return 0; |
| 68 |
auto info = KokkosBatched::Impl::checkPbtrsInput(A, x); |
| 69 |
if (info) return info; |
| 70 |
|
| 71 |
const int kd = A.extent(0) - 1; |
| 72 |
return KokkosBatched::Impl::SerialPbtrsInternalLower<Algo::Pbtrs::Unblocked>::invoke( |
| 73 |
A.extent(1), A.data(), A.stride_0(), A.stride_1(), x.data(), x.stride_0(), kd); |
| 74 |
} |
| 75 |
}; |
| 76 |
|
| 77 |
//// Upper //// |
| 78 |
template <> |
| 79 |
struct SerialPbtrs<Uplo::Upper, Algo::Pbtrs::Unblocked> { |
| 80 |
template <typename AViewType, typename XViewType> |
| 81 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const XViewType &x) { |
| 82 |
// Quick return if possible |
| 83 |
if (A.extent(1) == 0) return 0; |
| 84 |
auto info = KokkosBatched::Impl::checkPbtrsInput(A, x); |
| 85 |
if (info) return info; |
| 86 |
|
| 87 |
const int kd = A.extent(0) - 1; |
| 88 |
return KokkosBatched::Impl::SerialPbtrsInternalUpper<Algo::Pbtrs::Unblocked>::invoke( |
| 89 |
A.extent(1), A.data(), A.stride_0(), A.stride_1(), x.data(), x.stride_0(), kd); |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
} // namespace KokkosBatched |
| 94 |
|
| 95 |
#endif // KOKKOSBATCHED_PBTRS_SERIAL_IMPL_HPP_ |