steqr_internal.hh
Go to the documentation of this file.
1#pragma once
2
4
5#include <src/math-helpers.hh>
6
7#include <array>
8
9namespace batchlas {
10
11namespace internal {
12
13// {c, -s} of LAPACK lartg(a, b): the rotation convention of the work-group bulge chase.
14template <typename T>
15inline std::array<T, 2> givens_rotation(const T& a, const T& b) {
16 auto [c_l, s_l, r] = internal::lartg(a, b);
17 (void)r;
18 return std::array<T, 2>{c_l, -s_l};
19}
20
21// Similarity transform of rows/cols i, j of the tridiagonal (d, e); returns the new bulge.
22// QR == true indexes top-down (virtual k == physical k), false bottom-up (k -> n-1-k), so one
23// bulge chase implements both the QR and the QL iteration.
24template <typename T>
26 const VectorView<T>& e,
27 const T& prev_bulge,
28 size_t i,
29 size_t j,
30 const std::array<T, 2>& givens,
31 bool QR) {
32 const T c = givens[0];
33 const T s = givens[1];
34
35 const size_t n = d.size();
36 const size_t ne = e.size();
37
38 auto d_get = [&](size_t k) -> T {
39 return QR ? d(k) : d(n - 1 - k);
40 };
41 auto d_set = [&](size_t k, T val) {
42 if (QR) {
43 d(k) = val;
44 } else {
45 d(n - 1 - k) = val;
46 }
47 };
48 auto e_get = [&](size_t k) -> T {
49 return QR ? e(k) : e(ne - 1 - k);
50 };
51 auto e_set = [&](size_t k, T val) {
52 if (QR) {
53 e(k) = val;
54 } else {
55 e(ne - 1 - k) = val;
56 }
57 };
58
59 T di = d_get(i);
60 T dj = d_get(j);
61 T ei = e_get(i);
62 T ej = (j < ne) ? e_get(j) : T(0);
63
64 T di_new = c * (c * di - ei * s) - s * (ei * c - s * dj);
65 T dj_new = c * (c * dj + ei * s) + s * (ei * c + s * di);
66 d_set(i, di_new);
67 d_set(j, dj_new);
68
69 if (i > 0) {
70 T e_im1 = e_get(i - 1);
71 e_set(i - 1, e_im1 * c - prev_bulge * s);
72 }
73
74 T ei_new = c * (c * ei + s * di) - s * (c * dj + s * ei);
75 e_set(i, ei_new);
76
77 if (j < ne) {
78 e_set(j, c * ej);
79 }
80
81 return -ej * s;
82}
83
84} // namespace internal
85
86template <Backend B, typename T>
88 const VectorView<T>& d_in,
89 const VectorView<T>& e_in,
90 const VectorView<T>& eigenvalues,
91 const Span<std::byte>& ws,
92 JobType jobz,
93 SteqrParams<T> params,
96
97template <typename T>
99 const VectorView<T>& d,
100 const VectorView<T>& e,
101 const VectorView<T>& eigenvalues,
102 JobType jobz,
103 SteqrParams<T> params);
104
105template <Backend B, typename T>
107 const VectorView<T>& d_in,
108 const VectorView<T>& e_in,
109 const VectorView<T>& eigenvalues,
110 const Span<std::byte>& ws,
111 JobType jobz,
112 SteqrParams<T> params,
115
116template <typename T>
118 const VectorView<T>& d,
119 const VectorView<T>& e,
120 const VectorView<T>& eigenvalues,
121 JobType jobz,
122 SteqrParams<T> params);
123
124// steqr's route choice WITHOUT the `info` clear.
125//
126// The public `steqr` is exactly `detail::info_clear` followed by this, and the two
127// tiers below it only ever RAISE a status (info_span.hh). stedc's leaves call this
128// one: its recursive driver solves the two halves of the SAME batch items with two
129// separate leaf solves, so a leaf that cleared would erase the first half's failure
130// and stedc would report success on an item that did not converge.
131template <Backend B, typename T>
133 const VectorView<T>& d_in,
134 const VectorView<T>& e_in,
135 const VectorView<T>& eigenvalues,
136 const Span<std::byte>& ws,
137 JobType jobz,
138 SteqrParams<T> params,
141
142} // namespace batchlas
Non-owning view of a batch of matrices: the argument type of every entry point.
Definition matrix.hh:485
Non-owning view of a batch of strided vectors: the vector argument type of the entry points.
Definition matrix.hh:1754
int size() const
Entries per item.
Definition matrix.hh:1837
JobType
Whether an eigensolver computes eigenvectors (LAPACK jobz).
Definition enums.hh:189
std::array< T, 2 > givens_rotation(const T &a, const T &b)
T apply_givens_rotation(const VectorView< T > &d, const VectorView< T > &e, const T &prev_bulge, size_t i, size_t j, const std::array< T, 2 > &givens, bool QR)
Event steqr_legacy(Queue &ctx, const VectorView< T > &d_in, const VectorView< T > &e_in, const VectorView< T > &eigenvalues, const Span< std::byte > &ws, JobType jobz, SteqrParams< T > params, const MatrixView< T, MatrixFormat::Dense > &eigvects, Span< int32_t > info=Span< int32_t >())
Event steqr_wg(Queue &ctx, const VectorView< T > &d_in, const VectorView< T > &e_in, const VectorView< T > &eigenvalues, const Span< std::byte > &ws, JobType jobz, SteqrParams< T > params, const MatrixView< T, MatrixFormat::Dense > &eigvects, Span< int32_t > info=Span< int32_t >())
Event steqr_dispatch(Queue &ctx, const VectorView< T > &d_in, const VectorView< T > &e_in, const VectorView< T > &eigenvalues, const Span< std::byte > &ws, JobType jobz, SteqrParams< T > params, const MatrixView< T, MatrixFormat::Dense > &eigvects, Span< int32_t > info=Span< int32_t >())
size_t steqr_wg_buffer_size(Queue &ctx, const VectorView< T > &d, const VectorView< T > &e, const VectorView< T > &eigenvalues, JobType jobz, SteqrParams< T > params)
size_t steqr_legacy_buffer_size(Queue &ctx, const VectorView< T > &d, const VectorView< T > &e, const VectorView< T > &eigenvalues, JobType jobz, SteqrParams< T > params)
Completion handle of enqueued work, returned by every entry point.
Where BatchLAS work runs: a device, a backend, an ordered SYCL queue and a workspace arena.
Non-owning view of size() contiguous elements of type T.
Definition sycl-span.hh:39
Parameters for steqr() and steqr_cta(), and for stedc()'s leaf solves.