group_blas_trmv.hh
Go to the documentation of this file.
1#pragma once
2
4
5namespace batchlas::device {
6
7namespace detail::generic {
8
9template <typename Tag, typename Group, typename T>
10inline constexpr void trmv(const Group& group,
12 MatrixVectorOperand<T> operand) {
13 const int local_id = detail::group_local_linear_id(group);
14 const int local_size = detail::group_local_linear_range(group);
15 const int extent = a.rows();
16 constexpr bool effective_lower = Tag::trans == Transpose::NoTrans ? Tag::uplo == Uplo::Lower : Tag::uplo == Uplo::Upper;
17
18 for (int output_step = 0; output_step < extent; ++output_step) {
19 const int output_index = effective_lower ? (extent - 1 - output_step) : output_step;
20 T partial{};
21 for (int input_index = local_id; input_index < extent; input_index += local_size) {
22 partial += detail::triangular_matrix_entry<Tag>(a, output_index, input_index) * operand.x(input_index);
23 }
24 partial = detail::reduce_sum_group(group, partial);
25 if (detail::group_is_leader(group)) {
26 operand.y(output_index) = operand.alpha * partial + operand.beta * operand.y(output_index);
27 }
28 }
29}
30
31} // namespace detail::generic
32
33namespace detail {
34
35template <typename Tag, typename Group, typename T>
36inline constexpr void dispatch_trmv(const Group& group,
38 MatrixVectorOperand<T> operand) {
40 operand,
41 TriangularTransform{.side = Tag::side, .uplo = Tag::uplo, .trans = Tag::trans, .diag = Tag::diag});
42 generic::trmv<Tag>(group, a, operand);
43}
44
45} // namespace detail
46
47/// @addtogroup api_device_blas
48/// @{
49
50/// @brief Triangular matrix-vector product \f$ y := \alpha\,\mathrm{op}(A)\,x + \beta\,y \f$, `A` triangular.
51///
52/// Out of place, unlike BLAS `trmv`: `A` is read only on its `UploV` triangle
53/// (and not on the diagonal when `DiagV` is `Unit`). `x` and `y` may be the same
54/// vector: rows are visited in the order that never overwrites an entry a later
55/// row still reads.
56/// @tparam UploV stored triangle of `A`
57/// @tparam TransV op() applied to `A`
58/// @tparam DiagV `Unit`: the diagonal is taken as 1
59/// @tparam Group `sycl::group`, `sycl::sub_group` or an `nd_item`; every work-item must call
60/// @param group executor
61/// @param a single n x n matrix
62/// @param operand `x`, `y` (each of length at least n), `alpha`, `beta`
63/// @pre `y` holds finite values even when `beta == 0`.
64/// @note Each `y` element is written by the group leader; barrier before other work-items read it.
65template <Uplo UploV = Uplo::Upper,
67 Diag DiagV = Diag::NonUnit,
68 typename Group,
69 typename T>
75
76/// @brief As trmv(), with an explicit DeviceBlasPolicy (ignored: one implementation).
77template <DeviceBlasPolicy Policy,
78 Uplo UploV = Uplo::Upper,
80 Diag DiagV = Diag::NonUnit,
81 typename Group,
82 typename T>
83inline constexpr void trmv(const Group& group,
85 MatrixVectorOperand<T> operand) {
86 (void)Policy;
87 trmv<UploV, TransV, DiagV>(group, a, operand);
88}
89
90/// @brief As trmv(), with the operands passed separately instead of in an operand struct.
91template <Uplo UploV = Uplo::Upper,
93 Diag DiagV = Diag::NonUnit,
94 typename Group,
95 typename T>
96inline constexpr void trmv(const Group& group,
98 const VectorView<T>& x,
99 const VectorView<T>& y,
100 T alpha = T(1),
101 T beta = T(0)) {
102 trmv<UploV, TransV, DiagV>(group, a, make_matvec_operand(x, y, alpha, beta));
103}
104
105/// @brief As trmv(), with an explicit DeviceBlasPolicy and the operands passed separately (ignored: one implementation).
106template <DeviceBlasPolicy Policy,
107 Uplo UploV = Uplo::Upper,
109 Diag DiagV = Diag::NonUnit,
110 typename Group,
111 typename T>
112inline constexpr void trmv(const Group& group,
114 const VectorView<T>& x,
115 const VectorView<T>& y,
116 T alpha = T(1),
117 T beta = T(0)) {
118 (void)Policy;
119 trmv<UploV, TransV, DiagV>(group, a, x, y, alpha, beta);
120}
121
122/// @}
123
124} // 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 MatrixVectorOperand< T > make_matvec_operand(const VectorView< T > &x, const VectorView< T > &y, T alpha=T(1), T beta=T(0))
Builds a MatrixVectorOperand.
DeviceBlasPolicy
Which implementation family a device BLAS call may use.
constexpr void trmv(const Group &group, const KernelMatrixView< T, MatrixFormat::Dense > &a, MatrixVectorOperand< T > operand)
Triangular matrix-vector product , A triangular.
Transpose
The operator op() applied to an operand: op(A) = A, A^T or A^H.
Definition enums.hh:171
Diag
Whether a triangular operand's diagonal is read or assumed to be one.
Definition enums.hh:303
Uplo
Which triangle of a symmetric, Hermitian or triangular operand is referenced.
Definition enums.hh:287
@ NoTrans
op(A) = A.
Definition enums.hh:172
@ NonUnit
The stored diagonal is used.
Definition enums.hh:304
@ Upper
The upper triangle (i <= j).
Definition enums.hh:288
@ Lower
The lower triangle (i >= j).
Definition enums.hh:289
constexpr void trmv(const Group &group, const KernelMatrixView< T, MatrixFormat::Dense > &a, MatrixVectorOperand< T > operand)
constexpr int group_local_linear_id(const Group &group)
constexpr void dispatch_trmv(const Group &group, const KernelMatrixView< T, MatrixFormat::Dense > &a, MatrixVectorOperand< T > operand)
constexpr T triangular_matrix_entry(const KernelMatrixView< T, MatrixFormat::Dense > &a, int row, int col)
constexpr int group_local_linear_range(const Group &group)
constexpr T reduce_sum_group(const Group &group, const T &value)
constexpr void validate_triangular_operand(const KernelMatrixView< T, MatrixFormat::Dense > &a, const MatrixVectorOperand< T > &operand, TriangularTransform transform)
constexpr bool group_is_leader(const Group &group)
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
Operands of a matrix-vector operation: .
T beta
scale of the input y; 0 still reads y
VectorView< T > y
output vector; read (scaled by beta) and overwritten
Mode of a triangular product (trmv, trmm).