Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_Laswp_Serial_Impl.hpp

raw
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_LASWP_SERIAL_IMPL_HPP_
18 #define KOKKOSBATCHED_LASWP_SERIAL_IMPL_HPP_
19
20 #include "KokkosBatched_Util.hpp"
21 #include "KokkosBatched_Laswp_Serial_Internal.hpp"
22
23 /// \author Yuuichi Asahi ([email protected])
24
25 namespace KokkosBatched {
26 namespace Impl {
27
28 template <typename PivViewType, typename AViewType>
29 KOKKOS_INLINE_FUNCTION static int checkLaswpInput(const PivViewType &piv, const AViewType &A) {
30 static_assert(Kokkos::is_view_v<PivViewType>, "KokkosBatched::laswp: PivViewType is not a Kokkos::View.");
31 static_assert(Kokkos::is_view_v<AViewType>, "KokkosBatched::laswp: AViewType is not a Kokkos::View.");
32 static_assert(AViewType::rank == 1 || AViewType::rank == 2, "KokkosBatched::laswp: AViewType must have rank 1 or 2.");
33 static_assert(PivViewType::rank == 1, "KokkosBatched::laswp: PivViewType must have rank 1.");
34
35 #if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
36 const int npiv = piv.extent(0);
37 const int lda = A.extent(0);
38 if (npiv > lda) {
39 Kokkos::printf(
40 "KokkosBatched::laswp: the dimension of the ipiv array must "
41 "satisfy ipiv.extent(0) <= A.extent(0): ipiv: %d, A: "
42 "%d \n",
43 npiv, lda);
44 return 1;
45 }
46 #endif
47 return 0;
48 }
49 } // namespace Impl
50
51 ///
52 /// Serial Internal Impl
53 /// ========================
54
55 ///
56 //// Forward pivot apply
57 ///
58
59 template <>
60 struct SerialLaswp<Direct::Forward> {
61 template <typename PivViewType, typename AViewType>
62 KOKKOS_INLINE_FUNCTION static int invoke(const PivViewType &piv, const AViewType &A) {
63 auto info = KokkosBatched::Impl::checkLaswpInput(piv, A);
64 if (info) return info;
65
66 if constexpr (AViewType::rank == 1) {
67 const int plen = piv.extent(0), ps0 = piv.stride(0), as0 = A.stride(0);
68 return KokkosBatched::Impl::SerialLaswpVectorForwardInternal::invoke(plen, piv.data(), ps0, A.data(), as0);
69 } else if constexpr (AViewType::rank == 2) {
70 // row permutation
71 const int plen = piv.extent(0), ps0 = piv.stride(0), n = A.extent(1), as0 = A.stride(0), as1 = A.stride(1);
72 return KokkosBatched::Impl::SerialLaswpMatrixForwardInternal::invoke(n, plen, piv.data(), ps0, A.data(), as0,
73 as1);
74 }
75 return 0;
76 }
77 };
78
79 ///
80 /// Backward pivot apply
81 ///
82
83 template <>
84 struct SerialLaswp<Direct::Backward> {
85 template <typename PivViewType, typename AViewType>
86 KOKKOS_INLINE_FUNCTION static int invoke(const PivViewType piv, const AViewType &A) {
87 auto info = KokkosBatched::Impl::checkLaswpInput(piv, A);
88 if (info) return info;
89
90 if constexpr (AViewType::rank == 1) {
91 const int plen = piv.extent(0), ps0 = piv.stride(0), as0 = A.stride(0);
92 return KokkosBatched::Impl::SerialLaswpVectorBackwardInternal::invoke(plen, piv.data(), ps0, A.data(), as0);
93 } else if constexpr (AViewType::rank == 2) {
94 // row permutation
95 const int plen = piv.extent(0), ps0 = piv.stride(0), n = A.extent(1), as0 = A.stride(0), as1 = A.stride(1);
96 return KokkosBatched::Impl::SerialLaswpMatrixBackwardInternal::invoke(n, plen, piv.data(), ps0, A.data(), as0,
97 as1);
98 }
99 return 0;
100 }
101 };
102 } // namespace KokkosBatched
103
104 #endif // KOKKOSBATCHED_LASWP_SERIAL_IMPL_HPP_