her2k.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 her2k = Event(Queue&,
16 const MatrixView<T, MatrixFormat::Dense>&,
17 const MatrixView<T, MatrixFormat::Dense>&,
18 const MatrixView<T, MatrixFormat::Dense>&,
20
21// Spelled out, not aliased to sig::her2k: a vendor parameter order may differ
22// from the public one (trsm's alpha is last).
23template <typename T>
24using her2k_vendor = Event(Queue&,
25 const MatrixView<T, MatrixFormat::Dense>&,
26 const MatrixView<T, MatrixFormat::Dense>&,
27 const MatrixView<T, MatrixFormat::Dense>&,
28 T,
30 Uplo,
31 Transpose);
32} // namespace sig
33
34
35/// @brief Batched Hermitian rank-2k update.
36///
37/// For every batch item computes, with `A` and `B` n x k (`NoTrans`) or k x n
38/// (`ConjTrans`) and `C` Hermitian n x n,
39/// \f[ C := \alpha A B^H + \bar\alpha B A^H + \beta C \quad (\texttt{NoTrans}) \f]
40/// \f[ C := \alpha A^H B + \bar\alpha B^H A + \beta C \quad (\texttt{ConjTrans}) \f]
41/// Only the triangle of `C` named by `uplo` is written; the other is left as it
42/// was (use `MatrixView::hermitize` to mirror it). The diagonal comes out real.
43///
44/// The second term is the conjugate transpose of the first, not a copy with the
45/// operands swapped; that is what makes the sum Hermitian for any complex
46/// `alpha`, and is the whole difference from syr2k. `beta` scales an
47/// already-Hermitian `C` and so is real. Also callable as
48/// `her2k(ctx, A, B, C, Her2kOptions<T>{...})`, with owning `Matrix` arguments,
49/// and without `Ba` (taken from `ctx.backend()`).
50///
51/// Not table-selected. On `Backend::CUDA` the cuBLAS backend chooses by a fixed rule between one
52/// strided-batched gemm into scratch that carries both terms, folded into the `uplo` triangle,
53/// and a per-item `cublas?her2k` loop (the loop also serves a scratch that does not fit);
54/// `BATCHLAS_EXPAND_ROUTE` = `expand` | `loop` pins it. The host backend runs the per-item
55/// `cblas_?her2k` loop.
56///
57/// @tparam Ba backend the call is compiled for; must match `ctx`'s device
58/// @tparam T `std::complex<float>` or `std::complex<double>`
59/// @param ctx queue the work is enqueued on
60/// @param A batch of n x k (NoTrans) or k x n (ConjTrans) matrices; not modified
61/// @param B batch with the same shape as `A`; not modified
62/// @param C batch of n x n matrices; the `uplo` triangle is updated in place
63/// @param alpha complex scale of \f$A B^H\f$ (its conjugate scales the mirror term)
64/// @param beta real scale of the input `C`
65/// @param uplo which triangle of `C` is written
66/// @param transA `Transpose::NoTrans` or `Transpose::ConjTrans`
67/// @return event of the last enqueued kernel; `C` is valid once it completes
68/// @pre All operands have the same batch size and conforming shapes per item.
69/// @throws std::invalid_argument if the shapes do not conform (`Backend::CUDA`; the host
70/// backend checks inside its deferred host task and throws std::runtime_error there)
71/// @throws batchlas::NoRouteError in a build without the vendor BLAS
72/// for `Ba`: her2k has no native implementation.
73/// @note Not instantiated for `Backend::ROCM`.
74/// @see syr2k, herk, Her2kOptions, @ref md_docs_2cpp-api, @ref md_docs_2perf_2level3 (the rule's crossover)
75/// @ingroup api_blas3
76template <Backend Ba, ComplexScalar T>
77BATCHLAS_API Event her2k(Queue& ctx,
81 T alpha,
82 float_t<T> beta,
83 Uplo uplo,
84 Transpose transA);
85
86} // namespace batchlas
87
88
89namespace batchlas::backend {
90
91// DECLARATION ONLY: each vendor TU defines and instantiates it for its Backend;
92// the public her2k is defined in src/ops/level3/level3.cc.
93// evidence: docs/design/vendor-independence.md#the-entry-point-facade
94/// @brief Vendor-library implementation of her2k (cuBLAS, host BLAS).
95///
96/// Not an entry point: batchlas::her2k calls it. Same arguments and semantics.
97/// @ingroup api_dispatch
98template <Backend Back, ComplexScalar T>
99BATCHLAS_API Event her2k_vendor(Queue& ctx,
103 T alpha,
104 float_t<T> beta,
105 Uplo uplo,
106 Transpose transA);
107
108} // namespace batchlas::backend
109
110namespace batchlas {
111
112// Owning-argument (`f(ctx, Matrix, ...)`) and backend-deducing (`f(ctx, ...)`)
113// overloads; see blas/queue-dispatch.hh.
114
115
117
118} // 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 her2k(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, float_t< T > beta, Uplo uplo, Transpose transA)
Batched Hermitian rank-2k update.
Event her2k_vendor(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, float_t< T > beta, Uplo uplo, Transpose transA)
Vendor-library implementation of her2k (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.