orgqr.hh
Go to the documentation of this file.
1#pragma once
2
3/// @file
4/// @brief Batched formation of Q from geqrf reflectors (orgqr/ungqr) 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 orgqr = Event(Queue&,
24 const MatrixView<T, MatrixFormat::Dense>&,
26
27template <typename T>
28using orgqr_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 orgqr_vendor = Event(Queue&,
35 const MatrixView<T, MatrixFormat::Dense>&,
36 Span<T>,
38
39template <typename T>
40using orgqr_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 orgqr() entry point.
46///
47/// Checks only non-negative extents. `n <= m` is not checked: an n > m view is
48/// served by the vendor kernel, the only one whose `can_run` admits it
49/// (src/ops/orgqr/orgqr.cc). The length of `tau` is checked by the option overloads.
50/// @throws batchlas::invalid_argument on negative extents
51/// @ingroup api_qr_lowlevel
52// Deliberately no n <= m check: rejecting such a view is a user-visible behaviour change.
53// evidence: docs/design/vendor-independence.md#positional-validators-reject-only-what-no-route-can-serve
54template <typename T>
56 if (A.rows() < 0 || A.cols() < 0) {
58 "ORGQR: Matrix dimensions cannot be negative (rows=" +
59 std::to_string(A.rows()) + ", cols=" + std::to_string(A.cols()) + ")");
60 }
61}
62
63
64/// @brief Batched formation of the first n columns of Q from geqrf() output.
65///
66/// As LAPACK `?orgqr` / `?ungqr` with \f$ k = n \f$: A holds, below its
67/// diagonal, the reflectors written by geqrf() on an m x n matrix, and on
68/// return A holds the m x n matrix
69/// \f$ Q = H_1 H_2 \cdots H_n \f$ restricted to its first n columns, with
70/// orthonormal columns (\f$ Q^H Q = I \f$).
71///
72/// Asynchronous: A is readable after the returned event is waited on.
73/// @tparam B backend; the backend-deducing overload takes it from `ctx.backend()`
74/// @tparam T scalar type (float, double, std::complex<float>, std::complex<double>)
75/// @param ctx queue the kernels are enqueued on
76/// @param A batch of m x n geqrf() outputs, m >= n; overwritten with Q
77/// @param tau reflector scalars from geqrf(), `n * batch` elements
78/// @param workspace device-accessible scratch of at least orgqr_buffer_size() bytes
79/// @return event of the last enqueued kernel
80/// @pre `A.cols() <= A.rows()`; not checked by any overload
81/// @pre `tau.size() >= min(m, n) * batch` (checked by the option overloads only)
82/// @throws batchlas::invalid_argument on negative extents
83/// @throws batchlas::NoRouteError if no native kernel can run the shape (the
84/// blocked kernel needs a GPU queue, a homogeneous batch and n <= m)
85/// and the vendor library was not built in
86/// @ingroup api_qr
87template <Backend B, typename T>
88BATCHLAS_API Event orgqr(Queue& ctx,
90 Span<T> tau,
91 Span<std::byte> workspace);
92
93/// @brief Workspace, in bytes, that orgqr() needs for this shape on this queue.
94/// @ingroup api_qr_lowlevel
95template <Backend B, typename T>
96BATCHLAS_API size_t orgqr_buffer_size(Queue& ctx,
98 Span<T> tau);
99
100} // namespace batchlas
101
102
103namespace batchlas::backend {
104
105/// @brief Vendor arm of orgqr(); called by the public orgqr(), not by users.
106/// @ingroup api_dispatch
107// Declaration only: the public orgqr lives in src/ops/orgqr/orgqr.cc.
108// evidence: docs/design/vendor-independence.md#the-entry-point-facade
109template <Backend B, typename T>
110BATCHLAS_API Event orgqr_vendor(Queue& ctx,
112 Span<T> tau,
113 Span<std::byte> workspace);
114
115
116/// @brief Workspace query of the vendor arm of orgqr().
117/// @ingroup api_dispatch
118template <Backend B, typename T>
119BATCHLAS_API size_t orgqr_vendor_buffer_size(Queue& ctx,
121 Span<T> tau);
122
123} // namespace batchlas::backend
124
125namespace batchlas {
126
127// Owning-container and backend-deducing overloads; see blas/queue-dispatch.hh.
128
131
132} // 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 orgqr_vendor(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau, Span< std::byte > workspace)
Vendor arm of orgqr(); called by the public orgqr(), not by users.
size_t orgqr_vendor_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau)
Workspace query of the vendor arm of orgqr().
size_t orgqr_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau)
Workspace, in bytes, that orgqr() needs for this shape on this queue.
void orgqr_validate_params(const MatrixView< T, MatrixFormat::Dense > &A)
Validates the arguments of the positional orgqr() entry point.
Definition orgqr.hh:55
Event orgqr(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau, Span< std::byte > workspace)
Batched formation of the first n columns of Q from geqrf() output.
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.