trmm.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 trmm = Event(Queue&,
16 const MatrixView<T, MatrixFormat::Dense>&,
17 const MatrixView<T, MatrixFormat::Dense>&,
18 const MatrixView<T, MatrixFormat::Dense>&,
19 T, Side, Uplo, Transpose, Diag);
20
21// Spelled out, not aliased to sig::trmm: a vendor parameter order may differ
22// from the public one (trsm's alpha is last).
23template <typename T>
24using trmm_vendor = Event(Queue&,
25 const MatrixView<T, MatrixFormat::Dense>&,
26 const MatrixView<T, MatrixFormat::Dense>&,
27 const MatrixView<T, MatrixFormat::Dense>&,
28 T,
29 Side,
30 Uplo,
32 Diag);
33} // namespace sig
34
35
36/// @brief Batched triangular matrix-matrix multiply, out of place.
37///
38/// For every batch item computes
39/// \f[ C := \alpha \, \mathrm{op}(A) \, B \quad (\texttt{Side::Left}), \qquad
40/// C := \alpha \, B \, \mathrm{op}(A) \quad (\texttt{Side::Right}) \f]
41/// with `A` triangular (`uplo`), unit or non-unit diagonal (`diag`), and
42/// \f$\mathrm{op}(A)\f$ one of \f$A, A^T, A^H\f$. `B` and `C` are m x n; `A` is
43/// m x m (Left) or n x n (Right). Under `Diag::Unit` the stored diagonal of `A`
44/// is not read.
45///
46/// Unlike reference BLAS `?trmm`, which overwrites `B`, this writes the product
47/// into `C` and leaves `B` unmodified. trsm, by contrast, is in place.
48/// Also callable as `trmm(ctx, A, B, C, TrmmOptions<T>{...})`, with owning
49/// `Matrix` arguments, and without `Ba` (taken from `ctx.backend()`).
50///
51/// Each call takes a kernel family from the tuned table for its shape (@ref selection_tables):
52/// `triangular` (`Side::Left` only: row tiles that skip the zero half of `A`), `expand`
53/// (`op(A)` written densely into scratch leased from the queue's arena, then one
54/// strided-batched gemm) or `vendor` (the library's per-item `?trmm` loop). Pin one with
55/// `BATCHLAS_TRMM_ROUTE` = `auto` | `native` | `vendor` | `triangular` | `expand`.
56///
57/// @tparam Ba backend the call is compiled for; must match `ctx`'s device
58/// @tparam T scalar type: `float`, `double`, `std::complex<float>` or `std::complex<double>`
59/// @param ctx queue the work is enqueued on
60/// @param A batch of triangular matrices; only the `uplo` triangle is read
61/// @param B batch of m x n input matrices; not modified
62/// @param C batch of m x n output matrices; overwritten with the product
63/// @param alpha scale of the product
64/// @param side whether op(A) multiplies from the left or the right
65/// @param uplo which triangle of `A` holds the data
66/// @param transA op() applied to `A`
67/// @param diag whether `A` has an implicit unit diagonal
68/// @return event of the last enqueued kernel; `C` is valid once it completes
69/// @pre All operands have the same batch size and conforming shapes per item.
70/// @throws std::invalid_argument if the shapes do not conform, or if `BATCHLAS_TRMM_ROUTE` names
71/// a family that is not compiled for `T` or cannot run this call (`native` and `vendor`
72/// instead fall back to the tuned choice with a warning)
73/// @throws std::runtime_error if no family can run the call in a build with the vendor BLAS
74/// (a heterogeneous batch: every family takes one (n, k) per launch)
75/// @throws batchlas::NoRouteError in a build without the vendor BLAS for `Ba`,
76/// unless the call is `Backend::CUDA` on a GPU, with homogeneous operands,
77/// batch <= 65535 and a shape the `triangular` tiles or the `expand`
78/// scratch admit (@ref md_docs_2perf_2level3).
79/// @see trsm, TrmmOptions, @ref md_docs_2cpp-api
80/// @ingroup api_blas3
81template <Backend Ba, typename T>
82BATCHLAS_API Event trmm(Queue& ctx,
86 T alpha,
87 Side side,
88 Uplo uplo,
89 Transpose transA,
90 Diag diag);
91
92} // namespace batchlas
93
94
95namespace batchlas::backend {
96
97// Declaration only: each vendor TU defines and instantiates it for its Backend.
98// The public trmm is defined in src/ops/trmm/trmm.cc, outside every vendor TU.
99// evidence: docs/design/vendor-independence.md#the-entry-point-facade
100/// @brief Vendor-library implementation of trmm (cuBLAS, rocBLAS, host BLAS).
101///
102/// Not an entry point: batchlas::trmm calls it. Same arguments and semantics.
103/// @ingroup api_dispatch
104template <Backend Back, typename T>
105BATCHLAS_API Event trmm_vendor(Queue& ctx,
109 T alpha,
110 Side side,
111 Uplo uplo,
112 Transpose transA,
113 Diag diag);
114
115} // namespace batchlas::backend
116
117namespace batchlas {
118
119// Owning-argument (`f(ctx, Matrix, ...)`) and backend-deducing (`f(ctx, ...)`)
120// overloads; see blas/queue-dispatch.hh.
121
122
124
125} // 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 trmm(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, Side side, Uplo uplo, Transpose transA, Diag diag)
Batched triangular matrix-matrix multiply, out of place.
Event trmm_vendor(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, Side side, Uplo uplo, Transpose transA, Diag diag)
Vendor-library implementation of trmm (cuBLAS, rocBLAS, host BLAS).
Transpose
The operator op() applied to an operand: op(A) = A, A^T or A^H.
Definition enums.hh:171
Diag
Whether a triangular operand's diagonal is read or assumed to be one.
Definition enums.hh:303
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.