| 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 |
|
| 17 |
#ifndef KOKKOSBATCHED_TBSV_SERIAL_IMPL_HPP_ |
| 18 |
#define KOKKOSBATCHED_TBSV_SERIAL_IMPL_HPP_ |
| 19 |
|
| 20 |
/// \author Yuuichi Asahi ([email protected]) |
| 21 |
|
| 22 |
#include "KokkosBatched_Util.hpp" |
| 23 |
#include "KokkosBatched_Tbsv_Serial_Internal.hpp" |
| 24 |
|
| 25 |
namespace KokkosBatched { |
| 26 |
|
| 27 |
template <typename AViewType, typename XViewType> |
| 28 |
KOKKOS_INLINE_FUNCTION static int checkTbsvInput([[maybe_unused]] const AViewType &A, |
| 29 |
[[maybe_unused]] const XViewType &x, [[maybe_unused]] const int k) { |
| 30 |
static_assert(Kokkos::is_view<AViewType>::value, "KokkosBatched::tbsv: AViewType is not a Kokkos::View."); |
| 31 |
static_assert(Kokkos::is_view<XViewType>::value, "KokkosBatched::tbsv: XViewType is not a Kokkos::View."); |
| 32 |
static_assert(AViewType::rank == 2, "KokkosBatched::tbsv: AViewType must have rank 2."); |
| 33 |
static_assert(XViewType::rank == 1, "KokkosBatched::tbsv: XViewType must have rank 1."); |
| 34 |
|
| 35 |
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0) |
| 36 |
if (k < 0) { |
| 37 |
Kokkos::printf( |
| 38 |
"KokkosBatched::tbsv: input parameter k must not be less than 0: k = " |
| 39 |
"%d\n", |
| 40 |
k); |
| 41 |
return 1; |
| 42 |
} |
| 43 |
|
| 44 |
const int lda = A.extent(0), n = A.extent(1); |
| 45 |
if (lda < (k + 1)) { |
| 46 |
Kokkos::printf( |
| 47 |
"KokkosBatched::tbsv: leading dimension of A must be smaller than k+1: " |
| 48 |
"lda = %d, k = %d\n", |
| 49 |
lda, k); |
| 50 |
return 1; |
| 51 |
} |
| 52 |
|
| 53 |
const int nx = x.extent(0); |
| 54 |
if (nx != n) { |
| 55 |
Kokkos::printf( |
| 56 |
"KokkosBatched::tbsv: Dimensions of x and A do not match: X: %d, A: %d " |
| 57 |
"x %d\n" |
| 58 |
"x.extent(0) must be equal to A.extent(1)\n", |
| 59 |
nx, lda, n); |
| 60 |
return 1; |
| 61 |
} |
| 62 |
#endif |
| 63 |
return 0; |
| 64 |
} |
| 65 |
|
| 66 |
//// Lower non-transpose //// |
| 67 |
template <typename ArgDiag> |
| 68 |
struct SerialTbsv<Uplo::Lower, Trans::NoTranspose, ArgDiag, Algo::Tbsv::Unblocked> { |
| 69 |
template <typename AViewType, typename XViewType> |
| 70 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const XViewType &x, const int k) { |
| 71 |
auto info = checkTbsvInput(A, x, k); |
| 72 |
if (info) return info; |
| 73 |
|
| 74 |
return SerialTbsvInternalLower<Algo::Tbsv::Unblocked>::invoke( |
| 75 |
ArgDiag::use_unit_diag, A.extent(1), A.data(), A.stride_0(), A.stride_1(), x.data(), x.stride_0(), k); |
| 76 |
} |
| 77 |
}; |
| 78 |
|
| 79 |
//// Lower transpose //// |
| 80 |
template <typename ArgDiag> |
| 81 |
struct SerialTbsv<Uplo::Lower, Trans::Transpose, ArgDiag, Algo::Tbsv::Unblocked> { |
| 82 |
template <typename AViewType, typename XViewType> |
| 83 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const XViewType &x, const int k) { |
| 84 |
auto info = checkTbsvInput(A, x, k); |
| 85 |
if (info) return info; |
| 86 |
|
| 87 |
return SerialTbsvInternalLowerTranspose<Algo::Tbsv::Unblocked>::invoke( |
| 88 |
ArgDiag::use_unit_diag, false, A.extent(1), A.data(), A.stride_0(), A.stride_1(), x.data(), x.stride_0(), k); |
| 89 |
} |
| 90 |
}; |
| 91 |
|
| 92 |
//// Lower conjugate-transpose //// |
| 93 |
template <typename ArgDiag> |
| 94 |
struct SerialTbsv<Uplo::Lower, Trans::ConjTranspose, ArgDiag, Algo::Tbsv::Unblocked> { |
| 95 |
template <typename AViewType, typename XViewType> |
| 96 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const XViewType &x, const int k) { |
| 97 |
auto info = checkTbsvInput(A, x, k); |
| 98 |
if (info) return info; |
| 99 |
|
| 100 |
return SerialTbsvInternalLowerTranspose<Algo::Tbsv::Unblocked>::invoke( |
| 101 |
ArgDiag::use_unit_diag, true, A.extent(1), A.data(), A.stride_0(), A.stride_1(), x.data(), x.stride_0(), k); |
| 102 |
} |
| 103 |
}; |
| 104 |
|
| 105 |
//// Upper non-transpose //// |
| 106 |
template <typename ArgDiag> |
| 107 |
struct SerialTbsv<Uplo::Upper, Trans::NoTranspose, ArgDiag, Algo::Tbsv::Unblocked> { |
| 108 |
template <typename AViewType, typename XViewType> |
| 109 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const XViewType &x, const int k) { |
| 110 |
auto info = checkTbsvInput(A, x, k); |
| 111 |
if (info) return info; |
| 112 |
|
| 113 |
return SerialTbsvInternalUpper<Algo::Tbsv::Unblocked>::invoke( |
| 114 |
ArgDiag::use_unit_diag, A.extent(1), A.data(), A.stride_0(), A.stride_1(), x.data(), x.stride_0(), k); |
| 115 |
} |
| 116 |
}; |
| 117 |
|
| 118 |
//// Upper transpose //// |
| 119 |
template <typename ArgDiag> |
| 120 |
struct SerialTbsv<Uplo::Upper, Trans::Transpose, ArgDiag, Algo::Tbsv::Unblocked> { |
| 121 |
template <typename AViewType, typename XViewType> |
| 122 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const XViewType &x, const int k) { |
| 123 |
auto info = checkTbsvInput(A, x, k); |
| 124 |
if (info) return info; |
| 125 |
|
| 126 |
return SerialTbsvInternalUpperTranspose<Algo::Tbsv::Unblocked>::invoke( |
| 127 |
ArgDiag::use_unit_diag, false, A.extent(1), A.data(), A.stride_0(), A.stride_1(), x.data(), x.stride_0(), k); |
| 128 |
} |
| 129 |
}; |
| 130 |
|
| 131 |
//// Upper conjugate-transpose //// |
| 132 |
template <typename ArgDiag> |
| 133 |
struct SerialTbsv<Uplo::Upper, Trans::ConjTranspose, ArgDiag, Algo::Tbsv::Unblocked> { |
| 134 |
template <typename AViewType, typename XViewType> |
| 135 |
KOKKOS_INLINE_FUNCTION static int invoke(const AViewType &A, const XViewType &x, const int k) { |
| 136 |
auto info = checkTbsvInput(A, x, k); |
| 137 |
if (info) return info; |
| 138 |
|
| 139 |
return SerialTbsvInternalUpperTranspose<Algo::Tbsv::Unblocked>::invoke( |
| 140 |
ArgDiag::use_unit_diag, true, A.extent(1), A.data(), A.stride_0(), A.stride_1(), x.data(), x.stride_0(), k); |
| 141 |
} |
| 142 |
}; |
| 143 |
|
| 144 |
} // namespace KokkosBatched |
| 145 |
|
| 146 |
#endif // KOKKOSBATCHED_TBSV_SERIAL_IMPL_HPP_ |