Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_SolveUTV_TeamVector_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 #ifndef KOKKOSBATCHED_SOLVE_UTV_TEAMVECTOR_INTERNAL_HPP
17 #define KOKKOSBATCHED_SOLVE_UTV_TEAMVECTOR_INTERNAL_HPP
18
19 /// \author Kyungjoo Kim ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22
23 #include "KokkosBlas2_team_gemv_impl.hpp"
24 #include "KokkosBatched_Trsv_TeamVector_Internal.hpp"
25
26 #include "KokkosBatched_Gemm_TeamVector_Internal.hpp"
27 #include "KokkosBatched_Trsm_TeamVector_Internal.hpp"
28
29 namespace KokkosBatched {
30
31 ///
32 /// TeamVector Internal
33 /// ===================
34 struct TeamVectorSolveUTV_Internal {
35 template <typename MemberType, typename ValueType, typename IntType>
36 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int matrix_rank, const int m,
37 const int /*n*/, const ValueType *U, const int us0, const int us1,
38 const ValueType *T, const int ts0, const int ts1, const ValueType *V,
39 const int vs0, const int vs1, const IntType *p, const int ps0,
40 /* */ ValueType *x, const int xs0,
41 /* */ ValueType *b, const int bs0,
42 /* */ ValueType *w) {
43 typedef ValueType value_type;
44 // typedef IntType int_type;
45
46 const value_type one(1), zero(0);
47 const int ws0 = 1;
48
49 if (matrix_rank < m) {
50 /// w = U^T b
51 KokkosBlas::Impl::TeamVectorGemvInternal<Algo::Gemv::Unblocked>::invoke(member, matrix_rank, m, one, U, us1, us0,
52 b, bs0, zero, w, ws0);
53
54 /// w = T^{-1} w
55 TeamVectorTrsvInternalLower<Algo::Trsv::Unblocked>::invoke(member, false, matrix_rank, one, T, ts0, ts1, w, ws0);
56
57 /// x = V^T w
58 KokkosBlas::Impl::TeamVectorGemvInternal<Algo::Gemv::Unblocked>::invoke(member, m, matrix_rank, one, V, vs1, vs0,
59 w, ws0, zero, x, xs0);
60 } else {
61 KokkosBlas::Impl::TeamVectorGemvInternal<Algo::Gemv::Unblocked>::invoke(member, matrix_rank, m, one, U, us1, us0,
62 b, bs0, zero, x, xs0);
63
64 TeamVectorTrsvInternalUpper<Algo::Trsv::Unblocked>::invoke(member, false, matrix_rank, one, T, ts0, ts1, x, xs0);
65 }
66
67 /// x = P^T x
68 TeamVectorApplyPivotVectorBackwardInternal ::invoke(member, m, p, ps0, x, xs0);
69
70 return 0;
71 }
72
73 template <typename MemberType, typename ValueType, typename IntType>
74 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int matrix_rank, const int m, const int n,
75 const int nrhs, const ValueType *U, const int us0, const int us1,
76 const ValueType *T, const int ts0, const int ts1, const ValueType *V,
77 const int vs0, const int vs1, const IntType *p, const int ps0,
78 /* */ ValueType *X, const int xs0, const int xs1,
79 /* */ ValueType *B, const int bs0, const int bs1,
80 /* */ ValueType *w) {
81 typedef ValueType value_type;
82 // typedef IntType int_type;
83
84 const value_type one(1), zero(0);
85
86 value_type *W = w; /// m x nrhs
87 const int ws0 = xs0 < xs1 ? 1 : nrhs, ws1 = xs0 < xs1 ? m : 1;
88
89 if (matrix_rank < n) {
90 /// U is m x matrix_rank
91 /// T is matrix_rank x matrix_rank
92 /// V is matrix_rank x n
93 /// W = U^T B
94 TeamVectorGemmInternal<Algo::Gemm::Unblocked>::invoke(member, matrix_rank, nrhs, m, one, U, us1, us0, B, bs0, bs1,
95 zero, W, ws0, ws1);
96 member.team_barrier();
97
98 /// W = T^{-1} W
99 TeamVectorTrsmInternalLeftLower<Algo::Trsm::Unblocked>::invoke(member, false, matrix_rank, nrhs, one, T, ts0, ts1,
100 W, ws0, ws1);
101 member.team_barrier();
102
103 /// X = V^T W
104 TeamVectorGemmInternal<Algo::Gemm::Unblocked>::invoke(member, n, nrhs, matrix_rank, one, V, vs1, vs0, W, ws0, ws1,
105 zero, X, xs0, xs1);
106 member.team_barrier();
107 } else {
108 /// W = U^T B
109 TeamVectorGemmInternal<Algo::Gemm::Unblocked>::invoke(member, matrix_rank, nrhs, m, one, U, us1, us0, B, bs0, bs1,
110 zero, X, xs0, xs1);
111 member.team_barrier();
112
113 /// X = T^{-1} X
114 TeamVectorTrsmInternalLeftUpper<Algo::Trsm::Unblocked>::invoke(member, false, matrix_rank, nrhs, one, T, ts0, ts1,
115 X, xs0, xs1);
116 member.team_barrier();
117 }
118
119 /// X = P^T X
120 TeamVectorApplyPivotMatrixBackwardInternal ::invoke(member, nrhs, n, p, ps0, X, xs0, xs1);
121
122 return 0;
123 }
124 };
125
126 } // end namespace KokkosBatched
127
128 #endif