3#include <batchlas/export.hh>
59template <
typename T, BinaryOp Op>
92template <
typename T, BinaryOp Op>
257 const auto m = ta ? A.
cols() : A.
rows();
258 const auto n = tb ? B.
rows() : B.
cols();
260 (void)
gemm(ctx, A, B, C,
263 .transA = opts.transA,
264 .transB = opts.transB,
265 .precision = opts.precision});
285 (void)
potrf(ctx, L, {.uplo = uplo});
302 (void)
syev(ctx, work, W.
to_span(), {.jobz = JobType::NoEigenVectors, .uplo = uplo});
341 return Eigh<T>{std::move(W), std::move(V), std::move(info)};
367 const size_t n_pivots =
static_cast<size_t>(A.
rows()) *
static_cast<size_t>(A.
batch_size());
368 auto pivot_bytes = ctx.
workspace(n_pivots *
sizeof(int64_t));
369 Span<int64_t> pivots(
reinterpret_cast<int64_t*
>(pivot_bytes.data()), n_pivots);
382 (void)
getrf(ctx, LU, pivots);
383 (void)
getrs(ctx, LU, X, pivots, {.trans = trans});
447 return ::batchlas::inv(ctx, A);
457 return ::batchlas::transpose<T, MatrixFormat::Dense>(ctx, A);
467 return ::batchlas::norm<T, MatrixFormat::Dense>(ctx, A, norm_type);
478 return ::batchlas::cond(ctx, A, norm_type);
512 "linalg::svd: SvdVectors::None would leave U and Vh empty; use "
513 "::batchlas::gesvd directly for a values-only decomposition");
515 const int64_t m = A.
rows();
516 const int64_t n = A.
cols();
517 const int64_t k = std::min(m, n);
524 static_cast<int>(
svd_u_cols(vectors, m, k)), batch);
526 static_cast<int>(n), batch);
528 static_cast<size_t>(batch));
533 ctx, work, S.
to_span(), U, Vh, vectors, vectors));
539 return Svd<T>{std::move(U), std::move(S), std::move(Vh), std::move(info)};
560 return Lu<T>{std::move(LU), std::move(pivots)};
Non-owning view of a batch of matrices: the argument type of every entry point.
int rows() const
Rows per item (the capacity on a heterogeneous batch).
int cols() const
Columns per item (the capacity on a heterogeneous batch).
static Event copy(Queue &ctx, const MatrixView< T, MType > &dest, const MatrixView< T, MType > &src)
Enqueues dest := src on ctx, honouring each side's ld and stride.
int batch_size() const
Number of batch items.
Owning batch of batch_size() matrices of equal (capacity) shape.
The call violates the API contract.
A real floating-point scalar (float, double).
Enumerations, scalar traits and scalar concepts shared by every public header.
Batched general linear solve (gesv) by LU with partial pivoting.
Event gemm(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, T beta, Transpose transA, Transpose transB, ComputePrecision precision=ComputePrecision::Default)
Batched general matrix-matrix multiply.
size_t syev_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< typename base_type< T >::type > eigenvalues, JobType jobtype, Uplo uplo)
Workspace, in bytes, that syev() needs for the same arguments.
Event syev(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &descrA, Span< typename base_type< T >::type > eigenvalues, JobType jobtype, Uplo uplo, Span< std::byte > workspace, Span< int32_t > info)
Eigenvalues, and optionally eigenvectors, of a batch of symmetric/Hermitian matrices (LAPACK ?...
constexpr int64_t svd_u_cols(SvdVectors job, int64_t m, int64_t k)
Number of columns of U that job writes.
constexpr int64_t svd_vh_rows(SvdVectors job, int64_t n, int64_t k)
Number of rows of V^H that job writes.
Transpose
The operator op() applied to an operand: op(A) = A, A^T or A^H.
NormType
Matrix norm computed by norm and used by the condition estimators.
ComputePrecision
Internal compute precision of a GEMM (the cuBLAS cublasComputeType_t).
Uplo
Which triangle of a symmetric, Hermitian or triangular operand is referenced.
SvdVectors
Which singular vectors gesvd computes for one factor (LAPACK jobu / jobvt).
@ EigenVectors
Eigenvalues and eigenvectors (jobz = 'V').
@ Frobenius
sqrt(sum |a_ij|^2).
@ Default
The precision of the scalar type.
@ Upper
The upper triangle (i <= j).
@ Lower
The lower triangle (i >= j).
@ None
Do not compute this factor.
@ All
Full square factor (LAPACK 'A').
size_t posv_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Uplo uplo)
Workspace, in bytes, that posv() needs for these operands on this queue.
size_t gesv_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B)
Workspace, in bytes, that gesv() needs for these operands on this queue.
Event potrf(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &descrA, Uplo uplo, Span< std::byte > workspace, Span< int32_t > info)
Batched Cholesky factorization of Hermitian positive-definite matrices.
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().
Event getrf(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< int64_t > pivots, Span< std::byte > work_space, Span< int32_t > info)
Batched LU factorization with partial pivoting.
Event posv(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Uplo uplo, Span< std::byte > work_space, Span< int32_t > info)
Batched solve of for Hermitian positive-definite A.
Event gesv(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Span< int64_t > pivots, Span< std::byte > work_space, Span< int32_t > info)
Batched solve of by LU with partial pivoting.
Eigh< T > eigh(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Uplo uplo=kDefaultUplo)
Eigenvalues and eigenvectors of a symmetric/Hermitian A; A is not modified.
Matrix< T, MatrixFormat::Dense > transpose(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
Returns as a new matrix.
Matrix< T, MatrixFormat::Dense > subtract(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B)
Returns a new matrix (elementwise).
Matrix< T, MatrixFormat::Dense > divide(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B)
Returns a new matrix (elementwise).
Event triangular_mask_into(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &C, Uplo uplo, int64_t k=0)
A with everything outside the requested triangle zeroed.
Event divide_into(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C)
elementwise; see elementwise_into().
Matrix< T, MatrixFormat::Dense > multiply(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B)
Returns a new matrix (Hadamard, not matmul()).
Matrix< T, MatrixFormat::Dense > solve_spd(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Uplo uplo=Uplo::Lower)
Solves for Hermitian positive-definite A by Cholesky; returns X.
Event elementwise_into(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C)
Elementwise for = Op, per batch item.
Event scale(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, T alpha)
In-place scaling .
Lu< T > lu(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
LU factorisation with partial pivoting, ; A is not modified.
Matrix< T, MatrixFormat::Dense > matmul(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatmulOptions< T > &opts={})
Returns a new matrix .
Matrix< T, MatrixFormat::Dense > cholesky(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Uplo uplo=kDefaultUplo)
Returns the Cholesky factor of a Hermitian positive-definite A; A is not modified.
Event add_into(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C)
elementwise; see elementwise_into().
Event axpby_into(Queue &ctx, T alpha, const MatrixView< T, MatrixFormat::Dense > &A, T beta, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C)
, elementwise, per batch item.
Svd< T > svd(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, SvdVectors vectors=SvdVectors::All)
Singular value decomposition ; A is not modified.
UnifiedVector< typename base_type< T >::type > eigvalsh(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Uplo uplo=kDefaultUplo)
Returns the eigenvalues of a symmetric/Hermitian A, ascending per item; A is not modified.
UnifiedVector< typename base_type< T >::type > norm(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, NormType norm_type=NormType::Frobenius)
Returns one norm per batch item.
Matrix< T, MatrixFormat::Dense > solve(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, Transpose trans=Transpose::NoTrans)
Solves by LU with partial pivoting; returns X.
Matrix< T, MatrixFormat::Dense > triu(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, int64_t k=0)
Returns a copy of A with everything below diagonal k zeroed (NumPy triu).
Matrix< T, MatrixFormat::Dense > inv(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
Returns as a new matrix; A is not modified.
Matrix< T, MatrixFormat::Dense > scaled(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, T alpha)
Returns a new matrix ; A is not modified (scale() works in place).
BinaryOp
Elementwise operation selected by elementwise_into().
Event multiply_into(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C)
elementwise (Hadamard), not the matrix product; see matmul().
Matrix< T, MatrixFormat::Dense > add(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B)
Returns a new matrix (elementwise).
Matrix< T, MatrixFormat::Dense > tril(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, int64_t k=0)
Returns a copy of A with everything above diagonal k zeroed (NumPy tril).
constexpr Uplo kDefaultUplo
Default triangle of the linalg wrappers that read one.
Event subtract_into(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C)
elementwise; see elementwise_into().
UnifiedVector< T > cond(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, NormType norm_type=NormType::Frobenius)
Returns per item (eigenvalue-magnitude ratio for Spectral).
size_t gesvd_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< typename base_type< T >::type > singular_values, const MatrixView< T, MatrixFormat::Dense > &U, const MatrixView< T, MatrixFormat::Dense > &Vh, SvdVectors jobu, SvdVectors jobvh)
Workspace, in bytes, that gesvd() needs for the same arguments.
Event gesvd(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< typename base_type< T >::type > singular_values, const MatrixView< T, MatrixFormat::Dense > &U, const MatrixView< T, MatrixFormat::Dense > &Vh, SvdVectors jobu, SvdVectors jobvh, Span< std::byte > workspace, Span< int32_t > info)
Singular value decomposition of a batch of matrices (LAPACK ?gesvd).
The batched containers: Matrix (owning), MatrixView (non-owning), KernelMatrixView (device-side),...
void require_square(const char *fn, const char *name, const MV &A)
Matrix< T, MatrixFormat::Dense > like(const MatrixView< T, MatrixFormat::Dense > &A)
Option-struct spellings of the dense BLAS and LAPACK-style entry points.
Batched Hermitian positive-definite solve (posv) by Cholesky.
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.
void wait() const
Block until all work enqueued on this Queue has completed.
batchlas::WorkspaceLease workspace(size_t bytes)
Borrow bytes of device scratch from this Queue's arena.
Non-owning view of size() contiguous elements of type T.
Owning, growable array of T in USM shared memory (sycl::malloc_shared).
constexpr Span< T > to_span() const
A Span over the first size() elements.
UnifiedVector< typename base_type< T >::type > values
ascending, n per batch item
UnifiedVector< int32_t > info
Per-item convergence status: 0 converged, > 0 LAPACK-like.
Matrix< T, MatrixFormat::Dense > vectors
eigenvectors as columns, n x n per item
Matrix< T, MatrixFormat::Dense > factors
L and U packed; L's unit diagonal is implicit.
UnifiedVector< int64_t > pivots
rows * batch_size, in getrf()'s pivot format
Options for matmul(). Deliberately has no beta: C is freshly allocated.
ComputePrecision precision
internal compute type
T alpha
scale of the product
UnifiedVector< typename base_type< T >::type > values
k = min(m, n) per batch item
UnifiedVector< int32_t > info
Per-item convergence status, as Eigh::info. Always filled.
Matrix< T, MatrixFormat::Dense > Vh
n x n (All) or k x n (Thin)
Matrix< T, MatrixFormat::Dense > U
m x m (All) or m x k (Thin)
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.
batchlas::UnifiedVector, an owning growable array in USM shared memory.