Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_Hessenberg_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 #ifndef KOKKOSBATCHED_HESSENBERG_SERIAL_INTERNAL_HPP
17 #define KOKKOSBATCHED_HESSENBERG_SERIAL_INTERNAL_HPP
18
19 /// \author Kyungjoo Kim ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22 #include "KokkosBatched_Householder_Serial_Internal.hpp"
23 #include "KokkosBatched_ApplyHouseholder_Serial_Internal.hpp"
24
25 namespace KokkosBatched {
26
27 ///
28 /// Serial Internal Impl
29 /// ====================
30 ///
31 /// this impl follows the flame interface of householder transformation
32 ///
33 struct SerialHessenbergInternal {
34 template <typename ValueType>
35 KOKKOS_INLINE_FUNCTION static int invoke(const int m, // m = NumRows(A)
36 const int n, // n = NumCols(A)
37 /* */ ValueType *A, const int as0, const int as1,
38 /* */ ValueType *t, const int ts,
39 /* */ ValueType *w) {
40 typedef ValueType value_type;
41
42 /// Given a matrix A, it computes hessenberg decomposition of the matrix
43 /// - t is to store tau and w is for workspace
44 /// - H = Q^H A Q and A = Q H Q^H
45
46 // partitions used for loop iteration
47 Partition2x2<value_type> A_part2x2(as0, as1);
48 Partition3x3<value_type> A_part3x3(as0, as1);
49
50 Partition2x1<value_type> t_part2x1(ts);
51 Partition3x1<value_type> t_part3x1(ts);
52
53 // partitions used in loop body
54 Partition2x1<value_type> A21_part2x1(as0);
55 Partition2x1<value_type> A22_part2x1(as0);
56 Partition1x2<value_type> A2_part1x2(as1);
57
58 // initial partition of A where ATL has a zero dimension
59 A_part2x2.partWithATL(A, m, n, 0, 0);
60 t_part2x1.partWithAT(t, m, 0);
61
62 for (int m_atl = 0; m_atl < m; ++m_atl) {
63 // part 2x2 into 3x3
64 A_part3x3.partWithABR(A_part2x2, 1, 1);
65 const int m_A22 = m - m_atl - 1;
66 const int n_A22 = n - m_atl - 1;
67
68 t_part3x1.partWithAB(t_part2x1, 1);
69 value_type *tau = t_part3x1.A1;
70
71 /// -----------------------------------------------------
72 if (m_A22 > 0) {
73 // partition A21 into 2x1
74 A21_part2x1.partWithAT(A_part3x3.A21, m_A22, 1);
75
76 // perform householder transformation
77 const int m_A22_b = m_A22 - 1;
78 SerialLeftHouseholderInternal::invoke(m_A22_b, A21_part2x1.AT, A21_part2x1.AB, as0, tau);
79
80 // partition A22 into 2x1
81 A22_part2x1.partWithAT(A_part3x3.A22, m_A22, 1);
82
83 // left apply householder to partitioned A22
84 SerialApplyLeftHouseholderInternal::invoke(m_A22_b, n_A22, tau, A21_part2x1.AB, as0, A22_part2x1.AT, as1,
85 A22_part2x1.AB, as0, as1, w);
86
87 // partition A*2 column into 1x2
88 A2_part1x2.partWithAL(A_part3x3.A02, n_A22, 1);
89
90 // right apply householder to A*2 colums
91 const int n_A22_r = n_A22 - 1;
92 SerialApplyRightHouseholderInternal::invoke(m, n_A22_r, tau, A21_part2x1.AB, as0, A2_part1x2.AL, as0,
93 A2_part1x2.AR, as0, as1, w);
94 }
95 /// -----------------------------------------------------
96 A_part2x2.mergeToATL(A_part3x3);
97 t_part2x1.mergeToAT(t_part3x1);
98 }
99 return 0;
100 }
101 };
102
103 } // end namespace KokkosBatched
104
105 #endif