syr2k.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 syr2k = Event(Queue&,
16 const MatrixView<T, MatrixFormat::Dense>&,
17 const MatrixView<T, MatrixFormat::Dense>&,
18 const MatrixView<T, MatrixFormat::Dense>&,
19 T, T, Uplo, Transpose);
20
21// Spelled out, not aliased to sig::syr2k: a vendor parameter order may differ
22// from the public one (trsm's alpha is last).
23template <typename T>
24using syr2k_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 Uplo,
31 Transpose);
32} // namespace sig
33
34
35/// @brief Batched symmetric rank-2k update.
36///
37/// For every batch item computes, with `A` and `B` n x k (`NoTrans`) or k x n
38/// (`Trans`) and `C` symmetric n x n,
39/// \f[ C := \alpha A B^T + \alpha B A^T + \beta C \quad (\texttt{NoTrans}) \f]
40/// \f[ C := \alpha A^T B + \alpha B^T A + \beta C \quad (\texttt{Trans}) \f]
41/// Only the triangle of `C` named by `uplo` is written; the other is left as it
42/// was (use `MatrixView::symmetrize` to mirror it).
43///
44/// Constrained to real `T`; the complex spelling is her2k. Also callable as
45/// `syr2k(ctx, A, B, C, Syr2kOptions<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/// `triangular` (`float` only: both products fused into 128-wide tiles of the requested half)
50/// or `vendor` (the library's per-item `?syr2k` loop). Pin one with
51/// `BATCHLAS_SYR2K_ROUTE` = `auto` | `native` | `vendor` | `triangular`.
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 n x k (NoTrans) or k x n (Trans) matrices; not modified
57/// @param B batch with the same shape as `A`; not modified
58/// @param C batch of n x n matrices; the `uplo` triangle is updated in place
59/// @param alpha scale of both products
60/// @param beta scale of the input `C`
61/// @param uplo which triangle of `C` is written
62/// @param transA `Transpose::NoTrans` or `Transpose::Trans`, applied to `A` and `B`
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; k > 0.
65/// @throws std::invalid_argument if the shapes do not conform, or if `BATCHLAS_SYR2K_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` on a GPU, `float`, not `ConjTrans`,
72/// with homogeneous operands and batch <= 65535 (the `triangular` tiles;
73/// @ref md_docs_2perf_2level3).
74/// @see her2k, syrk, Syr2kOptions, @ref md_docs_2cpp-api
75/// @ingroup api_blas3
76template <Backend Ba, RealScalar T>
77BATCHLAS_API Event syr2k(Queue& ctx,
81 T alpha,
82 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 syr2k is defined in src/ops/syr2k/syr2k.cc, outside every vendor TU.
93// evidence: docs/design/vendor-independence.md#the-entry-point-facade
94/// @brief Vendor-library implementation of syr2k (cuBLAS, rocBLAS, host BLAS).
95///
96/// Not an entry point: batchlas::syr2k calls it. Same arguments and semantics.
97/// @ingroup api_dispatch
98template <Backend Back, RealScalar T>
99BATCHLAS_API Event syr2k_vendor(Queue& ctx,
103 T alpha,
104 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 syr2k(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, T beta, Uplo uplo, Transpose transA)
Batched symmetric rank-2k update.
Event syr2k_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, Uplo uplo, Transpose transA)
Vendor-library implementation of syr2k (cuBLAS, rocBLAS, 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
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.