herk.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 herk = Event(Queue&,
16 const MatrixView<T, MatrixFormat::Dense>&,
17 const MatrixView<T, MatrixFormat::Dense>&,
19
20// Spelled out, not aliased to sig::herk: a vendor parameter order may differ
21// from the public one (trsm's alpha is last).
22template <typename T>
23using herk_vendor = Event(Queue&,
24 const MatrixView<T, MatrixFormat::Dense>&,
25 const MatrixView<T, MatrixFormat::Dense>&,
28 Uplo,
29 Transpose);
30} // namespace sig
31
32
33/// @brief Batched Hermitian rank-k update.
34///
35/// For every batch item computes
36/// \f[ C := \alpha A A^H + \beta C \quad (\texttt{NoTrans},\ A \text{ is } n \times k), \qquad
37/// C := \alpha A^H A + \beta C \quad (\texttt{ConjTrans},\ A \text{ is } k \times n) \f]
38/// with `C` Hermitian n x n. Only the triangle of `C` named by `uplo` is written;
39/// the other triangle is left exactly as it was (use `MatrixView::hermitize` to
40/// mirror it). The diagonal comes out real: an imaginary part on `C`'s diagonal
41/// is neither read nor produced.
42///
43/// `alpha` and `beta` are real (`float_t<T>`), as in BLAS `?herk`: a complex
44/// alpha would make \f$\alpha A A^H\f$ non-Hermitian. Constrained to complex `T`;
45/// the real spelling is syrk. Also callable as
46/// `herk(ctx, A, C, HerkOptions<T>{...})`, with owning `Matrix` arguments, and
47/// without `Ba` (taken from `ctx.backend()`).
48///
49/// Not table-selected. On `Backend::CUDA` the cuBLAS backend chooses by a fixed rule between one
50/// strided-batched gemm into scratch folded into the `uplo` triangle and a per-item
51/// `cublas?herk` loop (the loop also serves a scratch that does not fit);
52/// `BATCHLAS_EXPAND_ROUTE` = `expand` | `loop` pins it. `BATCHLAS_SYRK_ROUTE=gram` opts a GPU
53/// call into syrk's conjugating Gram tile kernel where it admits the shape (measured slower; kept
54/// for testing). The host backend runs the per-item `cblas_?herk` loop.
55///
56/// @tparam Ba backend the call is compiled for; must match `ctx`'s device
57/// @tparam T `std::complex<float>` or `std::complex<double>`
58/// @param ctx queue the work is enqueued on
59/// @param A batch of n x k (NoTrans) or k x n (ConjTrans) matrices; not modified
60/// @param C batch of n x n matrices; the `uplo` triangle is updated in place
61/// @param alpha real scale of the product
62/// @param beta real scale of the input `C`
63/// @param uplo which triangle of `C` is written
64/// @param transA `Transpose::NoTrans` or `Transpose::ConjTrans`
65/// @return event of the last enqueued kernel; `C` is valid once it completes
66/// @pre `A` and `C` 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`: herk has no native implementation.
71/// @note Not instantiated for `Backend::ROCM`.
72/// @see syrk, her2k, HerkOptions, @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 herk(Queue& ctx,
78 float_t<T> alpha,
79 float_t<T> beta,
80 Uplo uplo,
81 Transpose transA);
82
83} // namespace batchlas
84
85
86namespace batchlas::backend {
87
88// Declaration only: each vendor TU defines and instantiates it for its Backend.
89// The public herk is defined in src/ops/level3/level3.cc, outside every vendor TU.
90// evidence: docs/design/vendor-independence.md#the-entry-point-facade
91/// @brief Vendor-library implementation of herk (cuBLAS, host BLAS).
92///
93/// Not an entry point: batchlas::herk calls it. Same arguments and semantics.
94/// @ingroup api_dispatch
95template <Backend Back, ComplexScalar T>
96BATCHLAS_API Event herk_vendor(Queue& ctx,
99 float_t<T> alpha,
100 float_t<T> beta,
101 Uplo uplo,
102 Transpose transA);
103
104} // namespace batchlas::backend
105
106namespace batchlas {
107
108// Owning-argument (`f(ctx, Matrix, ...)`) and backend-deducing (`f(ctx, ...)`)
109// overloads; see blas/queue-dispatch.hh.
110
111
113
114} // 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 herk(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &C, float_t< T > alpha, float_t< T > beta, Uplo uplo, Transpose transA)
Batched Hermitian rank-k update.
Event herk_vendor(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &C, float_t< T > alpha, float_t< T > beta, Uplo uplo, Transpose transA)
Vendor-library implementation of herk (cuBLAS, host BLAS).
Transpose
The operator op() applied to an operand: op(A) = A, A^T or A^H.
Definition enums.hh:171
Uplo
Which triangle of a symmetric, Hermitian or triangular operand is referenced.
Definition enums.hh:287
typename base_type< T >::type float_t
Shorthand for base_type<T>::type: the precision of T (tolerances, norms, eigenvalues).
Definition enums.hh:41
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.