| 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_PTTRF_SERIAL_IMPL_HPP_ |
| 17 |
#define KOKKOSBATCHED_PTTRF_SERIAL_IMPL_HPP_ |
| 18 |
|
| 19 |
#include <KokkosBatched_Util.hpp> |
| 20 |
#include "KokkosBatched_Pttrf_Serial_Internal.hpp" |
| 21 |
|
| 22 |
/// \author Yuuichi Asahi ([email protected]) |
| 23 |
|
| 24 |
namespace KokkosBatched { |
| 25 |
|
| 26 |
template <typename DViewType, typename EViewType> |
| 27 |
KOKKOS_INLINE_FUNCTION static int checkPttrfInput([[maybe_unused]] const DViewType &d, |
| 28 |
[[maybe_unused]] const EViewType &e) { |
| 29 |
static_assert(Kokkos::is_view<DViewType>::value, "KokkosBatched::pttrf: DViewType is not a Kokkos::View."); |
| 30 |
static_assert(Kokkos::is_view<EViewType>::value, "KokkosBatched::pttrf: EViewType is not a Kokkos::View."); |
| 31 |
|
| 32 |
static_assert(DViewType::rank == 1, "KokkosBatched::pttrf: DViewType must have rank 1."); |
| 33 |
static_assert(EViewType::rank == 1, "KokkosBatched::pttrf: EViewType must have rank 1."); |
| 34 |
|
| 35 |
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0) |
| 36 |
const int nd = d.extent(0); |
| 37 |
const int ne = e.extent(0); |
| 38 |
|
| 39 |
if (ne + 1 != nd) { |
| 40 |
Kokkos::printf( |
| 41 |
"KokkosBatched::pttrf: Dimensions of d and e do not match: d: %d, e: " |
| 42 |
"%d \n" |
| 43 |
"e.extent(0) must be equal to d.extent(0) - 1\n", |
| 44 |
nd, ne); |
| 45 |
return 1; |
| 46 |
} |
| 47 |
#endif |
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
template <> |
| 52 |
struct SerialPttrf<Algo::Pttrf::Unblocked> { |
| 53 |
template <typename DViewType, typename EViewType> |
| 54 |
KOKKOS_INLINE_FUNCTION static int invoke(const DViewType &d, const EViewType &e) { |
| 55 |
// Quick return if possible |
| 56 |
if (d.extent(0) == 0) return 0; |
| 57 |
if (d.extent(0) == 1) return (d(0) < 0 ? 1 : 0); |
| 58 |
|
| 59 |
auto info = checkPttrfInput(d, e); |
| 60 |
if (info) return info; |
| 61 |
|
| 62 |
return SerialPttrfInternal<Algo::Pttrf::Unblocked>::invoke(d.extent(0), d.data(), d.stride(0), e.data(), |
| 63 |
e.stride(0)); |
| 64 |
} |
| 65 |
}; |
| 66 |
} // namespace KokkosBatched |
| 67 |
|
| 68 |
#endif // KOKKOSBATCHED_PTTRF_SERIAL_IMPL_HPP_ |