symm.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 symm = 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::symm: a vendor parameter order may differ
22// from the public one (trsm's alpha is last).
23template <typename T>
24using symm_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 symmetric 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` symmetric: only the triangle named by `uplo` is read and the other
41/// is taken to be its transpose. `B` and `C` are m x n; `A` is m x m (Left) or
42/// n x n (Right).
43///
44/// Constrained to real `T`; the complex spelling is hemm. Also callable as
45/// `symm(ctx, A, B, C, SymmOptions<T>{...})`, with owning `Matrix` arguments,
46/// and without `Ba` (taken from `ctx.backend()`).
47///
48/// Each call takes a kernel family from the tuned table for its shape (@ref selection_tables):
49/// `expand` (mirror `A`'s triangle into scratch leased from the queue's arena, then one
50/// strided-batched gemm) or `vendor` (the library's per-item `?symm` loop). Pin one with
51/// `BATCHLAS_SYMM_ROUTE` = `auto` | `native` | `vendor` | `expand`.
52///
53/// @tparam Ba backend the call is compiled for; must match `ctx`'s device
54/// @tparam T `float` or `double`
55/// @param ctx queue the work is enqueued on
56/// @param A batch of symmetric matrices; only the `uplo` triangle is read
57/// @param B batch of m x n matrices; not modified
58/// @param C batch of m x n matrices; input scaled by `beta`, overwritten with the result
59/// @param alpha scale of the product
60/// @param beta scale of the input `C`
61/// @param side whether `A` multiplies from the left or the right
62/// @param uplo which triangle of `A` holds the data
63/// @return event of the last enqueued kernel; `C` is valid once it completes
64/// @pre All operands have the same batch size and conforming shapes per item.
65/// @throws std::invalid_argument if the shapes do not conform, or if `BATCHLAS_SYMM_ROUTE` names
66/// a family that is not compiled for `T` or cannot run this call (`native` and `vendor`
67/// instead fall back to the tuned choice with a warning)
68/// @throws std::runtime_error if no family can run the call in a build with the vendor BLAS
69/// (a heterogeneous batch: every family takes one (n, k) per launch)
70/// @throws batchlas::NoRouteError in a build without the vendor BLAS for `Ba`,
71/// unless the call is `Backend::CUDA` or `Backend::ROCM` on a GPU, with homogeneous operands,
72/// batch <= 65535 and an expansion scratch that fits (the `expand` choice;
73/// @ref md_docs_2perf_2level3).
74/// @note `Backend::ROCM` has no vendor symm: its `vendor` choice symmetrizes a copy of `A`
75/// and calls gemm, and blocks the host until it finishes.
76/// @see hemm, SymmOptions, @ref md_docs_2cpp-api
77/// @ingroup api_blas3
78template <Backend Ba, RealScalar T>
79BATCHLAS_API Event symm(Queue& ctx,
83 T alpha,
84 T beta,
85 Side side,
86 Uplo uplo);
87
88} // namespace batchlas
89
90
91namespace batchlas::backend {
92
93// Declaration only: each vendor TU defines and instantiates it for its Backend.
94// The public symm is defined in src/ops/symm/symm.cc, outside every vendor TU.
95// evidence: docs/design/vendor-independence.md#the-entry-point-facade
96/// @brief Vendor-library implementation of symm (cuBLAS, host BLAS).
97///
98/// Not an entry point: batchlas::symm calls it. Same arguments and semantics.
99/// @ingroup api_dispatch
100template <Backend Back, RealScalar T>
101BATCHLAS_API Event symm_vendor(Queue& ctx,
105 T alpha,
106 T beta,
107 Side side,
108 Uplo uplo);
109
110} // namespace batchlas::backend
111
112namespace batchlas {
113
114// Owning-argument (`f(ctx, Matrix, ...)`) and backend-deducing (`f(ctx, ...)`)
115// overloads; see blas/queue-dispatch.hh.
116
117
119
120} // 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 symm(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 symmetric matrix-matrix multiply.
Event symm_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 symm (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.