getrs.hh
Go to the documentation of this file.
1#pragma once
2
3/// @file
4/// @brief Batched solve with LU factors from getrf (getrs) and its workspace query.
5/// @ingroup api_factorizations
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 getrs = Event(Queue&,
24 const MatrixView<T, MatrixFormat::Dense>&,
25 const MatrixView<T, MatrixFormat::Dense>&,
27
28template <typename T>
29using getrs_buffer_size = size_t(Queue&,
30 const MatrixView<T, MatrixFormat::Dense>&,
31 const MatrixView<T, MatrixFormat::Dense>&,
32 Transpose);
33
34// Vendor signatures are spelled out, not aliased: a vendor parameter list can differ.
35template <typename T>
36using getrs_vendor = Event(Queue&,
37 const MatrixView<T,MatrixFormat::Dense>&,
38 const MatrixView<T,MatrixFormat::Dense>&,
42
43template <typename T>
44using getrs_vendor_buffer_size = size_t(Queue&,
45 const MatrixView<T,MatrixFormat::Dense>&,
46 const MatrixView<T,MatrixFormat::Dense>&,
47 Transpose);
48} // namespace sig
49
50
51/// @brief Validates the arguments of the positional getrs() entry point.
52///
53/// Checks only non-negative extents. Squareness of A, `A.rows() == B.rows()`,
54/// equal batch sizes and the pivot span's length are checked by the option
55/// overloads; on this path a non-conforming pair fails every native can_run and
56/// goes to the vendor.
57/// @throws batchlas::invalid_argument on negative extents
58/// @ingroup api_factorizations_lowlevel
59// Runs before selection in src/ops/getrs/getrs.cc reads A.rows()/B.cols().
60// Deliberately minimal; rejecting more would change a working call into an error.
61// evidence: docs/design/vendor-independence.md#positional-validators-reject-only-what-no-route-can-serve
62template <typename T>
65 if (A.rows() < 0 || A.cols() < 0 || B.rows() < 0 || B.cols() < 0) {
67 "GETRS: Matrix dimensions cannot be negative (A: rows=" +
68 std::to_string(A.rows()) + ", cols=" + std::to_string(A.cols()) +
69 "; B: rows=" + std::to_string(B.rows()) +
70 ", cols=" + std::to_string(B.cols()) + ")");
71 }
72}
73
74
75/// @brief Batched solve of \f$ \mathrm{op}(A) X = B \f$ using the LU factors from getrf().
76///
77/// A and @p pivots must be exactly what getrf() produced on the same backend
78/// (see getrf() for the packed 1-based int32 pivot format). \f$ \mathrm{op}(A) \f$
79/// is A, \f$ A^T \f$ or \f$ A^H \f$ for `NoTrans`, `Trans`, `ConjTrans`.
80/// B is overwritten with X. No singularity check is made: a zero U(i,i)
81/// (reported by getrf's `info`) produces infinities or NaNs in that item.
82///
83/// Asynchronous: B is readable after the returned event is waited on.
84/// @tparam Back backend; the backend-deducing overload takes it from `ctx.backend()`
85/// @tparam T scalar type (float, double, std::complex<float>, std::complex<double>)
86/// @param ctx queue the kernels are enqueued on
87/// @param A batch of n x n LU factors from getrf(); not modified
88/// @param B batch of n x nrhs right-hand sides; overwritten with X
89/// @param transA which of A, A^T, A^H to solve with
90/// @param pivots pivots from getrf(), `n * batch` entries
91/// @param work_space device-accessible scratch of at least getrs_buffer_size() bytes
92/// @return event of the last enqueued kernel
93/// @pre `A.rows() == A.cols() == B.rows()`, equal batch sizes, and
94/// `pivots.size() >= n * batch` (checked by the option overloads only)
95/// @throws batchlas::invalid_argument on negative extents
96/// @throws batchlas::NoRouteError if no native kernel can run the shape and the
97/// vendor library was not built in
98/// @see GetrsOptions
99/// @ingroup api_factorizations
100template <Backend Back, typename T>
101BATCHLAS_API Event getrs(Queue& ctx,
104 Transpose transA,
105 Span<int64_t> pivots,
106 Span<std::byte> work_space);
107
108/// @brief Workspace, in bytes, that getrs() needs for these operands on this queue.
109/// @ingroup api_factorizations_lowlevel
110template <Backend Back, typename T>
111BATCHLAS_API size_t getrs_buffer_size(Queue& ctx,
114 Transpose transA);
115
116} // namespace batchlas
117
118
119namespace batchlas::backend {
120
121/// @brief Vendor arm of getrs(); called by getrs() when it selects the `vendor`
122/// kernel family, not by users.
123/// @ingroup api_dispatch
124// DECLARATION ONLY: the public getrs is defined in src/ops/getrs/getrs.cc.
125// evidence: docs/design/vendor-independence.md#the-entry-point-facade
126template <Backend Back, typename T>
127BATCHLAS_API Event getrs_vendor(Queue& ctx,
130 Transpose transA,
131 Span<int64_t> pivots,
132 Span<std::byte> work_space);
133
134
135/// @brief Workspace query of the vendor arm of getrs().
136/// @ingroup api_dispatch
137template <Backend Back, typename T>
138BATCHLAS_API size_t getrs_vendor_buffer_size(Queue& ctx,
141 Transpose transA);
142
143} // namespace batchlas::backend
144
145namespace batchlas {
146
147// Owning-container and backend-deducing overloads; see blas/queue-dispatch.hh.
148
151
152} // 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.
size_t getrs_vendor_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Transpose transA)
Workspace query of the vendor arm of getrs().
Event getrs_vendor(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Transpose transA, Span< int64_t > pivots, Span< std::byte > work_space)
Vendor arm of getrs(); called by getrs() when it selects the vendor kernel family,...
Transpose
The operator op() applied to an operand: op(A) = A, A^T or A^H.
Definition enums.hh:171
void getrs_validate_params(const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B)
Validates the arguments of the positional getrs() entry point.
Definition getrs.hh:63
size_t getrs_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Transpose transA)
Workspace, in bytes, that getrs() needs for these operands on this queue.
Event getrs(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Transpose transA, Span< int64_t > pivots, Span< std::byte > work_space)
Batched solve of using the LU factors from getrf().
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.