geqrf.hh
Go to the documentation of this file.
1#pragma once
2
3/// @file
4/// @brief Batched Householder QR factorization (geqrf) and its workspace query.
5/// @ingroup api_qr
6
7#include <batchlas/export.hh>
8#include <stdexcept>
9#include <string>
10
16
17namespace batchlas {
18
19// Signature aliases for explicit instantiation; see BATCHLAS_INSTANTIATE in
20// src/util/template-instantiations.hh. Keep in sync with the declarations below.
21namespace sig {
22template <typename T>
23using geqrf = Event(Queue&,
24 const MatrixView<T, MatrixFormat::Dense>&,
26
27template <typename T>
28using geqrf_buffer_size = size_t(Queue&,
29 const MatrixView<T, MatrixFormat::Dense>&,
30 Span<T>);
31
32// Vendor signatures are spelled out, not aliased: a vendor parameter list can differ.
33template <typename T>
34using geqrf_vendor = Event(Queue&,
35 const MatrixView<T,MatrixFormat::Dense>&,
36 Span<T>,
38
39template <typename T>
40using geqrf_vendor_buffer_size = size_t(Queue&,
41 const MatrixView<T,MatrixFormat::Dense>&,
42 Span<T>);
43} // namespace sig
44
45/// @brief Validates the arguments of the positional geqrf() entry point.
46///
47/// Checks only non-negative extents. Rectangular A of either orientation is
48/// valid; the length of @p tau is checked by the option overloads.
49/// @throws batchlas::invalid_argument on negative extents
50/// @ingroup api_qr_lowlevel
51// Runs in src/ops/geqrf/geqrf.cc before the selection key reads A.rows()/A.cols().
52// Deliberately no squareness check (rectangular A is the point of geqrf), no
53// m >= n check (can_run sends a wide view to the vendor, which serves it) and no
54// tau-length check.
55// evidence: docs/design/vendor-independence.md#positional-validators-reject-only-what-no-route-can-serve
56template <typename T>
58 if (A.rows() < 0 || A.cols() < 0) {
60 "GEQRF: Matrix dimensions cannot be negative (rows=" +
61 std::to_string(A.rows()) + ", cols=" + std::to_string(A.cols()) + ")");
62 }
63}
64
65
66/// @brief Batched Householder QR factorization \f$ A = Q R \f$.
67///
68/// For every m x n batch item, as LAPACK `?geqrf`: on return the upper
69/// triangle (upper trapezoid if m < n) of A holds R, and the part below the
70/// diagonal holds the Householder vectors \f$ v_i \f$ with an implied unit
71/// leading entry. With \f$ k = \min(m, n) \f$,
72/// \f$ Q = H_1 H_2 \cdots H_k \f$, \f$ H_i = I - \tau_i v_i v_i^H \f$.
73/// Pass A and @p tau unchanged to orgqr() to form Q or to ormqr() to apply it.
74///
75/// Asynchronous: A and @p tau are readable after the returned event is waited on.
76/// @tparam B backend; the backend-deducing overload takes it from `ctx.backend()`
77/// @tparam T scalar type (float, double, std::complex<float>, std::complex<double>)
78/// @param ctx queue the kernels are enqueued on
79/// @param A batch of m x n matrices; overwritten with R and the reflectors
80/// @param tau reflector scalars, `k * batch` elements; item b's
81/// \f$ \tau_i \f$ is `tau[b * k + i]`
82/// @param work_space device-accessible scratch of at least geqrf_buffer_size() bytes
83/// @return event of the last enqueued kernel
84/// @pre `tau.size() >= min(m, n) * A.batch_size()` (checked by the option overloads only)
85/// @throws batchlas::invalid_argument on negative extents
86/// @throws batchlas::NoRouteError if no native kernel can run the shape (the
87/// native kernels need m >= n) and the vendor library was not built in
88/// @ingroup api_qr
89template <Backend B, typename T>
90BATCHLAS_API Event geqrf(Queue& ctx,
92 Span<T> tau,
93 Span<std::byte> work_space);
94
95/// @brief Workspace, in bytes, that geqrf() needs for this shape on this queue.
96/// @ingroup api_qr_lowlevel
97template <Backend B, typename T>
98BATCHLAS_API size_t geqrf_buffer_size(Queue& ctx,
100 Span<T> tau);
101
102} // namespace batchlas
103
104
105namespace batchlas::backend {
106
107/// @brief Vendor arm of geqrf(); called by geqrf() when it selects the `vendor`
108/// kernel family, not by users.
109/// @ingroup api_dispatch
110// DECLARATION ONLY: the public geqrf is defined in src/ops/geqrf/geqrf.cc.
111// evidence: docs/design/vendor-independence.md#the-entry-point-facade
112template <Backend B, typename T>
113BATCHLAS_API Event geqrf_vendor(Queue& ctx,
115 Span<T> tau,
116 Span<std::byte> work_space);
117
118
119/// @brief Workspace query of the vendor arm of geqrf().
120/// @ingroup api_dispatch
121template <Backend B, typename T>
122BATCHLAS_API size_t geqrf_vendor_buffer_size(Queue& ctx,
124 Span<T> tau);
125
126} // namespace batchlas::backend
127
128namespace batchlas {
129
130// Owning-container and backend-deducing overloads; see blas/queue-dispatch.hh.
131
134
135} // namespace batchlas
Non-owning view of a batch of matrices: the argument type of every entry point.
Definition matrix.hh:485
int rows() const
Rows per item (the capacity on a heterogeneous batch).
Definition matrix.hh:605
int cols() const
Columns per item (the capacity on a heterogeneous batch).
Definition matrix.hh:611
The call violates the API contract.
Definition error.hh:77
Enumerations, scalar traits and scalar concepts shared by every public header.
Event geqrf_vendor(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau, Span< std::byte > work_space)
Vendor arm of geqrf(); called by geqrf() when it selects the vendor kernel family,...
size_t geqrf_vendor_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau)
Workspace query of the vendor arm of geqrf().
size_t geqrf_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau)
Workspace, in bytes, that geqrf() needs for this shape on this queue.
void geqrf_validate_params(const MatrixView< T, MatrixFormat::Dense > &A)
Validates the arguments of the positional geqrf() entry point.
Definition geqrf.hh:57
Event geqrf(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau, Span< std::byte > work_space)
Batched Householder QR factorization .
The batched containers: Matrix (owning), MatrixView (non-owning), KernelMatrixView (device-side),...
Span(T *, typename Span< T >::size_t) -> Span< T >
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.
Non-owning view of size() contiguous elements of type T.
Definition sycl-span.hh:39
batchlas::Device, batchlas::Event and batchlas::Queue: where work runs and how it is ordered.
batchlas::Span, the non-owning pointer + length every entry point takes for 1-D data.