Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_Laswp_Serial_Internal.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_INTERNAL_HPP_
18 #define KOKKOSBATCHED_LASWP_SERIAL_INTERNAL_HPP_
19
20 /// \author Yuuichi Asahi ([email protected])
21
22 #include "KokkosBatched_Util.hpp"
23
24 namespace KokkosBatched {
25 namespace Impl {
26
27 ///
28 /// Serial Internal Impl
29 /// ========================
30
31 ///
32 //// Forward pivot apply
33 ///
34
35 struct SerialLaswpVectorForwardInternal {
36 template <typename IntType, typename ValueType>
37 KOKKOS_INLINE_FUNCTION static int invoke(const int plen, const IntType *KOKKOS_RESTRICT p, const int ps0,
38 /* */ ValueType *KOKKOS_RESTRICT A, const int as0) {
39 for (int i = 0; i < plen; ++i) {
40 const int piv = p[i * ps0];
41 if (piv != i) {
42 const int idx_i = i * as0, idx_p = piv * as0;
43 const ValueType tmp = A[idx_i];
44 A[idx_i] = A[idx_p];
45 A[idx_p] = tmp;
46 }
47 }
48 return 0;
49 }
50 };
51
52 struct SerialLaswpMatrixForwardInternal {
53 template <typename IntType, typename ValueType>
54 KOKKOS_INLINE_FUNCTION static int invoke(const int n, const int plen, const IntType *KOKKOS_RESTRICT p, const int ps0,
55 /* */ ValueType *KOKKOS_RESTRICT A, const int as0, const int as1) {
56 if (as0 <= as1) {
57 // LayoutLeft like
58 for (int j = 0; j < n; j++) {
59 ValueType *KOKKOS_RESTRICT A_at_j = A + j * as1;
60 for (int i = 0; i < plen; ++i) {
61 const int piv = p[i * ps0];
62 if (piv != i) {
63 const int idx_i = i * as0, idx_p = piv * as0;
64 const ValueType tmp = A_at_j[idx_i];
65 A_at_j[idx_i] = A_at_j[idx_p];
66 A_at_j[idx_p] = tmp;
67 }
68 }
69 }
70 } else {
71 // LayoutRight like
72 for (int i = 0; i < plen; ++i) {
73 const int piv = p[i * ps0];
74 if (piv != i) {
75 const int idx_i = i * as0, idx_p = piv * as0;
76 for (int j = 0; j < n; j++) {
77 ValueType *KOKKOS_RESTRICT A_at_j = A + j * as1;
78 const ValueType tmp = A_at_j[idx_i];
79 A_at_j[idx_i] = A_at_j[idx_p];
80 A_at_j[idx_p] = tmp;
81 }
82 }
83 }
84 }
85 return 0;
86 }
87 };
88
89 ///
90 /// Backward pivot apply
91 ///
92
93 struct SerialLaswpVectorBackwardInternal {
94 template <typename IntType, typename ValueType>
95 KOKKOS_INLINE_FUNCTION static int invoke(const int plen, const IntType *KOKKOS_RESTRICT p, const int ps0,
96 /* */ ValueType *KOKKOS_RESTRICT A, const int as0) {
97 for (int i = (plen - 1); i >= 0; --i) {
98 const int piv = p[i * ps0];
99 if (piv != i) {
100 const int idx_i = i * as0, idx_p = piv * as0;
101 const ValueType tmp = A[idx_i];
102 A[idx_i] = A[idx_p];
103 A[idx_p] = tmp;
104 }
105 }
106 return 0;
107 }
108 };
109
110 struct SerialLaswpMatrixBackwardInternal {
111 template <typename IntType, typename ValueType>
112 KOKKOS_INLINE_FUNCTION static int invoke(const int n, const int plen, const IntType *KOKKOS_RESTRICT p, const int ps0,
113 /* */ ValueType *KOKKOS_RESTRICT A, const int as0, const int as1) {
114 if (as0 <= as1) {
115 // LayoutLeft like
116 for (int j = 0; j < n; j++) {
117 ValueType *KOKKOS_RESTRICT A_at_j = A + j * as1;
118 for (int i = (plen - 1); i >= 0; --i) {
119 const int piv = p[i * ps0];
120 if (piv != i) {
121 const int idx_i = i * as0, idx_p = piv * as0;
122 const ValueType tmp = A_at_j[idx_i];
123 A_at_j[idx_i] = A_at_j[idx_p];
124 A_at_j[idx_p] = tmp;
125 }
126 }
127 }
128 } else {
129 // LayoutRight like
130 for (int i = (plen - 1); i >= 0; --i) {
131 const int piv = p[i * ps0];
132 if (piv != i) {
133 const int idx_i = i * as0, idx_p = piv * as0;
134 for (int j = 0; j < n; j++) {
135 ValueType *KOKKOS_RESTRICT A_at_j = A + j * as1;
136 const ValueType tmp = A_at_j[idx_i];
137 A_at_j[idx_i] = A_at_j[idx_p];
138 A_at_j[idx_p] = tmp;
139 }
140 }
141 }
142 }
143 return 0;
144 }
145 };
146
147 } // namespace Impl
148 } // namespace KokkosBatched
149
150 #endif // KOKKOSBATCHED_LASWP_SERIAL_INTERNAL_HPP_