Debian Codegraph @

packages/kokkos-kernels/batched/dense/src/KokkosBatched_Gesv.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 #ifndef KOKKOSBATCHED_GESV_HPP
17 #define KOKKOSBATCHED_GESV_HPP
18
19 /// \author Kim Liegeois ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22 #include "KokkosBatched_Vector.hpp"
23
24 namespace KokkosBatched {
25
26 struct Gesv {
27 struct StaticPivoting {};
28 struct NoPivoting {};
29
30 using Default = StaticPivoting;
31 };
32
33 /// \brief Serial Batched GESV:
34 ///
35 /// Solve A_l x_l = b_l for all l = 0, ..., N
36 /// using a batched LU decomposition, 2 batched triangular solves, and a batched
37 /// static pivoting.
38 ///
39 /// \tparam MatrixType: Input type for the matrix, needs to be a 2D view
40 /// \tparam VectorType: Input type for the right-hand side and the solution,
41 /// needs to be a 1D view
42 ///
43 /// \param A [in]: matrix, a rank 2 view
44 /// \param X [out]: solution, a rank 1 view
45 /// \param B [in]: right-hand side, a rank 1 view
46 /// \param tmp [in]: a rank 2 view used to store temporary variable; dimension
47 /// must be n x (n+4) where n is the number of rows.
48 ///
49 ///
50 /// Two versions are available (those are chosen based on ArgAlgo):
51 ///
52 /// 1. NoPivoting: the solver does not use a pivoting strategy,
53 /// 2. StaticPivoting: the solver uses a static pivoting strategy that relies
54 /// on using
55 /// maximal absolute value of row and column to choose pivots and apply
56 /// them before calling the LU decomposition. Known limitation: the
57 /// currently implemented strategy would not work with some matrices such
58 /// as [[2, 1], [1, 0]], when this is the case, the Gesv (if used with
59 /// pivoting), will return 1 and print an error message.
60 ///
61 /// No nested parallel_for is used inside of the function.
62 ///
63
64 template <typename ArgAlgo>
65 struct SerialGesv {
66 template <typename MatrixType, typename XVectorType, typename YVectorType>
67 KOKKOS_INLINE_FUNCTION static int invoke(const MatrixType A, const XVectorType X, const YVectorType Y,
68 const MatrixType tmp);
69
70 template <typename MatrixType, typename VectorType>
71 [[deprecated]] KOKKOS_INLINE_FUNCTION static int invoke(const MatrixType A, const VectorType X, const VectorType Y,
72 const MatrixType tmp) {
73 return invoke(A, X, Y, tmp);
74 }
75 };
76
77 /// \brief Team Batched GESV:
78 ///
79 /// Solve A_l x_l = b_l for all l = 0, ..., N
80 /// using a batched LU decomposition, 2 batched triangular solves, and a batched
81 /// static pivoting.
82 ///
83 /// \tparam MatrixType: Input type for the matrix, needs to be a 2D view
84 /// \tparam VectorType: Input type for the right-hand side and the solution,
85 /// needs to be a 1D view
86 ///
87 /// \param member [in]: TeamPolicy member
88 /// \param A [in]: matrix, a rank 2 view
89 /// \param X [out]: solution, a rank 1 view
90 /// \param B [in]: right-hand side, a rank 1 view
91 ///
92 /// Two versions are available (those are chosen based on ArgAlgo):
93 ///
94 /// 1. NoPivoting: the solver does not use a pivoting strategy,
95 /// 2. StaticPivoting: the solver uses a static pivoting strategy that relies
96 /// on using
97 /// maximal absolute value of row and column to choose pivots and apply
98 /// them before calling the LU decomposition. Known limitation: the
99 /// currently implemented strategy would not work with some matrices such
100 /// as [[2, 1], [1, 0]], when this is the case, the Gesv (if used with
101 /// pivoting), will return 1 and print an error message.
102 ///
103 /// A nested parallel_for with TeamThreadRange is used.
104 ///
105
106 template <typename MemberType, typename ArgAlgo>
107 struct TeamGesv {
108 template <typename MatrixType, typename VectorType>
109 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const MatrixType A, const VectorType X,
110 const VectorType Y);
111 };
112
113 /// \brief Team Vector Batched GESV:
114 ///
115 /// Solve A_l x_l = b_l for all l = 0, ..., N
116 /// using a batched LU decomposition, 2 batched triangular solves, and a batched
117 /// static pivoting.
118 ///
119 /// \tparam MatrixType: Input type for the matrix, needs to be a 2D view
120 /// \tparam VectorType: Input type for the right-hand side and the solution,
121 /// needs to be a 1D view
122 ///
123 /// \param member [in]: TeamPolicy member
124 /// \param A [in]: matrix, a rank 2 view
125 /// \param X [out]: solution, a rank 1 view
126 /// \param B [in]: right-hand side, a rank 1 view
127 ///
128 /// Two versions are available (those are chosen based on ArgAlgo):
129 ///
130 /// 1. NoPivoting: the solver does not use a pivoting strategy,
131 /// 2. StaticPivoting: the solver uses a static pivoting strategy that relies
132 /// on using
133 /// maximal absolute value of row and column to choose pivots and apply
134 /// them before calling the LU decomposition. Known limitation: the
135 /// currently implemented strategy would not work with some matrices such
136 /// as [[2, 1], [1, 0]], when this is the case, the Gesv (if used with
137 /// pivoting), will return 1 and print an error message.
138 ///
139 /// Two nested parallel_for with both TeamVectorRange and ThreadVectorRange
140 /// (or one with TeamVectorRange) are used inside.
141 ///
142
143 template <typename MemberType, typename ArgAlgo>
144 struct TeamVectorGesv {
145 template <typename MatrixType, typename VectorType>
146 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const MatrixType A, const VectorType X,
147 const VectorType Y);
148 };
149
150 } // namespace KokkosBatched
151
152 #include "KokkosBatched_Gesv_Impl.hpp"
153
154 #endif