gemv.hh
Go to the documentation of this file.
1#pragma once
2
3#include <batchlas/export.hh>
8
9namespace batchlas {
10
11// Signature aliases for explicit instantiation; see BATCHLAS_INSTANTIATE in
12// src/util/template-instantiations.hh. Keep in sync with the declarations below.
13namespace sig {
14template <typename T>
15using gemv = Event(Queue&,
16 const MatrixView<T, MatrixFormat::Dense>&,
17 const VectorView<T>&,
18 const VectorView<T>&,
19 T, T, Transpose);
20
21// Spelled out, not aliased to sig::gemv: a vendor parameter order may differ
22// from the public one (trsm's alpha is last).
23template <typename T>
24using gemv_vendor = Event(Queue&,
25 const MatrixView<T,MatrixFormat::Dense>&,
26 const VectorView<T>&,
27 const VectorView<T>&,
28 T,
29 T,
30 Transpose);
31} // namespace sig
32
33
34/// @brief Batched general matrix-vector multiply.
35///
36/// For every batch item \f$b\f$ computes
37/// \f[ y_b := \alpha \, \mathrm{op}(A_b) \, x_b + \beta \, y_b \f]
38/// where \f$\mathrm{op}(A)\f$ is \f$A\f$, \f$A^T\f$ or \f$A^H\f$ according to
39/// `transA`. For an m x n `A`, `X` has length n and `Y` length m under
40/// `NoTrans`, and the other way round under `Trans` / `ConjTrans`. The vectors'
41/// `inc` (element spacing) and `stride` (batch spacing) are honoured.
42///
43/// Also callable as `gemv(ctx, A, x, y, GemvOptions<T>{...})`, with owning
44/// `Matrix` / `Vector` arguments, and without `B` (taken from `ctx.backend()`).
45///
46/// @tparam B backend the call is compiled for; must match `ctx`'s device
47/// @tparam T scalar type: `float`, `double`, `std::complex<float>` or `std::complex<double>`
48/// @param ctx queue the work is enqueued on
49/// @param A batch of m x n matrices
50/// @param X batch of input vectors
51/// @param Y batch of output vectors; input scaled by `beta`, overwritten with the result
52/// @param alpha scale of the product
53/// @param beta scale of the input `Y`
54/// @param transA op() applied to `A`
55/// @return event of the last enqueued kernel; `Y` is valid once it completes
56/// @pre `A`, `X` and `Y` have the same batch size and conforming lengths.
57/// @throws batchlas::NoRouteError in a build without the vendor BLAS for `B`
58/// when no native kernel can run the call (for example a heterogeneous `A`).
59/// @note No argument validation is done up front: a shape the native kernels
60/// refuse goes to the vendor library, which reports it.
61/// @see GemvOptions, @ref md_docs_2cpp-api
62/// @ingroup api_blas2
63template <Backend B, typename T>
64BATCHLAS_API Event gemv(Queue& ctx,
66 const VectorView<T>& X,
67 const VectorView<T>& Y,
68 T alpha,
69 T beta,
70 Transpose transA);
71
72} // namespace batchlas
73
74
75namespace batchlas::backend {
76
77// DECLARATION ONLY: each vendor TU defines and instantiates it for its Backend;
78// the public gemv is defined in src/ops/gemv/gemv.cc.
79// evidence: docs/design/vendor-independence.md#the-entry-point-facade
80/// @brief Vendor-library implementation of gemv (cuBLAS, rocBLAS, host BLAS).
81///
82/// Not an entry point: batchlas::gemv calls it when it selects the `vendor`
83/// kernel family. Same arguments and semantics as batchlas::gemv.
84/// @ingroup api_dispatch
85template <Backend B, typename T>
86BATCHLAS_API Event gemv_vendor(Queue& ctx,
88 const VectorView<T>& X,
89 const VectorView<T>& Y,
90 T alpha,
91 T beta,
92 Transpose transA);
93
94} // namespace batchlas::backend
95
96namespace batchlas {
97
98// Owning-argument (`f(ctx, Matrix, ...)`) and backend-deducing (`f(ctx, ...)`)
99// overloads; see blas/queue-dispatch.hh.
100
101
103
104} // 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
Enumerations, scalar traits and scalar concepts shared by every public header.
Event gemv(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const VectorView< T > &X, const VectorView< T > &Y, T alpha, T beta, Transpose transA)
Batched general matrix-vector multiply.
Event gemv_vendor(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const VectorView< T > &X, const VectorView< T > &Y, T alpha, T beta, Transpose transA)
Vendor-library implementation of gemv (cuBLAS, rocBLAS, host BLAS).
Transpose
The operator op() applied to an operand: op(A) = A, A^T or A^H.
Definition enums.hh:171
The batched containers: Matrix (owning), MatrixView (non-owning), KernelMatrixView (device-side),...
Backend deduction from the Queue and the USM pointer check.
#define BATCHLAS_DISPATCH_ON_QUEUE(NAME)
Completion handle of enqueued work, returned by every entry point.
Event()
An empty Event, already complete.
Where BatchLAS work runs: a device, a backend, an ordered SYCL queue and a workspace arena.
batchlas::Device, batchlas::Event and batchlas::Queue: where work runs and how it is ordered.