hemm.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 hemm = Event(Queue&,
16 const MatrixView<T, MatrixFormat::Dense>&,
17 const MatrixView<T, MatrixFormat::Dense>&,
18 const MatrixView<T, MatrixFormat::Dense>&,
19 T, T, Side, Uplo);
20
21// Spelled out, not aliased to sig::hemm: a vendor parameter order may differ
22// from the public one (trsm's alpha is last).
23template <typename T>
24using hemm_vendor = Event(Queue&,
25 const MatrixView<T, MatrixFormat::Dense>&,
26 const MatrixView<T, MatrixFormat::Dense>&,
27 const MatrixView<T, MatrixFormat::Dense>&,
28 T,
29 T,
30 Side,
31 Uplo);
32} // namespace sig
33
34
35/// @brief Batched Hermitian matrix-matrix multiply.
36///
37/// For every batch item computes
38/// \f[ C := \alpha A B + \beta C \quad (\texttt{Side::Left}), \qquad
39/// C := \alpha B A + \beta C \quad (\texttt{Side::Right}) \f]
40/// with `A` Hermitian. Only the triangle of `A` named by `uplo` is read; the
41/// other is taken to be its conjugate transpose, and the imaginary part of the
42/// diagonal is taken to be zero whatever is stored there. `B` and `C` are m x n;
43/// `A` is m x m (Left) or n x n (Right).
44///
45/// Constrained to complex `T`: for a real matrix Hermitian and symmetric are the
46/// same statement, and the real spelling is symm. Also callable as
47/// `hemm(ctx, A, B, C, HemmOptions<T>{...})`, with owning `Matrix` arguments,
48/// and without `Ba` (taken from `ctx.backend()`).
49///
50/// Not table-selected. On `Backend::CUDA` the cuBLAS backend chooses by a fixed rule between
51/// expanding `A` into scratch plus one strided-batched gemm and a per-item `cublas?hemm` loop
52/// (the loop also serves a scratch that does not fit); `BATCHLAS_EXPAND_ROUTE` = `expand` |
53/// `loop` pins it. The host backend runs the per-item `cblas_?hemm` loop.
54///
55/// @tparam Ba backend the call is compiled for; must match `ctx`'s device
56/// @tparam T `std::complex<float>` or `std::complex<double>`
57/// @param ctx queue the work is enqueued on
58/// @param A batch of Hermitian matrices; only the `uplo` triangle is read
59/// @param B batch of m x n matrices; not modified
60/// @param C batch of m x n matrices; input scaled by `beta`, overwritten with the result
61/// @param alpha scale of the product
62/// @param beta scale of the input `C`
63/// @param side whether `A` multiplies from the left or the right
64/// @param uplo which triangle of `A` holds the data
65/// @return event of the last enqueued kernel; `C` is valid once it completes
66/// @pre All operands have the same batch size and conforming shapes per item.
67/// @throws std::invalid_argument if the shapes do not conform (`Backend::CUDA`; the host
68/// backend checks inside its deferred host task and throws std::runtime_error there)
69/// @throws batchlas::NoRouteError in a build without the vendor BLAS
70/// for `Ba`: hemm has no native implementation.
71/// @note Not instantiated for `Backend::ROCM` (rocBLAS has no wrapper here).
72/// @see symm, HemmOptions, @ref md_docs_2cpp-api, @ref md_docs_2perf_2level3 (the rule's crossover)
73/// @ingroup api_blas3
74template <Backend Ba, ComplexScalar T>
75BATCHLAS_API Event hemm(Queue& ctx,
79 T alpha,
80 T beta,
81 Side side,
82 Uplo uplo);
83
84} // namespace batchlas
85
86
87namespace batchlas::backend {
88
89// DECLARATION ONLY: each vendor TU defines and instantiates it for its Backend;
90// the public hemm is defined in src/ops/level3/level3.cc.
91// evidence: docs/design/vendor-independence.md#the-entry-point-facade
92/// @brief Vendor-library implementation of hemm (cuBLAS, host BLAS).
93///
94/// Not an entry point: batchlas::hemm calls it. Same arguments and semantics.
95/// @ingroup api_dispatch
96template <Backend Back, ComplexScalar T>
97BATCHLAS_API Event hemm_vendor(Queue& ctx,
101 T alpha,
102 T beta,
103 Side side,
104 Uplo uplo);
105
106} // namespace batchlas::backend
107
108namespace batchlas {
109
110// Owning-argument (`f(ctx, Matrix, ...)`) and backend-deducing (`f(ctx, ...)`)
111// overloads; see blas/queue-dispatch.hh.
112
113
115
116} // namespace batchlas
Non-owning view of a batch of matrices: the argument type of every entry point.
Definition matrix.hh:485
Enumerations, scalar traits and scalar concepts shared by every public header.
Event hemm(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, T beta, Side side, Uplo uplo)
Batched Hermitian matrix-matrix multiply.
Event hemm_vendor(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, T beta, Side side, Uplo uplo)
Vendor-library implementation of hemm (cuBLAS, host BLAS).
Uplo
Which triangle of a symmetric, Hermitian or triangular operand is referenced.
Definition enums.hh:287
Side
Side on which a special operand multiplies: op(A) * B or B * op(A).
Definition enums.hh:319
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.