group_blas_ger.hh
Go to the documentation of this file.
1#pragma once
2
4
5namespace batchlas::device {
6
7namespace detail::generic {
8
9template <typename Group, typename T>
10inline constexpr void ger(const Group& group,
11 const VectorView<T>& x,
13 OuterProductTransform transform) {
14 const int local_id = detail::group_local_linear_id(group);
15 const int local_size = detail::group_local_linear_range(group);
16 const int row_extent = operand.a.rows();
17 const int col_extent = operand.a.cols();
18
19 for (int linear_index = local_id; linear_index < row_extent * col_extent; linear_index += local_size) {
20 const int row = linear_index % row_extent;
21 const int col = linear_index / row_extent;
22 const T lhs = detail::maybe_conjugate(x(row), transform.conjugate_x);
23 const T rhs = detail::maybe_conjugate(operand.y(col), transform.conjugate_y);
24 detail::accumulate_rank1_output(operand, row, col, lhs * rhs);
25 }
26}
27
28} // namespace detail::generic
29
30namespace detail {
31
32template <typename Tag, typename Group, typename T>
33inline constexpr void dispatch_ger(const Group& group,
34 const VectorView<T>& x,
35 Rank1UpdateOperand<T> operand) {
36 validate_rank1_operand(x, operand);
37 generic::ger(group,
38 x,
39 operand,
40 OuterProductTransform{.conjugate_x = Tag::conjugate_x, .conjugate_y = Tag::conjugate_y});
41}
42
43} // namespace detail
44
45/// @addtogroup api_device_blas
46/// @{
47
48/// @brief Rank-1 update \f$ A := A + \alpha\,\tilde{x}\,\tilde{y}^{T} \f$, with \f$\tilde{x}\f$, \f$\tilde{y}\f$ optionally conjugated.
49///
50/// geru() and gerc() are the BLAS-named spellings (no conjugation, and
51/// conjugated `y`). Each element of `A` is owned by one work-item, so no
52/// reduction and no barrier is involved.
53/// @tparam ConjugateXV use \f$\bar{x}\f$
54/// @tparam ConjugateYV use \f$\bar{y}\f$
55/// @tparam Group `sycl::group`, `sycl::sub_group` or an `nd_item`; every work-item must call
56/// @param group executor whose work-items share the elements of `A`
57/// @param x left vector, length `a.rows()`
58/// @param operand `y` (length `a.cols()`), `A` (updated in place) and `alpha`
59/// @pre single-problem views; sizes as above. Checked by `assert` only.
60template <bool ConjugateXV = false, bool ConjugateYV = false, typename Group, typename T>
61inline constexpr void ger(const Group& group,
62 const VectorView<T>& x,
63 Rank1UpdateOperand<T> operand) {
65}
66
67/// @brief As ger(), with an explicit DeviceBlasPolicy (ignored: one implementation).
68template <DeviceBlasPolicy Policy,
69 bool ConjugateXV = false,
70 bool ConjugateYV = false,
71 typename Group,
72 typename T>
73inline constexpr void ger(const Group& group,
74 const VectorView<T>& x,
75 Rank1UpdateOperand<T> operand) {
76 (void)Policy;
77 ger<ConjugateXV, ConjugateYV>(group, x, operand);
78}
79
80/// @brief As ger(), with the operands passed separately instead of in an operand struct.
81template <bool ConjugateXV = false, bool ConjugateYV = false, typename Group, typename T>
82inline constexpr void ger(const Group& group,
83 const VectorView<T>& x,
84 const VectorView<T>& y,
86 T alpha = T(1)) {
88}
89
90/// @brief As ger(), with an explicit DeviceBlasPolicy and the operands passed separately (ignored: one implementation).
91template <DeviceBlasPolicy Policy,
92 bool ConjugateXV = false,
93 bool ConjugateYV = false,
94 typename Group,
95 typename T>
96inline constexpr void ger(const Group& group,
97 const VectorView<T>& x,
98 const VectorView<T>& y,
100 T alpha = T(1)) {
101 (void)Policy;
102 ger<ConjugateXV, ConjugateYV>(group, x, y, a, alpha);
103}
104
105/// @brief Unconjugated rank-1 update \f$ A := A + \alpha\,x\,y^{T} \f$; ger() without conjugation.
106/// @param group executor whose work-items share the elements of `A`
107/// @param x left vector, length `a.rows()`
108/// @param operand `y`, `A` and `alpha`
109template <typename Group, typename T>
110inline constexpr void geru(const Group& group,
111 const VectorView<T>& x,
112 Rank1UpdateOperand<T> operand) {
113 ger<false, false>(group, x, operand);
114}
115
116/// @brief As geru(), with an explicit DeviceBlasPolicy (ignored: one implementation).
117template <DeviceBlasPolicy Policy, typename Group, typename T>
118inline constexpr void geru(const Group& group,
119 const VectorView<T>& x,
120 Rank1UpdateOperand<T> operand) {
121 (void)Policy;
122 geru(group, x, operand);
123}
124
125/// @brief As geru(), with the operands passed separately instead of in an operand struct.
126template <typename Group, typename T>
127inline constexpr void geru(const Group& group,
128 const VectorView<T>& x,
129 const VectorView<T>& y,
131 T alpha = T(1)) {
132 ger<false, false>(group, x, y, a, alpha);
133}
134
135/// @brief As geru(), with an explicit DeviceBlasPolicy and the operands passed separately (ignored: one implementation).
136template <DeviceBlasPolicy Policy, typename Group, typename T>
137inline constexpr void geru(const Group& group,
138 const VectorView<T>& x,
139 const VectorView<T>& y,
141 T alpha = T(1)) {
142 (void)Policy;
143 geru(group, x, y, a, alpha);
144}
145
146/// @brief Conjugated rank-1 update \f$ A := A + \alpha\,x\,y^{H} \f$; ger() with conjugated `y`.
147/// @param group executor whose work-items share the elements of `A`
148/// @param x left vector, length `a.rows()`
149/// @param operand `y`, `A` and `alpha`
150template <typename Group, typename T>
151inline constexpr void gerc(const Group& group,
152 const VectorView<T>& x,
153 Rank1UpdateOperand<T> operand) {
154 ger<false, true>(group, x, operand);
155}
156
157/// @brief As gerc(), with an explicit DeviceBlasPolicy (ignored: one implementation).
158template <DeviceBlasPolicy Policy, typename Group, typename T>
159inline constexpr void gerc(const Group& group,
160 const VectorView<T>& x,
161 Rank1UpdateOperand<T> operand) {
162 (void)Policy;
163 gerc(group, x, operand);
164}
165
166/// @brief As gerc(), with the operands passed separately instead of in an operand struct.
167template <typename Group, typename T>
168inline constexpr void gerc(const Group& group,
169 const VectorView<T>& x,
170 const VectorView<T>& y,
172 T alpha = T(1)) {
173 ger<false, true>(group, x, y, a, alpha);
174}
175
176/// @brief As gerc(), with an explicit DeviceBlasPolicy and the operands passed separately (ignored: one implementation).
177template <DeviceBlasPolicy Policy, typename Group, typename T>
178inline constexpr void gerc(const Group& group,
179 const VectorView<T>& x,
180 const VectorView<T>& y,
182 T alpha = T(1)) {
183 (void)Policy;
184 gerc(group, x, y, a, alpha);
185}
186
187/// @}
188
189} // namespace batchlas::device
Non-owning view of a batch of strided vectors: the vector argument type of the entry points.
Definition matrix.hh:1754
Policy
Synchronous or asynchronous execution policy.
constexpr Rank1UpdateOperand< T > make_rank1_update_operand(const VectorView< T > &y, const KernelMatrixView< T, MatrixFormat::Dense > &a, T alpha=T(1))
Builds a Rank1UpdateOperand.
DeviceBlasPolicy
Which implementation family a device BLAS call may use.
constexpr void gerc(const Group &group, const VectorView< T > &x, Rank1UpdateOperand< T > operand)
Conjugated rank-1 update ; ger() with conjugated y.
constexpr void ger(const Group &group, const VectorView< T > &x, Rank1UpdateOperand< T > operand)
Rank-1 update , with , optionally conjugated.
constexpr void geru(const Group &group, const VectorView< T > &x, Rank1UpdateOperand< T > operand)
Unconjugated rank-1 update ; ger() without conjugation.
constexpr void ger(const Group &group, const VectorView< T > &x, Rank1UpdateOperand< T > operand, OuterProductTransform transform)
constexpr void validate_rank1_operand(const VectorView< T > &x, const Rank1UpdateOperand< T > &operand)
constexpr int group_local_linear_id(const Group &group)
constexpr void accumulate_rank1_output(const Rank1UpdateOperand< T > &operand, int row, int col, const T &value)
constexpr int group_local_linear_range(const Group &group)
constexpr T maybe_conjugate(const T &value, bool conjugate)
constexpr void dispatch_ger(const Group &group, const VectorView< T > &x, Rank1UpdateOperand< T > operand)
Trivially copyable view of a MatrixView for use inside a SYCL kernel.
Definition matrix.hh:145
auto rows() const
Row count (the capacity on a heterogeneous batch).
Definition matrix.hh:219
auto cols() const
Column count (the capacity on a heterogeneous batch).
Definition matrix.hh:223
Conjugation mode of a rank-1 update (ger, geru, gerc).
Operands of a rank-1 update: (conjugations per call).
KernelMatrixView< T, MatrixFormat::Dense > a
matrix updated in place
VectorView< T > y
right vector, length a.cols()