L2 — Matrix-Vector Operations#
General matrix-vector products (gemv), rank-1 updates (ger), the
strided / segmented gemv variants, and triangular solve / matvec
(trsv / trmv).
gemv#
Functions
-
template<typename T, bool TRANSPOSE = false, bool ROW_MAJOR = false, bool TRAILING_SYNC = true>
void gemv(uint32_t m, uint32_t n, T alpha, const T *A, const T *x, T beta, T *y)# Matrix-vector product:
y = alpha * A * x + beta * y(GEMV).Threads are distributed over the output rows of the
m×nmatrixA. SetTRANSPOSE=trueto computeAᵀ * xandROW_MAJOR=truefor row-majorA(Ais column-major by default). NumPy equivalent:y = alpha*A@x + beta*y(oralpha*A.T@x + beta*ywhen transposed).Unlike
gemm— where a row-major operand is just a transpose, so the only layout flag isROW_MAJOR_C— GEMV keeps a per-matrixROW_MAJORflag:TRANSPOSEalready selects the mathematical operation (A·xvsAᵀ·x), so it cannot also stand in for the storage order.TRANSPOSEandROW_MAJORare therefore independent. (This flag fully subsumes the formergemv_ex, which was justgemvwith the defaults removed and has been deleted.)- Template Parameters:
T – Scalar type (e.g.
float,double).TRANSPOSE – When true, multiply by
Aᵀinstead ofA(default false).ROW_MAJOR – When true,
Ais stored row-major (default false = column-major).
- Parameters:
m – Number of rows of
A.n – Number of columns of
A.alpha – Scalar multiplier on the product.
A – Input matrix of
m*nelements.x – Input vector (length
n, ormwhen transposed).beta – Scalar multiplier on the prior
y.y – In/out vector (length
m, ornwhen transposed).
-
template<typename T, bool TRANSPOSE = false, bool ROW_MAJOR = false, bool TRAILING_SYNC = true>
void gemv(uint32_t m, uint32_t n, T alpha, const T *A, const T *x, T *y)# Matrix-vector product:
y = alpha * A * x(GEMV), no-beta overload.Same as the full GEMV but overwrites
y(nobeta * yterm). SetTRANSPOSE=trueforAᵀ * xandROW_MAJOR=truefor row-majorA. NumPy equivalent:y = alpha*A@x(oralpha*A.T@xwhen transposed).- Template Parameters:
T – Scalar type (e.g.
float,double).TRANSPOSE – When true, multiply by
Aᵀinstead ofA(default false).ROW_MAJOR – When true,
Ais stored row-major (default false = column-major).
- Parameters:
m – Number of rows of
A.n – Number of columns of
A.alpha – Scalar multiplier on the product.
A – Input matrix of
m*nelements.x – Input vector (length
n, ormwhen transposed).y – Output vector (length
m, ornwhen transposed).
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE, bool ROW_MAJOR_A>
void gemv_impl_ct(uint32_t rank, uint32_t size, T alpha, const T *A, const T *x, T beta, T *y)#
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE, bool ROW_MAJOR_A>
void gemv_impl_ct(uint32_t rank, uint32_t size, T alpha, const T *A, const T *x, T *y)#
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool ROW_MAJOR = false, bool TRAILING_SYNC = true>
void gemv(T alpha, const T *A, const T *x, T beta, T *y)# Matrix-vector product:
y = alpha * A * x + beta * y(GEMV), compile-time size.Compile-time-
M,Noverload; the inner column loop is fully unrolled. SetTRANSPOSE=trueforAᵀ * xandROW_MAJOR=truefor row-majorA. NumPy equivalent:y = alpha*A@x + beta*y(oralpha*A.T@x + beta*y).- Template Parameters:
T – Scalar type (e.g.
float,double).M – Number of rows of
A(compile-time constant).N – Number of columns of
A(compile-time constant).TRANSPOSE – When true, multiply by
Aᵀinstead ofA(default false).ROW_MAJOR – When true,
Ais stored row-major (default false = column-major).
- Parameters:
alpha – Scalar multiplier on the product.
A – Input matrix of
M*Nelements.x – Input vector (length
N, orMwhen transposed).beta – Scalar multiplier on the prior
y.y – In/out vector (length
M, orNwhen transposed).
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool ROW_MAJOR = false, bool TRAILING_SYNC = true>
void gemv(T alpha, const T *A, const T *x, T *y)# Matrix-vector product:
y = alpha * A * x(GEMV), compile-time size, no-beta overload.Compile-time-
M,Noverload that overwritesy(nobeta * yterm). NumPy equivalent:y = alpha*A@x(oralpha*A.T@xwhen transposed).- Template Parameters:
T – Scalar type (e.g.
float,double).M – Number of rows of
A(compile-time constant).N – Number of columns of
A(compile-time constant).TRANSPOSE – When true, multiply by
Aᵀinstead ofA(default false).ROW_MAJOR – When true,
Ais stored row-major (default false = column-major).
- Parameters:
alpha – Scalar multiplier on the product.
A – Input matrix of
M*Nelements.x – Input vector (length
N, orMwhen transposed).y – Output vector (length
M, orNwhen transposed).
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool ROW_MAJOR = false>
void gemv(T alpha, const T *A, const T *x, T beta, T *y)# Matrix-vector product within one warp:
y = alpha * A * x + beta * y(GEMV), single-warp, compile-time size.Matrix-vector product on one thread:
y = alpha * A * x + beta * y(GEMV), compile-time size.One 32-lane warp computes the matvec with lanes striding over the output rows of the
M×NmatrixA(each row an independent inner product). SetTRANSPOSE=trueforAᵀ * xandROW_MAJOR=truefor row-majorA. No shared scratch, no__syncthreads; independent warps may run distinct problems concurrently. Full 32 lanes required.yis read only whenbeta != 0(BLAS semantics:beta == 0treatsyas write-only). NumPy equivalent:y = alpha*A@x + beta*y(oralpha*A.T@x + beta*ywhen transposed).One thread computes the matvec, walking the output rows of the
M×NmatrixAserially (each row an independent inner product). SetTRANSPOSE=trueforAᵀ * xandROW_MAJOR=truefor row-majorA. No shared scratch, no barriers, nothreadIdxread; operands may be thread-local register arrays.yis read only whenbeta != 0(BLAS semantics:beta == 0treatsyas write-only). NumPy equivalent:y = alpha*A@x + beta*y.- Template Parameters:
T – Scalar type (e.g.
float,double).M – Number of rows of
A(compile-time constant).N – Number of columns of
A(compile-time constant).TRANSPOSE – When true, multiply by
Aᵀinstead ofA(default false).ROW_MAJOR – When true,
Ais stored row-major (default false = column-major).T – Scalar type (e.g.
float,double).M – Number of rows of
A(compile-time constant).N – Number of columns of
A(compile-time constant).TRANSPOSE – When true, multiply by
Aᵀinstead ofA(default false).ROW_MAJOR – When true,
Ais stored row-major (default false = column-major).
- Parameters:
alpha – Scalar multiplier on the product.
A – Input matrix of
M*Nelements.x – Input vector (length
N, orMwhen transposed).beta – Scalar multiplier on the prior
y.y – In/out vector (length
M, orNwhen transposed).alpha – Scalar multiplier on the product.
A – Input matrix of
M*Nelements.x – Input vector (length
N, orMwhen transposed).beta – Scalar multiplier on the prior
y.y – In/out vector (length
M, orNwhen transposed).
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool ROW_MAJOR = false>
void gemv(T alpha, const T *A, const T *x, T *y)# Matrix-vector product within one warp:
y = alpha * A * x(GEMV), single-warp, compile-time size, implicit beta = 0.Matrix-vector product on one thread:
y = alpha * A * x(GEMV), compile-time size, no-beta overload.Overwrites
y(nobeta * yterm —yis never read, so it is safe to write into cold/uninitialized scratch). Otherwise identical to the beta overload above. No shared scratch, no__syncthreads. Full 32 lanes required. NumPy equivalent:y = alpha*A@x(oralpha*A.T@xwhen transposed).Overwrites
y(nobeta * yterm). NumPy equivalent:y = alpha*A@x(oralpha*A.T@xwhen transposed).- Template Parameters:
T – Scalar type (e.g.
float,double).M – Number of rows of
A(compile-time constant).N – Number of columns of
A(compile-time constant).TRANSPOSE – When true, multiply by
Aᵀinstead ofA(default false).ROW_MAJOR – When true,
Ais stored row-major (default false = column-major).T – Scalar type (e.g.
float,double).M – Number of rows of
A(compile-time constant).N – Number of columns of
A(compile-time constant).TRANSPOSE – When true, multiply by
Aᵀinstead ofA(default false).ROW_MAJOR – When true,
Ais stored row-major (default false = column-major).
- Parameters:
alpha – Scalar multiplier on the product.
A – Input matrix of
M*Nelements.x – Input vector (length
N, orMwhen transposed).y – Output vector (length
M, orNwhen transposed; overwritten).alpha – Scalar multiplier on the product.
A – Input matrix of
M*Nelements.x – Input vector (length
N, orMwhen transposed).y – Output vector (length
M, orNwhen transposed).
-
namespace warp
-
namespace thread
Contraction-parallel gemv (gemv_reduced)#
One warp owns each output element and its lanes split the contraction — the L2
sibling of gemm_reduced. See
Contraction-parallel ops (the *_reduced family).
Functions
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void gemv_reduced(T alpha, const T *A, const T *x, T beta, T *y)# Contraction-parallel GEMV:
y = alpha * op(A) * x + beta * y.Single-warp contraction-parallel GEMV:
y = alpha * op(A) * x + beta * y.Compile-time-size matrix-vector product that parallelizes the contraction across a warp’s lanes (one warp per output element) rather than one thread summing serially — the L2 analogue of
glass::gemm_reduced. Column-majorA. Thread-count invariant at any block size.Warp-per-problem analogue of
glass::gemv_reduced; one full 32-lane warp.- Template Parameters:
T – Scalar type.
M, N – A is M x N (column-major).
TRANSPOSE – If true, computes
Aᵀ x(output length N, contract over M); elseA x(length M, contract over N).TRAILING_SYNC – Emit a trailing
__syncthreads()(default true).T, M, N, TRANSPOSE – See glass::gemv_reduced.
TRAILING_SYNC – Emit a trailing
__syncwarp()(default true).
- Parameters:
alpha – Scalar on the product.
A – Input matrix (M x N, column-major).
x – Input vector (length N if !TRANSPOSE else M).
beta – Scalar on the existing y (read only when
beta != 0).y – In/out result (length M if !TRANSPOSE else N).
alpha, A, x, beta, y – See glass::gemv_reduced.
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void gemv_reduced(T alpha, const T *A, const T *x, T *y)# Contraction-parallel GEMV with implicit
beta = 0:y = alpha * op(A) * x.Single-warp contraction-parallel GEMV, implicit
beta = 0:y = alpha * op(A) * x.Overwrites y (not read). Otherwise identical to the beta overload.
- Template Parameters:
T, M, N, TRANSPOSE, TRAILING_SYNC – See the beta overload.
T, M, N, TRANSPOSE, TRAILING_SYNC – See the beta overload.
- Parameters:
alpha, A, x – See the beta overload.
y – Output (overwritten).
alpha, A, x, y – See the beta overload.
-
namespace gemv_reduced_detail#
-
namespace warp
Strided / segmented gemv#
Functions
-
template<typename T, uint32_t M, uint32_t N, uint32_t ROW_STRIDE = M>
void gemv_strided(T alpha, const T *A, const T *x, T beta, T *y)# Column-major GEMV with an explicit leading dimension:
y = alpha * A * x + beta * y.Compile-time-
M,Nmatrix-vector product whereA[i][j] = A[i + j*ROW_STRIDE], letting anM×Nmatrix be addressed inside a larger array (e.g. a spatial 6×6 embedded in a wider buffer, as in GRiD). WhenROW_STRIDE == Mthis is identical toglass::gemv<T,M,N>. NumPy equivalent:y = alpha*A@x + beta*y.- Template Parameters:
T – Scalar type (e.g.
float,double).M – Number of rows of
A(compile-time constant).N – Number of columns of
A(compile-time constant).ROW_STRIDE – Column-major leading dimension of
A(defaultM).
- Parameters:
alpha – Scalar multiplier on the product.
A – Input matrix, addressed at
A[row + col*ROW_STRIDE].x – Input vector of length
N.beta – Scalar multiplier on the prior
y.y – In/out vector of length
M.
-
template<typename T, uint32_t M, uint32_t N, uint32_t ROW_STRIDE = M>
void gemv_strided(T alpha, const T *A, const T *x, T *y)# Column-major GEMV with an explicit leading dimension:
y = alpha * A * x, no-beta overload.No-
betavariant of the strided GEMV that overwritesy, withA[i][j] = A[i + j*ROW_STRIDE]. NumPy equivalent:y = alpha*A@x.- Template Parameters:
T – Scalar type (e.g.
float,double).M – Number of rows of
A(compile-time constant).N – Number of columns of
A(compile-time constant).ROW_STRIDE – Column-major leading dimension of
A(defaultM).
- Parameters:
alpha – Scalar multiplier on the product.
A – Input matrix, addressed at
A[row + col*ROW_STRIDE].x – Input vector of length
N.y – Output vector of length
M.
Functions
-
template<typename T, uint32_t M, uint32_t N, uint32_t ROW_STRIDE = M, bool FUSE_SCALED_ADD = false, bool TRANSPOSE = false, bool ATOMIC_Y = false, typename IDX_T = int>
void gemv_segmented(uint32_t segments, const IDX_T *seg_a_off, const IDX_T *seg_x_off, const IDX_T *seg_y_off, const T *A, const T *x, T *y, T alpha, T beta, const IDX_T *seg_s_off = nullptr, const T *S = nullptr, const T *scalar = nullptr)# Segmented (batched) column-major GEMV:
y_seg = alpha*A_seg*x_seg + beta*y_segfor each segment.Computes
segmentsindependent small GEMVs concurrently in one block. EachA_segisM×N, column-major with leading dimensionROW_STRIDE, and base offsets into the flatA/x/yarrays come from the descriptor arrays. A single block-stride loop walks the flattenedsegments * OUT_ROWSoutputs (OUT_ROWS = TRANSPOSE ? N : M). Optional flags:TRANSPOSEcomputesAᵀ_seg · x_seg(the leaf→root direction);ATOMIC_Yaccumulates intoyviaatomicAddso segments may overlap (betais then ignored — pre-scaleyyourself);FUSE_SCALED_ADDfolds an extra per-segmentS * scalarterm into the singleystore (non-atomic path only).- Template Parameters:
T – Scalar type (e.g.
float,double).M – Rows per segment matrix (compile-time constant).
N – Columns per segment matrix (compile-time constant).
ROW_STRIDE – Column-major leading dimension of each
A_seg(defaultM).FUSE_SCALED_ADD – When true, add
S[seg]*scalar[seg]into the output (non-atomic only).TRANSPOSE – When true, each segment computes
Aᵀ_seg · x_seg.ATOMIC_Y – When true, accumulate into
ywithatomicAdd(overlap-safe).IDX_T – Index type of the offset descriptor arrays (default
int).
- Parameters:
segments – Number of independent GEMVs.
seg_a_off – Per-segment base element offsets of
A_segwithinA.seg_x_off – Per-segment base element offsets of
x_segwithinx.seg_y_off – Per-segment base element offsets of
y_segwithiny.A – Flat backing array of all segment matrices.
x – Flat backing array of all segment input vectors.
y – Flat backing array of all segment output vectors (in/out).
alpha – Scalar multiplier on each segment product.
beta – Scalar multiplier on the prior
y(ignored underATOMIC_Y).seg_s_off – Per-segment offsets of
S_segwithinS(FUSE only).S – Flat backing array for the fused scaled-add term (FUSE only).
scalar – Per-segment multiplier for the fused scaled-add (FUSE only).
-
template<typename T, uint32_t M, uint32_t N, uint32_t ROW_STRIDE = M, bool FUSE_SCALED_ADD = false, bool TRANSPOSE = false, bool ATOMIC_Y = false, typename IDX_T = int>
void gemv_segmented(uint32_t segments, const IDX_T *seg_a_off, const IDX_T *seg_x_off, const IDX_T *seg_y_off, const T *A, const T *x, T *y, T alpha, const IDX_T *seg_s_off = nullptr, const T *S = nullptr, const T *scalar = nullptr)# Segmented (batched) column-major GEMV, no-beta overload:
y_seg = alpha*A_seg*x_segper segment.No-
betavariant ofgemv_segmented: each segment overwrites itsy_seg(optionally plus the fused scaled-add) or computes the transpose. This also serves as theATOMIC_Yentry point, since atomic accumulate takes nobeta(see the full overload’s note on beta-under-atomic).- Template Parameters:
T – Scalar type (e.g.
float,double).M – Rows per segment matrix (compile-time constant).
N – Columns per segment matrix (compile-time constant).
ROW_STRIDE – Column-major leading dimension of each
A_seg(defaultM).FUSE_SCALED_ADD – When true, add
S[seg]*scalar[seg]into the output (non-atomic only).TRANSPOSE – When true, each segment computes
Aᵀ_seg · x_seg.ATOMIC_Y – When true, accumulate into
ywithatomicAdd(overlap-safe).IDX_T – Index type of the offset descriptor arrays (default
int).
- Parameters:
segments – Number of independent GEMVs.
seg_a_off – Per-segment base element offsets of
A_segwithinA.seg_x_off – Per-segment base element offsets of
x_segwithinx.seg_y_off – Per-segment base element offsets of
y_segwithiny.A – Flat backing array of all segment matrices.
x – Flat backing array of all segment input vectors.
y – Flat backing array of all segment output vectors (out, or accumulated under
ATOMIC_Y).alpha – Scalar multiplier on each segment product.
seg_s_off – Per-segment offsets of
S_segwithinS(FUSE only).S – Flat backing array for the fused scaled-add term (FUSE only).
scalar – Per-segment multiplier for the fused scaled-add (FUSE only).
ger#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void ger(uint32_t m, uint32_t n, T alpha, const T *x, const T *y, T *A)# Rank-1 update:
A += alpha * x * yᵀ(GER).Adds the scaled outer product of
xandyto them×ncolumn-major matrixA. NumPy equivalent:A += alpha * np.outer(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
m – Number of rows of
A(length ofx).n – Number of columns of
A(length ofy).alpha – Scalar multiplier on the outer product.
x – Input vector of length
m.y – Input vector of length
n.A – In/out matrix of
m*nelements (column-major).
-
template<typename T, uint32_t M, uint32_t N, bool TRAILING_SYNC = true>
void ger(T alpha, const T *x, const T *y, T *A)# Rank-1 update:
A += alpha * x * yᵀ(GER), compile-time size.Compile-time-
M,Noverload of the rank-1 update. NumPy equivalent:A += alpha * np.outer(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).M – Number of rows of
A/ length ofx(compile-time constant).N – Number of columns of
A/ length ofy(compile-time constant).
- Parameters:
alpha – Scalar multiplier on the outer product.
x – Input vector of length
M.y – Input vector of length
N.A – In/out matrix of
M*Nelements (column-major).
Triangular solve / matvec (trsv / trmv)#
Functions
-
template<typename T, FillMode FILL = FillMode::Lower, Diag DIAG = Diag::NonUnit, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void trsv(uint32_t n, const T *A, T *x)# Triangular solve
op(A) x = bin place (TRSV).Solves the triangular system for
x, overwriting the right-hand sidex(xholdsbon entry, the solution on return).Ais ann×ntriangular matrix stored column-major; only the triangle selected byFILLis read. SetTRANSPOSE=trueto solveAᵀx = bagainst that same stored triangle, andDIAG=Diag::Unitfor an implicit unit diagonal (the diagonal ofAis not read). Column-oriented elimination (forward whenop(A)is lower-triangular, i.e.(FILL==Lower) != TRANSPOSE, backward otherwise); ends with a trailing__syncthreads()so it composes without a defensive barrier. SciPy equivalent:x = scipy.linalg.solve_triangular(A, b, lower=(FILL==Lower), unit_diagonal=(DIAG==Unit), trans=(1 if TRANSPOSE else 0)).- Template Parameters:
T – Scalar type (e.g.
float,double).FILL – Which triangle of
Aholds the data (defaultFillMode::Lower).DIAG –
Diag::Unitfor an implicit unit diagonal (defaultDiag::NonUnit).TRANSPOSE – When true solve
Aᵀx = b(default false).
- Parameters:
n – Dimension (
Aisn×n,xhas lengthn).A – Triangular matrix (column-major,
n*nelements; read-only).x – In/out right-hand side; on return holds the solution.
-
template<typename T, uint32_t N, FillMode FILL = FillMode::Lower, Diag DIAG = Diag::NonUnit, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void trsv(const T *A, T *x)# Triangular solve
op(A) x = bin place (TRSV), compile-time size.Same as the runtime
trsvbut with the dimension as a template parameter. SciPy equivalent:x = scipy.linalg.solve_triangular(A, b, lower=(FILL==Lower), unit_diagonal=(DIAG==Unit), trans=(1 if TRANSPOSE else 0)).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Dimension (
AisN×N,xhas lengthN).FILL – Which triangle of
Aholds the data (defaultFillMode::Lower).DIAG –
Diag::Unitfor an implicit unit diagonal (defaultDiag::NonUnit).TRANSPOSE – When true solve
Aᵀx = b(default false).
- Parameters:
A – Triangular matrix (column-major,
N*Nelements; read-only).x – In/out right-hand side; on return holds the solution.
-
template<typename T, FillMode FILL = FillMode::Lower, Diag DIAG = Diag::NonUnit, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void trmv(uint32_t n, const T *A, const T *x, T *y)# Triangular matrix-vector product
y = op(A) x, out of place (TRMV).Computes the triangular matvec into a separate output
y(distinct from the inputx).Ais ann×ntriangular matrix stored column-major; only the triangle selected byFILLis read. SetTRANSPOSE=trueto computeAᵀxagainst that same stored triangle, andDIAG=Diag::Unitfor an implicit unit diagonal. No interior barrier: each thread owns disjoint outputs and reads the intactx. NumPy equivalent (lower, non-unit):y = np.tril(A) @ x(upper:np.triu(A) @ x; transposed:op(A).T @ x; unit: diagonal forced to 1).- Template Parameters:
T – Scalar type (e.g.
float,double).FILL – Which triangle of
Aholds the data (defaultFillMode::Lower).DIAG –
Diag::Unitfor an implicit unit diagonal (defaultDiag::NonUnit).TRANSPOSE – When true compute
Aᵀx(default false).
- Parameters:
n – Dimension (
Aisn×n,xandyhave lengthn).A – Triangular matrix (column-major,
n*nelements; read-only).x – Input vector (length
n; read-only).y – Output vector (length
n); must not aliasx.
-
template<typename T, uint32_t N, FillMode FILL = FillMode::Lower, Diag DIAG = Diag::NonUnit, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void trmv(const T *A, const T *x, T *y)# Triangular matrix-vector product
y = op(A) x, out of place (TRMV), compile-time size.Compile-time-
Noverload of the out-of-place TRMV. NumPy equivalent (lower, non-unit):y = np.tril(A) @ x.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Dimension (
AisN×N,xandyhave lengthN).FILL – Which triangle of
Aholds the data (defaultFillMode::Lower).DIAG –
Diag::Unitfor an implicit unit diagonal (defaultDiag::NonUnit).TRANSPOSE – When true compute
Aᵀx(default false).
- Parameters:
A – Triangular matrix (column-major,
N*Nelements; read-only).x – Input vector (length
N; read-only).y – Output vector (length
N); must not aliasx.
-
template<typename T>
inline constexpr std::size_t trmv_scratch_bytes(uint32_t n)# Scratch length (in elements of
T) required by the in-placetrmv.The in-place TRMV wrapper computes
op(A) xinto a temporary then copies it back overx; that temporary isnelements long.- Parameters:
n – Dimension passed to the in-place
trmv.- Returns:
Bytes the
scratchbuffer must hold.
-
template<typename T, FillMode FILL = FillMode::Lower, Diag DIAG = Diag::NonUnit, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void trmv(uint32_t n, const T *A, T *x, T *scratch)# Triangular matrix-vector product
x = op(A) x, in place (TRMV).In-place form: overwrites
xwithop(A) x. Becausetrmvreads the wholexwhile writing each output, the wrapper computes into a caller-providedscratch(lengthn, seetrmv_scratch_bytes) and copies the result back with a single barrier in between. Ends with a trailing__syncthreads(). NumPy equivalent (lower, non-unit):x = np.tril(A) @ x.- Template Parameters:
T – Scalar type (e.g.
float,double).FILL – Which triangle of
Aholds the data (defaultFillMode::Lower).DIAG –
Diag::Unitfor an implicit unit diagonal (defaultDiag::NonUnit).TRANSPOSE – When true compute
Aᵀx(default false).
- Parameters:
n – Dimension (
Aisn×n,xandscratchhave lengthn).A – Triangular matrix (column-major,
n*nelements; read-only).x – In/out vector (length
n); on return holdsop(A) x.scratch – Workspace of length
n(seetrmv_scratch_bytes).
-
template<typename T, uint32_t N, FillMode FILL = FillMode::Lower, Diag DIAG = Diag::NonUnit, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void trmv(const T *A, T *x, T *scratch)# Triangular matrix-vector product
x = op(A) x, in place (TRMV), compile-time size.Compile-time-
Noverload of the in-place TRMV. NumPy equivalent (lower, non-unit):x = np.tril(A) @ x.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Dimension (
AisN×N,xandscratchhave lengthN).FILL – Which triangle of
Aholds the data (defaultFillMode::Lower).DIAG –
Diag::Unitfor an implicit unit diagonal (defaultDiag::NonUnit).TRANSPOSE – When true compute
Aᵀx(default false).
- Parameters:
A – Triangular matrix (column-major,
N*Nelements; read-only).x – In/out vector (length
N); on return holdsop(A) x.scratch – Workspace of length
N(seetrmv_scratch_bytes).
-
template<typename T, uint32_t N, FillMode FILL = FillMode::Lower, Diag DIAG = Diag::NonUnit, bool TRANSPOSE = false>
void trsv(const T *A, T *x)# Triangular solve on one thread:
A x = bin place, compile-time size.One thread solves the
N×Ntriangular system by forward or back substitution (direction set byFILLandTRANSPOSE).Ais column-major and read-only;xis overwritten with the solution. No shared scratch, no barriers, nothreadIdxread; operands may be thread-local register arrays. SciPy equivalent:x = scipy.linalg.solve_triangular(A, b, lower=...).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Dimension (
AisN×N,xhas lengthN).FILL – Which triangle of
Aholds the data (defaultFillMode::Lower).DIAG –
Diag::Unitfor an implicit unit diagonal (defaultDiag::NonUnit).TRANSPOSE – When true solve
Aᵀx = b(default false).
- Parameters:
A – Triangular matrix (column-major,
N*Nelements; read-only).x – In/out right-hand side; on return holds the solution.
-
namespace thread
Cooperative-groups variants (glass::cgrps::)#
Functions
-
template<typename T, bool TRANSPOSE = false, bool ROW_MAJOR = false, bool TRAILING_SYNC = true>
void gemv(uint32_t m, uint32_t n, T alpha, const T *A, const T *x, T beta, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Matrix-vector multiply:
y = alpha * op(A) * x + beta * y(GEMV, cooperative-groups variant).Runtime-size, single-block; thread rank/size come from the cooperative group. NumPy equivalent:
y = alpha * A @ x + beta * y(orA.T @ xwhen TRANSPOSE).- Template Parameters:
T – Scalar type.
TRANSPOSE – If true, computes
A^T * x.ROW_MAJOR – Storage order of A (false = column-major).
- Parameters:
m, n – A is m x n.
alpha – Scalar multiplier on the product.
A – Input matrix.
x – Input vector.
beta – Scalar multiplier on the existing y (read only when
beta != 0).y – In/out result vector.
g – Cooperative thread group (defaults to the whole block).
-
template<typename T, bool TRANSPOSE = false, bool ROW_MAJOR = false, bool TRAILING_SYNC = true>
void gemv(uint32_t m, uint32_t n, T alpha, const T *A, const T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# GEMV with implicit
beta = 0:y = alpha * op(A) * x(cooperative-groups variant).Runtime-size overload that overwrites y (the existing y is not read). NumPy equivalent:
y = alpha * A @ x(orA.T @ xwhen TRANSPOSE).- Template Parameters:
T – Scalar type.
TRANSPOSE – If true, computes
A^T * x.ROW_MAJOR – Storage order of A (false = column-major).
- Parameters:
m, n – A is m x n.
alpha – Scalar multiplier on the product.
A – Input matrix.
x – Input vector.
y – Output result vector (overwritten).
g – Cooperative thread group (defaults to the whole block).
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool ROW_MAJOR = false, bool TRAILING_SYNC = true>
void gemv(T alpha, const T *A, const T *x, T beta, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size GEMV:
y = alpha * op(A) * x + beta * y(cooperative-groups variant).Dimensions baked in as template parameters. NumPy equivalent:
y = alpha * A @ x + beta * y(orA.T @ xwhen TRANSPOSE).- Template Parameters:
T – Scalar type.
M, N – Compile-time dimensions (A is M x N).
TRANSPOSE – If true, computes
A^T * x.ROW_MAJOR – Storage order of A (false = column-major).
- Parameters:
alpha – Scalar multiplier on the product.
A – Input matrix.
x – Input vector.
beta – Scalar multiplier on the existing y (read only when
beta != 0).y – In/out result vector.
g – Cooperative thread group (defaults to the whole block).
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool ROW_MAJOR = false, bool TRAILING_SYNC = true>
void gemv(T alpha, const T *A, const T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size GEMV with implicit
beta = 0:y = alpha * op(A) * x.Overwrites y (the existing y is not read). NumPy equivalent:
y = alpha * A @ x(orA.T @ xwhen TRANSPOSE).- Template Parameters:
T – Scalar type.
M, N – Compile-time dimensions (A is M x N).
TRANSPOSE – If true, computes
A^T * x.ROW_MAJOR – Storage order of A (false = column-major).
- Parameters:
alpha – Scalar multiplier on the product.
A – Input matrix.
x – Input vector.
y – Output result vector (overwritten).
g – Cooperative thread group (defaults to the whole block).
-
template<typename T, bool TRAILING_SYNC = true>
void ger(uint32_t m, uint32_t n, T alpha, const T *x, const T *y, T *A, cgrps::thread_group g = cgrps::this_thread_block())# Rank-1 update:
A += alpha * x * y^T(GER, cooperative-groups variant).Adds the scaled outer product of
xandyinto the column-major matrix A. NumPy equivalent:A += alpha * np.outer(x, y).- Template Parameters:
T – Scalar type.
- Parameters:
m, n – A is m x n (x length m, y length n).
alpha – Scalar multiplier on the outer product.
x, y – Input vectors.
A – In/out matrix (column-major).
g – Cooperative thread group (defaults to the whole block).
-
template<typename T, uint32_t M, uint32_t N, bool TRAILING_SYNC = true>
void ger(T alpha, const T *x, const T *y, T *A, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size rank-1 update:
A += alpha * x * y^T(GER, cooperative-groups variant).NumPy equivalent:
A += alpha * np.outer(x, y).- Template Parameters:
T – Scalar type.
M, N – Compile-time dimensions (A is M x N; x length M, y length N).
- Parameters:
alpha – Scalar multiplier on the outer product.
x, y – Input vectors.
A – In/out matrix (column-major).
g – Cooperative thread group (defaults to the whole block).
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void gemv_reduced(T alpha, const T *A, const T *x, T beta, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Contraction-parallel GEMV:
y = alpha * op(A) * x + beta * y(cooperative-groups variant).Cooperative-groups form of
glass::gemv_reduced. See it for semantics.- Template Parameters:
T, M, N, TRANSPOSE – See glass::gemv_reduced.
TRAILING_SYNC – Emit a trailing
g.sync()(default true).
- Parameters:
alpha, A, x, beta, y – See glass::gemv_reduced.
g – Cooperative thread group (defaults to the whole block; pass a warp-multiple group).
-
template<typename T, uint32_t M, uint32_t N, bool TRANSPOSE = false, bool TRAILING_SYNC = true>
void gemv_reduced(T alpha, const T *A, const T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Contraction-parallel GEMV with implicit
beta = 0:y = alpha * op(A) * x(cooperative-groups variant).- Template Parameters:
T, M, N, TRANSPOSE, TRAILING_SYNC – See the beta overload.
- Parameters:
alpha, A, x, y, g – See the beta overload.