L1 — Vector Operations#
Single-block vector primitives: scaled sums, copies, scaling, dot products,
reductions, norms, and elementwise logic. Pure-SIMT (glass::block::, bare
glass::) routines are
listed first, followed by the cooperative-groups (glass::cgrps::) variants.
Single-warp (glass::warp::) variants, where they exist, render inline beside
their block-scoped sibling (e.g. under reduce); see Warp-scoped operations (glass::warp::).
axpy / axpby#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void axpy(uint32_t n, T alpha, T *x, T *y)# Scaled vector sum:
y = alpha * x + y(AXPY).Each thread in the block strides over the
nelements. NumPy equivalent:y += alpha * x.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
alpha – Scalar multiplier.
x – Input vector of length
n.y – In/out vector of length
n(overwritten with the result).
-
template<typename T, bool TRAILING_SYNC = true>
void axpy(uint32_t n, T alpha, T *x, T *y, T *z)# Scaled vector sum into a third buffer:
z = alpha * x + y(AXPY).Out-of-place variant that leaves
xandyuntouched. NumPy equivalent:z = alpha * x + y.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
alpha – Scalar multiplier.
x – Input vector of length
n.y – Input vector of length
n.z – Output vector of length
n(overwritten with the result).
-
template<typename T, bool TRAILING_SYNC = true>
void axpby(uint32_t n, T alpha, T *x, T beta, T *y, T *z)# Doubly-scaled vector sum:
z = alpha * x + beta * y(AXPBY).Out-of-place generalization of AXPY with an independent scale on
y. NumPy equivalent:z = alpha * x + beta * y.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
alpha – Scalar multiplier on
x.x – Input vector of length
n.beta – Scalar multiplier on
y.y – Input vector of length
n.z – Output vector of length
n(overwritten with the result).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void axpy(T alpha, T *x, T *y)# Scaled vector sum:
y = alpha * x + y(AXPY), compile-time size.Compile-time-
Noverload of AXPY. NumPy equivalent:y += alpha * x.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Scalar multiplier.
x – Input vector of length
N.y – In/out vector of length
N(overwritten with the result).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void axpy(T alpha, T *x, T *y, T *z)# Scaled vector sum into a third buffer:
z = alpha * x + y(AXPY), compile-time size.Compile-time-
Nout-of-place overload. NumPy equivalent:z = alpha * x + y.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Scalar multiplier.
x – Input vector of length
N.y – Input vector of length
N.z – Output vector of length
N(overwritten with the result).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void axpby(T alpha, T *x, T beta, T *y, T *z)# Doubly-scaled vector sum:
z = alpha * x + beta * y(AXPBY), compile-time size.Compile-time-
Noverload of AXPBY. NumPy equivalent:z = alpha * x + beta * y.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Scalar multiplier on
x.x – Input vector of length
N.beta – Scalar multiplier on
y.y – Input vector of length
N.z – Output vector of length
N(overwritten with the result).
-
template<typename T>
void axpy(uint32_t n, T alpha, T *x, T *y)# Scaled vector sum within one warp:
y = alpha * x + y(AXPY), single-warp.Scaled vector sum on one thread:
y = alpha * x + y(AXPY), single-thread.One 32-lane warp computes the update with lanes striding over the
nelements. Elementwise, no inter-lane comms, no shared scratch, no__syncthreads. Independent warps may run distinct problems concurrently. Full 32 lanes required. NumPy equivalent:y += alpha * x.One thread walks the
nelements serially. No shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy equivalent:y += alpha * x.- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Number of elements.
alpha – Scalar multiplier.
x – Input vector of length
n.y – In/out vector of length
n(overwritten with the result).n – Number of elements.
alpha – Scalar multiplier.
x – Input vector of length
n.y – In/out vector of length
n(overwritten with the result).
-
template<typename T, uint32_t N>
void axpy(T alpha, T *x, T *y)# Scaled vector sum within one warp:
y = alpha * x + y(AXPY), single-warp, compile-time size.Scaled vector sum on one thread:
y = alpha * x + y(AXPY), single-thread, compile-time size.Compile-time-
Noverload of the single-warp AXPY. Elementwise, no shared scratch, no__syncthreads. NumPy equivalent:y += alpha * x.Compile-time-
Noverload; the trip count folds and the loop unrolls, soxandymay be thread-local register arrays. NumPy equivalent:y += alpha * x.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Scalar multiplier.
x – Input vector of length
N.y – In/out vector of length
N(overwritten with the result).alpha – Scalar multiplier.
x – Input vector of length
N.y – In/out vector of length
N(overwritten with the result).
-
namespace warp
-
namespace thread#
Row-strided AXPY: Y[r + c*Y_RS] += alpha * X[r + c*X_RS] over an M×N block.
The AXPY analogue of gemv_strided — adds an M×N (column-major) block of X into a same-shaped block of Y when the two live inside wider buffers with different leading dimensions (X_RS, Y_RS). PDDP packs a 14×14 update into a 21-lead buffer top-left (Y_RS=21, X_RS=14). Each (r,c) element is written by exactly one thread/lane, so there is no race and the op is trivially thread-count invariant. Block + warp::.
Functions
-
template<typename T, uint32_t M, uint32_t N, uint32_t Y_RS, uint32_t X_RS = M, bool TRAILING_SYNC = true>
void axpy_strided(T alpha, const T *X, T *Y)# Row-strided AXPY
Y[r + c*Y_RS] += alpha * X[r + c*X_RS]over an M×N block.Row-strided AXPY within one warp:
Y[r + c*Y_RS] += alpha * X[r + c*X_RS].Column-major;
Xis addressed at leading dimensionX_RS(defaultM),YatY_RS. WhenX_RS == MandY_RS == Mthis is a plainglass::axpyover theM*Ncontiguous elements. NumPy:Y[:M,:N] += alpha * X[:M,:N](col-major lds).Single-warp form of
axpy_strided: one 32-lane warp strides over theM*Nblock elements. Each element written once; no inter-lane comms, no shared scratch.TRAILING_SYNCgates a closing__syncwarp(). Full 32 lanes required; independent warps may run distinct problems concurrently.- Template Parameters:
T – Scalar type (e.g.
float,double).M – Rows of the block.
N – Columns of the block.
Y_RS – Column-major leading dimension of
Y.X_RS – Column-major leading dimension of
X(defaultM).TRAILING_SYNC – Emit a trailing
__syncthreads()(default true).T – Scalar type.
M, N – Block shape.
Y_RS – Leading dimension of
Y.X_RS – Leading dimension of
X(defaultM).TRAILING_SYNC – Emit a trailing
__syncwarp()(default true).
- Parameters:
alpha – Scalar multiplier on
X.X – Input block, addressed at
X[r + c*X_RS](read-only).Y – In/out block, addressed at
Y[r + c*Y_RS].alpha – Scalar multiplier on
X.X – Input block, addressed at
X[r + c*X_RS](read-only).Y – In/out block, addressed at
Y[r + c*Y_RS].
-
template<typename T, uint32_t M, uint32_t N, uint32_t Y_RS, uint32_t X_RS = M>
void axpy_strided(T alpha, const T *X, T *Y)# Row-strided AXPY on one thread:
Y[r + c*Y_RS] += alpha * X[r + c*X_RS], single-thread.One thread adds the column-major
M×Nblock ofX(leading dimensionX_RS) into the same-shaped block ofY(leading dimensionY_RS), walking the elements serially. No shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy:Y[:M,:N] += alpha * X[:M,:N](col-major lds).- Template Parameters:
T – Scalar type (e.g.
float,double).M – Rows of the block.
N – Columns of the block.
Y_RS – Column-major leading dimension of
Y.X_RS – Column-major leading dimension of
X(defaultM).
- Parameters:
alpha – Scalar multiplier on
X.X – Input block, addressed at
X[r + c*X_RS](read-only).Y – In/out block, addressed at
Y[r + c*Y_RS].
-
namespace warp
-
namespace thread
copy#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void copy(uint32_t n, T *x, T *y)# Vector copy:
y = x(COPY).Each thread in the block strides over the
nelements. NumPy equivalent:y = x.copy().- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Input vector of length
n.y – Output vector of length
n(overwritten with a copy ofx).
-
template<typename T, bool TRAILING_SYNC = true>
void copy(uint32_t n, T alpha, T *x, T *y)# Scaled vector copy:
y = alpha * x.Copies
xintoywhile scaling byalpha. NumPy equivalent:y = alpha * x.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
alpha – Scalar multiplier.
x – Input vector of length
n.y – Output vector of length
n(overwritten with the result).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void copy(T *x, T *y)# Vector copy:
y = x(COPY), compile-time size.Compile-time-
Noverload of copy. NumPy equivalent:y = x.copy().- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N.y – Output vector of length
N(overwritten with a copy ofx).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void copy(T alpha, T *x, T *y)# Scaled vector copy:
y = alpha * x, compile-time size.Compile-time-
Noverload of scaled copy. NumPy equivalent:y = alpha * x.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Scalar multiplier.
x – Input vector of length
N.y – Output vector of length
N(overwritten with the result).
-
template<typename T>
void copy(uint32_t n, T *x, T *y)# Vector copy within one warp:
y = x(COPY), single-warp.Vector copy on one thread:
y = x(COPY), single-thread.One 32-lane warp copies the vector with lanes striding over the
nelements. Elementwise, no inter-lane comms, no shared scratch, no__syncthreads. Independent warps may run distinct problems concurrently. Full 32 lanes required. NumPy equivalent:y = x.copy().One thread walks the
nelements serially. No shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy equivalent:y = x.copy().- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Number of elements.
x – Input vector of length
n.y – Output vector of length
n(overwritten with a copy ofx).n – Number of elements.
x – Input vector of length
n.y – Output vector of length
n(overwritten with a copy ofx).
-
template<typename T, uint32_t N>
void copy(T *x, T *y)# Vector copy within one warp:
y = x(COPY), single-warp, compile-time size.Vector copy on one thread:
y = x(COPY), single-thread, compile-time size.Compile-time-
Noverload of the single-warp copy. Elementwise, no shared scratch, no__syncthreads. NumPy equivalent:y = x.copy().Compile-time-
Noverload; the trip count folds and the loop unrolls, soxandymay be thread-local register arrays. NumPy equivalent:y = x.copy().- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N.y – Output vector of length
N(overwritten with a copy ofx).x – Input vector of length
N.y – Output vector of length
N(overwritten with a copy ofx).
-
namespace warp
-
namespace thread
Row-strided COPY: Y[r + c*Y_RS] = alpha * X[r + c*X_RS] over an M×N block.
The COPY (overwrite) sibling of axpy_strided — moves a column-major M×N block of X into a same-shaped block of Y when the two live inside wider buffers with different leading dimensions (X_RS, Y_RS), optionally scaling by alpha. Each (r,c) element is written by exactly one thread/lane (no race, trivially thread-count invariant). Block + warp::.
Functions
-
template<typename T, uint32_t M, uint32_t N, uint32_t Y_RS, uint32_t X_RS = M, bool TRAILING_SYNC = true>
void copy_strided(T alpha, const T *X, T *Y)# Row-strided COPY
Y[r + c*Y_RS] = alpha * X[r + c*X_RS]over an M×N block.Row-strided COPY within one warp:
Y[r + c*Y_RS] = alpha * X[r + c*X_RS].Column-major;
Xat leading dimensionX_RS(defaultM),YatY_RS. WhenX_RS == MandY_RS == Mthis is a plain scaledglass::copyoverM*Ncontiguous elements. NumPy:Y[:M,:N] = alpha * X[:M,:N](col-major lds).Single-warp form of
copy_strided: one 32-lane warp strides over theM*Nblock elements. Each element written once; no inter-lane comms, no shared scratch.TRAILING_SYNCgates a closing__syncwarp(). Full 32 lanes required; independent warps may run distinct problems concurrently.- Template Parameters:
T – Scalar type (e.g.
float,double).M – Rows of the block.
N – Columns of the block.
Y_RS – Column-major leading dimension of
Y.X_RS – Column-major leading dimension of
X(defaultM).TRAILING_SYNC – Emit a trailing
__syncthreads()(default true).T – Scalar type.
M, N – Block shape.
Y_RS – Leading dimension of
Y.X_RS – Leading dimension of
X(defaultM).TRAILING_SYNC – Emit a trailing
__syncwarp()(default true).
- Parameters:
alpha – Scalar multiplier on
X.X – Input block, addressed at
X[r + c*X_RS](read-only).Y – Output block, addressed at
Y[r + c*Y_RS](overwritten).alpha – Scalar multiplier on
X.X – Input block, addressed at
X[r + c*X_RS](read-only).Y – Output block, addressed at
Y[r + c*Y_RS](overwritten).
-
template<typename T, uint32_t M, uint32_t N, uint32_t Y_RS, uint32_t X_RS = M>
void copy_strided(T alpha, const T *X, T *Y)# Row-strided COPY on one thread:
Y[r + c*Y_RS] = alpha * X[r + c*X_RS], single-thread.One thread moves the column-major
M×Nblock ofX(leading dimensionX_RS) into the same-shaped block ofY(leading dimensionY_RS), scaling byalphaand walking the elements serially. No shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy:Y[:M,:N] = alpha * X[:M,:N](col-major lds).- Template Parameters:
T – Scalar type (e.g.
float,double).M – Rows of the block.
N – Columns of the block.
Y_RS – Column-major leading dimension of
Y.X_RS – Column-major leading dimension of
X(defaultM).
- Parameters:
alpha – Scalar multiplier on
X.X – Input block, addressed at
X[r + c*X_RS](read-only).Y – Output block, addressed at
Y[r + c*Y_RS](overwritten).
-
namespace warp
-
namespace thread
scal#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void scal(uint32_t n, T alpha, T *x)# Scale a vector in place:
x = alpha * x(SCAL).NumPy equivalent:
x *= alpha.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
alpha – Scalar multiplier.
x – In/out vector of length
n(overwritten with the result).
-
template<typename T, bool TRAILING_SYNC = true>
void scal(uint32_t n, T alpha, T *x, T *y)# Scale a vector into a second buffer:
y = alpha * x(SCAL).Out-of-place variant that leaves
xuntouched. NumPy equivalent:y = alpha * x.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
alpha – Scalar multiplier.
x – Input vector of length
n.y – Output vector of length
n(overwritten with the result).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void scal(T alpha, T *x)# Scale a vector in place:
x = alpha * x(SCAL), compile-time size.Compile-time-
Noverload. NumPy equivalent:x *= alpha.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Scalar multiplier.
x – In/out vector of length
N(overwritten with the result).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void scal(T alpha, T *x, T *y)# Scale a vector into a second buffer:
y = alpha * x(SCAL), compile-time size.Compile-time-
Nout-of-place overload. NumPy equivalent:y = alpha * x.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Scalar multiplier.
x – Input vector of length
N.y – Output vector of length
N(overwritten with the result).
-
template<typename T>
void scal(uint32_t n, T alpha, T *x)# Scale a vector in place within one warp:
x = alpha * x(SCAL), single-warp.Scale a vector in place on one thread:
x = alpha * x(SCAL), single-thread.One 32-lane warp scales the vector with lanes striding over the
nelements. Elementwise, no inter-lane comms, no shared scratch, no__syncthreads. Independent warps may run distinct problems concurrently. Full 32 lanes required. NumPy equivalent:x *= alpha.One thread walks the
nelements serially. No shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy equivalent:x *= alpha.- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Number of elements.
alpha – Scalar multiplier.
x – In/out vector of length
n(overwritten with the result).n – Number of elements.
alpha – Scalar multiplier.
x – In/out vector of length
n(overwritten with the result).
-
template<typename T, uint32_t N>
void scal(T alpha, T *x)# Scale a vector in place within one warp:
x = alpha * x(SCAL), single-warp, compile-time size.Scale a vector in place on one thread:
x = alpha * x(SCAL), single-thread, compile-time size.Compile-time-
Noverload of the single-warp scale. Elementwise, no shared scratch, no__syncthreads. NumPy equivalent:x *= alpha.Compile-time-
Noverload; the trip count folds and the loop unrolls, soxmay be a thread-local register array. NumPy equivalent:x *= alpha.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Scalar multiplier.
x – In/out vector of length
N(overwritten with the result).alpha – Scalar multiplier.
x – In/out vector of length
N(overwritten with the result).
-
namespace warp
-
namespace thread
swap#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void swap(uint32_t n, T *x, T *y)# Swap two vectors element-wise:
x ↔ y(SWAP).Exchanges the contents of
xandy.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – In/out vector of length
n.y – In/out vector of length
n.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void swap(T *x, T *y)# Swap two vectors element-wise:
x ↔ y(SWAP), compile-time size.Compile-time-
Noverload of swap.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N.y – In/out vector of length
N.
rot / rotg (Givens plane rotation)#
Apply (rot, BLAS SROT/DROT: x = c*x + s*y, y = c*y - s*x; block +
glass::warp::) and generate (rotg, BLAS SROTG/DROTG semantics, the
overflow-safe scaled form; a __host__ __device__ scalar helper).
Givens plane rotation: apply (rot, BLAS SROT/DROT) and generate (rotg, BLAS SROTG/DROTG).
rot applies the rotation [c s; -s c] to a vector pair in place: x[i] = c*x[i] + s*y[i], y[i] = c*y[i] - s*x_old[i]. Each element index is owned by exactly one thread, which reads BOTH old values into registers before writing — no staging, no cross-thread hazard, trivially thread-count invariant. Block + warp::.
rotg is a __host__ __device__ SCALAR helper (one caller, no cooperation): given (a, b) it computes (c, s, r) with c*a + s*b = r and c*b - s*a = 0 (so applying rot with the returned (c, s) to the pair (a, b) zeroes b), using the overflow-safe scaled form of the reference BLAS DROTG.
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void rot(uint32_t n, T *x, T *y, T c, T s)# Apply a Givens plane rotation to a vector pair in place (ROT).
x[i] = c*x[i] + s*y[i],y[i] = c*y[i] - s*x_old[i]for alli— the BLAS SROT/DROT update. NumPy equivalent:x, y = c*x + s*y, c*y - s*x.- Template Parameters:
T – Scalar type (e.g.
float,double).TRAILING_SYNC – Emit a trailing
__syncthreads()(default true).
- Parameters:
n – Number of elements.
x – In/out vector of length
n.y – In/out vector of length
n.c – Rotation cosine.
s – Rotation sine.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void rot(T *x, T *y, T c, T s)# Apply a Givens plane rotation in place (ROT), compile-time size.
Compile-time-
Noverload. NumPy equivalent:x, y = c*x + s*y, c*y - s*x.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
TRAILING_SYNC – Emit a trailing
__syncthreads()(default true).
- Parameters:
x – In/out vector of length
N.y – In/out vector of length
N.c – Rotation cosine.
s – Rotation sine.
-
template<typename T>
void rotg(T a, T b, T &c, T &s, T &r)# Generate a Givens plane rotation (ROTG) —
__host__ __device__scalar helper.Given
(a, b), computes(c, s, r)such that[c s; -s c] @ [a; b] = [r; 0]— i.e.c = a/r,s = b/r,r = ±sqrt(a² + b²)with the reference-BLAS DROTG sign convention (the sign of the larger-magnitude input) and its overflow-safe scaling (scale = |a| + |b|; the squares are formed ona/scale,b/scale).(a, b) = (0, 0)returns(c, s, r) = (1, 0, 0). Scalar: call from one thread (or redundantly from all — it is deterministic), or on the host. SciPy equivalent:(c, s), r = scipy.linalg.blas.drotg(a, b), np.hypot(a, b)(up to the sign convention).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
a – First component.
b – Second component (the one the rotation annihilates).
c – Output rotation cosine.
s – Output rotation sine.
r – Output rotated magnitude (
c*a + s*b).
-
template<typename T>
void rot(uint32_t n, T *x, T *y, T c, T s)# Apply a Givens plane rotation within one warp (ROT), single-warp.
Apply a Givens plane rotation on one thread (ROT), single-thread.
One 32-lane warp applies
x[i] = c*x[i] + s*y[i],y[i] = c*y[i] - s*x_old[i](lane-strided; each index owned by one lane, both olds read into registers first). Trailing__syncwarp(). NumPy equivalent:x, y = c*x + s*y, c*y - s*x.One thread applies
x[i] = c*x[i] + s*y[i],y[i] = c*y[i] - s*x_old[i]serially over thenelements (both olds read into registers first). No shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy equivalent:x, y = c*x + s*y, c*y - s*x.- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Number of elements.
x – In/out vector of length
n.y – In/out vector of length
n.c – Rotation cosine.
s – Rotation sine.
n – Number of elements.
x – In/out vector of length
n.y – In/out vector of length
n.c – Rotation cosine.
s – Rotation sine.
-
template<typename T, uint32_t N>
void rot(T *x, T *y, T c, T s)# Apply a Givens plane rotation within one warp (ROT), compile-time size.
Apply a Givens plane rotation on one thread (ROT), single-thread, compile-time size.
Compile-time-
Noverload of the single-warp rot. NumPy equivalent:x, y = c*x + s*y, c*y - s*x.Compile-time-
Noverload; the trip count folds and the loop unrolls, soxandymay be thread-local register arrays. NumPy equivalent:x, y = c*x + s*y, c*y - s*x.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N.y – In/out vector of length
N.c – Rotation cosine.
s – Rotation sine.
x – In/out vector of length
N.y – In/out vector of length
N.c – Rotation cosine.
s – Rotation sine.
-
namespace warp
-
namespace thread
dot#
Functions
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void dot(T *x, T *y)# Inner product:
y[0] = x · y(DOT), in-place, compile-time size.Compile-time-
Noverload; the scalar result lands iny[0](usesyas scratch). NumPy equivalent:np.dot(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N.y – In/out vector of length
N; the dot product lands iny[0].
-
template<typename T, bool TRAILING_SYNC = true>
void dot_lowmem(uint32_t n, T *x, T *y, T *out)# Inner product:
out[0] = x · y(DOT), low-memory variant.Writes the element-wise products into
out, then thread 0 serially accumulates them intoout[0], leavingxandyuntouched. NumPy equivalent:np.dot_lowmem(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Input vector of length
n.y – Input vector of length
n.out – Length-
nscratch/output buffer; the result lands inout[0].
-
template<typename T>
constexpr std::size_t dot_fast_scratch_bytes(uint32_t block_threads)# Shared-scratch size in bytes for the
dot_fastops.The warp-shuffle dot combines across warps through one scratch slot per warp:
ceil(block_threads / 32)elements ofT. Allocatedot_fast_scratch_bytes<T>(block_threads)for thes_scratchargument.- Template Parameters:
T – Scalar type.
- Parameters:
block_threads – Number of threads in the launching block.
- Returns:
Bytes to allocate for
s_scratch.
-
template<typename T, bool TRAILING_SYNC = true>
void dot_fast(uint32_t n, T *x, T *y, T *out, T *s_scratch)# Inner product:
out[0] = x · y(DOT), warp-shuffle variant.Accumulates the element-wise products with a warp-shuffle reduction plus an inter-warp reduction through shared scratch, leaving
xandyuntouched. NumPy equivalent:np.dot_fast(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Input vector of length
n.y – Input vector of length
n.out – Output buffer; the result lands in
out[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void dot_fast(T *x, T *y, T *out, T *s_scratch)# Inner product:
out[0] = x · y(DOT), warp-shuffle, compile-time size.Compile-time-
Noverload of the warp-shuffle dot product. NumPy equivalent:np.dot_fast(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N.y – Input vector of length
N.out – Output buffer; the result lands in
out[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T>
T dot(uint32_t n, T *x, T *y)# Inner product within one warp: returns
x · yon every lane, single-warp.One 32-lane warp forms the element-wise products and reduces them with
__shfl_down_sync, then BROADCASTS the scalar total back to all 32 lanes via__shfl_sync(from a lane’s register, never a shared re-read — immune to the__restrict__stale-cache miscompile). Inputs are left untouched; no shared scratch, no__syncthreads. Full 32 lanes required; independent warps may run distinct problems concurrently. NumPy equivalent:np.dot(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Input vector of length
n.y – Input vector of length
n.
- Returns:
The inner product
x · y, identical on every lane.
-
template<typename T, uint32_t N>
T dot(T *x, T *y)# Inner product within one warp: returns
x · yon every lane, single-warp, compile-time size.Compile-time-
Noverload of the single-warp dot. Reduces with__shfl_down_syncand broadcasts the total to all 32 lanes from a register. No shared scratch, no__syncthreads. NumPy equivalent:np.dot(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N.y – Input vector of length
N.
- Returns:
The inner product
x · y, identical on every lane.
-
template<typename T>
T dot(uint32_t n, const T *x, const T *y)# Inner product on one thread: returns
x · y, single-thread.Serially accumulates the element-wise products. Inputs untouched; no shared scratch, no shuffles, no barriers. NumPy equivalent:
np.dot(x, y). Works well on low DOF problems with small vectors that fit into a register Parallelism can be leveraged by scaling thread count.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Input vector of length
n.y – Input vector of length
n.
- Returns:
The inner product
x · y.
-
template<typename T, uint32_t N>
T dot(const T *x, const T *y)# Inner product on one thread: returns
x · y, single-thread, compile-time size.Compile-time-
Noverload; the trip count folds and the loop unrolls, soxandymay be thread-local register arrays. NumPy equivalent:np.dot(x, y).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N.y – Input vector of length
N.
- Returns:
The inner product
x · y.
-
namespace warp
-
namespace thread
Functions
-
template<typename T, uint32_t N, uint32_t SX = 1, uint32_t SY = 1>
T dot_strided(const T *x, const T *y)# Per-thread strided inner product:
Σ x[i*SX] * y[i*SY](DOT, strided).A single thread independently walks the full
N-length product with compile-time strides, returning the scalar result. There is NO block-wide reduction — intended for use inside an already thread-parallel outer loop (e.g. GRiD generated kernels). WithSX = SY = 1this is a plain scalar dot; the inner loop is fully unrolled. NumPy equivalent:np.dot(x[::SX], y[::SY]).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of products to accumulate (compile-time constant).
SX – Element stride into
x(compile-time, default 1).SY – Element stride into
y(compile-time, default 1).
- Parameters:
x – Input vector, accessed at indices
0, SX, 2*SX, ….y – Input vector, accessed at indices
0, SY, 2*SY, ….
- Returns:
The strided inner product
Σ x[i*SX] * y[i*SY].
-
template<typename T, uint32_t N, uint32_t SX = 1, uint32_t SY = 1>
void dot_strided(const T *x, const T *y, T *out)# Per-thread strided inner product, store-to-pointer overload.
Same per-thread strided dot as the value-returning overload, but writes the scalar result to
*out. NumPy equivalent:out[0] = np.dot(x[::SX], y[::SY]).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of products to accumulate (compile-time constant).
SX – Element stride into
x(compile-time, default 1).SY – Element stride into
y(compile-time, default 1).
- Parameters:
x – Input vector, accessed at indices
0, SX, 2*SX, ….y – Input vector, accessed at indices
0, SY, 2*SY, ….out – Destination for the scalar result.
Functions
-
template<typename T, uint32_t N, uint32_t SX = 1, uint32_t SY = 1, bool TRAILING_SYNC = true>
void dot_strided_coalesced(const T *x, const T *y, T *out, T *s_scratch)# Block-cooperative strided inner product with coalesced loads (DOT, strided).
Computes the same value as
dot_strided<T,N,SX,SY>(Σ x[i*SX] * y[i*SY]), but the WHOLE block cooperates on one dot product: thei-loop is distributed across threads with a block stride so consecutive ranks touch addressesSXapart, turning a per-warp strided gather into a coalesced burst whenSXis the inner contiguous axis. Partial sums are combined via warp-shuffle plus a shared-scratch block reduction; the scalar result is broadcast to*out(visible to all threads after the trailing barrier). Requires a block-wide,__syncthreads-safe launch — usedot_stridedinstead in a per-thread context. NumPy equivalent:np.dot(x[::SX], y[::SY]).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of products to accumulate (compile-time constant).
SX – Element stride into
x(compile-time, default 1).SY – Element stride into
y(compile-time, default 1).
- Parameters:
x – Input vector, accessed at indices
0, SX, 2*SX, ….y – Input vector, accessed at indices
0, SY, 2*SY, ….out – Destination for the scalar result (broadcast to all threads).
s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
reduce#
Functions
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void reduce(T *x)# Sum reduction:
x[0] = Σ x[i](in-place), compile-time size.Compile-time-
Noverload of the halving reduce. NumPy equivalent:np.sum(x).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N; the sum lands inx[0].
-
template<typename T, bool TRAILING_SYNC = true>
void reduce_lowmem(uint32_t n, T *x)# Sum reduction:
x[0] = Σ x[i](in-place), low-memory variant.Thread 0 serially accumulates all elements into
x[0]; uses no scratch. NumPy equivalent:np.sum(x).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – In/out vector of length
n; the sum lands inx[0].
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void reduce_lowmem(T *x)# Sum reduction:
x[0] = Σ x[i](in-place), low-memory, compile-time size.Compile-time-
Noverload; thread 0 serially accumulates intox[0]. NumPy equivalent:np.sum(x).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N; the sum lands inx[0].
-
template<typename T>
constexpr std::size_t reduce_fast_scratch_bytes(uint32_t block_threads)# Shared-scratch size in bytes for the
reduce_fastops.The warp-shuffle reduce combines across warps through one scratch slot per warp:
ceil(block_threads / 32)elements ofT. Allocatereduce_fast_scratch_bytes<T>(block_threads)for thes_scratchargument.- Template Parameters:
T – Scalar type.
- Parameters:
block_threads – Number of threads in the launching block.
- Returns:
Bytes to allocate for
s_scratch.
-
template<typename T, bool TRAILING_SYNC = true>
void reduce_fast(uint32_t n, T *x, T *s_scratch)# Sum reduction:
x[0] = Σ x[i](in-place), warp-shuffle variant.Accumulates with a warp-shuffle reduction plus an inter-warp reduction through shared scratch; the total lands in
x[0]. NumPy equivalent:np.sum(x).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – In/out vector of length
n; the sum lands inx[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void reduce_fast(T *x, T *s_scratch)# Sum reduction:
x[0] = Σ x[i](in-place), warp-shuffle, compile-time size.Compile-time-
Noverload of the warp-shuffle reduce. NumPy equivalent:np.sum(x).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N; the sum lands inx[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T, bool TRAILING_SYNC = true>
T reduce_fast(T partial, T *s_scratch)# Block-sum of a per-thread register value: returns
Σ partial.Reduces one PER-THREAD contribution
partial(one per thread) across the block and returns the total to EVERY thread, with no intermediatex[]buffer. This is the entry point for fused “compute-a-partial-then-sum” patterns (e.g. cost/barrier kernels). The result is also broadcast throughs_scratch[0]; the routine ends on a__syncthreads(), sos_scratchis safe to reuse afterwards. Threads with no contribution should pass0.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
partial – This thread’s contribution to the block sum.
s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim); on returns_scratch[0]holds the total.
- Returns:
The block-wide total
Σ partial, identical on every thread.
-
template<typename T, bool TRAILING_SYNC = true>
T reduce_fast_min(T partial, T *s_scratch)# Block-min of a per-thread register value: returns
min partial.Min twin of the
reduce_fast(partial, s_scratch)sum overload above, with the same shape: one PER-THREAD contribution in, the block-wide minimum returned to EVERY thread, nox[]buffer. The entry point for fused “compute-a-partial-then
-min” patterns (e.g. a softmax’s max-shift, or a smooth-min collision cost). Threads with no contribution should pass the identity — a large sentinel such as
1e30f, NOT zero.Kept separate from the sum overload rather than folded into a generic
reduce_fast(partial, s_scratch, Op): an operator template would force every existing call site through a functor, and the two identities (0 vs +inf) cannot share a default.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
partial – This thread’s contribution to the block min.
s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim); on returns_scratch[0]holds the minimum.
- Returns:
The block-wide minimum, identical on every thread.
-
template<typename T>
T reduced_tree32(T p[32])# Fixed 32-way pairwise tree reduce of a register array (returns the sum in p[0]).
Combines 32 partials in the EXACT pairwise grouping that
glass::warp::reduceproduces in lane 0 (a__shfl_down_synctree with offsets 16,8,4,2,1), so a serial caller (e.g. a sub-warp fallback below 32 threads) matches the full-warp caller bit-for-bit. This is the shared primitive that lets the contraction-parallel*_reducedengines stay thread-count invariant across the 32-thread boundary. NumPy equivalent:np.sum(p)(different rounding).- Template Parameters:
T – Scalar type.
- Parameters:
p – In/out array of 32 partials; on return
p[0]holds the total (p is clobbered).- Returns:
The sum of
p[0..31].
-
template<typename T>
void reduce(uint32_t n, T *x)# Sum reduction within one warp:
x[0] = Σ x[i](in-place), single-warp.Sum reduction on one thread:
x[0] = Σ x[i], single-thread.One 32-lane warp sums the vector with
__shfl_down_sync; the total lands inx[0](input overwritten). No shared scratch, no inter-warp combine. NumPy equivalent:np.sum(x).Serially accumulates the elements and writes the total to
x[0]. Onlyx[0]is written — the tail is left untouched (unlike the block halving reduce, which usesxas scratch). No shared scratch, no shuffles, no barriers, nothreadIdxread. NumPy equivalent:np.sum(x).- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Number of elements.
x – In/out vector of length
n; the sum lands inx[0].n – Number of elements.
x – In/out vector of length
n; the sum lands inx[0].
-
template<typename T, uint32_t N>
void reduce(T *x)# Sum reduction within one warp:
x[0] = Σ x[i](in-place), single-warp, compile-time size.Sum reduction on one thread:
x[0] = Σ x[i], single-thread, compile-time size.Compile-time-
Noverload. NumPy equivalent:np.sum(x).Compile-time-
Noverload; the trip count folds and the loop unrolls, soxmay be a thread-local register array. Onlyx[0]is written. NumPy equivalent:np.sum(x).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N; the sum lands inx[0].x – In/out vector of length
N; the sum lands inx[0].
-
template<typename T>
T reduce(T partial)# Warp-sum of a per-lane register value: returns
Σ partialon every lane.Sum of a per-thread register value on one thread: returns
partial.Reduces one PER-LANE contribution across a single warp and broadcasts the total back to all 32 lanes — no
x[]buffer, no shared scratch. The entry point for fused “compute-a-partial-then-sum” patterns inside a warp (e.g. row-norm / residual accumulation). Inactive lanes should pass0.The single-thread mirror of
warp::reduce(partial): with one problem per thread there is exactly ONE contribution, so the “reduction” is the identity. Exists so tier-generic call sites (templated on the interface) compile against every tier with the same shape. No barriers, no shuffles, nothreadIdxread. NumPy equivalent:np.sum([partial]).- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
partial – This lane’s contribution.
partial – This thread’s (sole) contribution.
- Returns:
The warp-wide total
Σ partial, identical on every lane.- Returns:
partial, unchanged.
-
template<typename T>
T reduce_min(T partial)# Warp-min of a per-lane register value: returns
min(partial)on every lane.The min twin of the register
warp::reduce(same shuffle ladder + broadcast; no buffer, no scratch). Inactive/idle lanes must pass the identity (e.g.+INFINITY— there is no empty-lane sentinel here; useargmin_pairwhen a lane can be excluded by index). NaN candidates lose every compare, so a NaN lane never wins unless ALL lanes are NaN. Full 32-lane warp required.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
partial – This lane’s contribution.
- Returns:
The warp-wide minimum, identical on every lane.
-
template<typename T>
T reduce_max(T partial)# Warp-max of a per-lane register value: returns
max(partial)on every lane.See
reduce_min(pass-INFINITYfrom idle lanes).- Template Parameters:
T – Scalar type.
- Parameters:
partial – This lane’s contribution.
- Returns:
The warp-wide maximum, identical on every lane.
-
namespace warp
-
namespace thread
prefix_sum#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void prefix_sum_exclusive(T *s_input, T *s_output, int n)# Exclusive prefix sum (scan):
s_output[i] = Σ_{j<i} s_input[j].Block-wide Hillis-Steele scan;
s_output[0]is 0 and each subsequent entry is the running total of all strictly-earlier inputs. NumPy equivalent:s_output = np.concatenate([[0], np.cumsum(s_input)[:-1]]).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
s_input – Input vector of length
n(in shared memory).s_output – Output scan buffer of length
n(in shared memory).n – Number of elements (must not exceed
blockDim.x).
-
template<typename T, bool TRAILING_SYNC = true>
void prefix_sum_inclusive(T *s_input, T *s_output, int n)# Inclusive prefix sum (scan):
s_output[i] = Σ_{j<=i} s_input[j].Block-wide Hillis-Steele scan; each entry is the running total of all inputs up to and including that index. NumPy equivalent:
s_output = np.cumsum(s_input).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
s_input – Input vector of length
n(in shared memory).s_output – Output scan buffer of length
n(in shared memory).n – Number of elements (must not exceed
blockDim.x).
Norms#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void vector_norm(uint32_t N, T *a, T *out)# Euclidean (L2) norm into a separate buffer:
out[0] = ‖a‖₂(default).Default halving-tree variant, completing the reduction family’s bare surface (mirrors how the plain
reduce/dot/nrm2engines are built): the block writes the per-element squares intoout, tree-reduces them with the sharedreducemachinery, and thread 0 takes the square root. Non-destructive —ais left untouched;outdoubles as the length-Nscratch (no shared scratch needed, unlikevector_norm_fast). Thread-count invariant: the pairwise tree gives byte-identical output at any block size. NumPy equivalent:np.linalg.norm(a).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
N – Number of elements.
a – Input vector of length
N(read-only).out – Length-
Nscratch/output buffer; the result lands inout[0].
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void vector_norm(T *a, T *out)# Euclidean (L2) norm into a separate buffer:
out[0] = ‖a‖₂, compile-time size.Compile-time-
Noverload of the default halving-tree vector norm; leavesauntouched. NumPy equivalent:np.linalg.norm(a).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
a – Input vector of length
N(read-only).out – Length-
Nscratch/output buffer; the result lands inout[0].
-
template<typename T, bool TRAILING_SYNC = true>
void vector_norm_lowmem(uint32_t N, T *a, T *out)# Euclidean (L2) norm into a separate buffer:
out[0] = ‖a‖₂, low-memory variant.Writes the per-element squares into
out, then thread 0 serially sums them and takes the square root, leavingauntouched. NumPy equivalent:np.linalg.norm(a).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
N – Number of elements.
a – Input vector of length
N.out – Length-
Nscratch/output buffer; the result lands inout[0].
-
template<typename T, bool TRAILING_SYNC = true>
void vector_norm_fast(uint32_t N, T *a, T *out, T *s_scratch)# Euclidean (L2) norm into a separate buffer:
out[0] = ‖a‖₂, warp-shuffle variant.Accumulates the sum of squares with a warp-shuffle reduction plus an inter-warp reduction through shared scratch, then takes the square root, leaving
auntouched. NumPy equivalent:np.linalg.norm(a).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
N – Number of elements.
a – Input vector of length
N.out – Output buffer; the result lands in
out[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void vector_norm_fast(T *a, T *out, T *s_scratch)# Euclidean (L2) norm into a separate buffer:
out[0] = ‖a‖₂, warp-shuffle, compile-time size.Compile-time-
Noverload of the warp-shuffle vector norm; leavesauntouched. NumPy equivalent:np.linalg.norm(a).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
a – Input vector of length
N.out – Output buffer; the result lands in
out[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void nrm2_lowmem(uint32_t n, T *x)# Euclidean (L2) norm:
x[0] = ‖x‖₂(in-place, destructive), low-memory variant.Squares each element in place, then thread 0 serially sums them and takes the square root, leaving the result in
x[0](the input is overwritten). NumPy equivalent:np.linalg.norm(x).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – In/out vector of length
n; the result lands inx[0].
-
template<typename T, bool TRAILING_SYNC = true>
void nrm2_fast(uint32_t n, T *x, T *s_scratch)# Euclidean (L2) norm:
x[0] = ‖x‖₂(in-place), warp-shuffle variant.Accumulates the sum of squares with a warp-shuffle reduction plus an inter-warp reduction through shared scratch, then takes the square root; the result lands in
x[0]. NumPy equivalent:np.linalg.norm(x).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – In/out vector of length
n; the result lands inx[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void nrm2_fast(T *x, T *s_scratch)# Euclidean (L2) norm:
x[0] = ‖x‖₂, warp-shuffle, compile-time size.Compile-time-
Noverload of the warp-shuffle L2 norm. NumPy equivalent:np.linalg.norm(x).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N; the result lands inx[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T>
T nrm2(uint32_t n, const T *x)# Euclidean (L2) norm within one warp: returns
‖x‖₂on every lane.Euclidean (L2) norm on one thread: returns
‖x‖₂, single-thread.Single-warp L2 norm, mirroring
warp::dot: one 32-lane warp reduces the per-lane sum-of-squares with__shfl_down_sync, BROADCASTS the total to all 32 lanes via__shfl_sync(from a register — immune to the__restrict__stale-cache miscompile), and each lane takes the square root. Non-destructive (xuntouched), no shared scratch, no__syncthreads; uses type-genericsqrt, like every tier (the block forms’ float-onlysqrtfwas fixed 2026-07-17). Full 32 lanes required. NumPy equivalent:np.linalg.norm(x).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.Serially accumulates the sum of squares and returns its square root, mirroring
warp::nrm2(value-returning, non-destructive — unlike the destructive block_fast/_lowmemforms; one thread has no reduction strategy, so the tier ships no such twins). Uses type-genericsqrt(correct fordouble). Inputs untouched; no shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy equivalent:np.linalg.norm(x).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Number of elements.
x – Input vector of length
n(read-only).n – Number of elements.
x – Input vector of length
n(read-only).
- Returns:
‖x‖₂, identical on every lane.- Returns:
‖x‖₂.
-
template<typename T, uint32_t N>
T nrm2(const T *x)# Euclidean (L2) norm within one warp, compile-time size (returns it on every lane).
Euclidean (L2) norm on one thread, compile-time size: returns
‖x‖₂.Compile-time-
Noverload of the single-warp L2 norm. Non-destructive, no shared scratch, no__syncthreads; type-genericsqrt. NumPy equivalent:np.linalg.norm(x).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.Compile-time-
Noverload; the trip count folds and the loop unrolls, soxmay be a thread-local register array. Non-destructive; type-genericsqrt. NumPy equivalent:np.linalg.norm(x).Range contract: naive sum of squares (no LAPACK-style
snrm2scaling), so the intermediate sum overflows toinffor‖x‖ ≳ 1e19(f32) /‖x‖ ≳ 1e154(f64) and loses tiny components to underflow.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N(read-only).x – Input vector of length
N(read-only).
- Returns:
‖x‖₂, identical on every lane.- Returns:
‖x‖₂.
-
namespace warp
-
namespace thread
1-norm of a difference: ‖x − y‖₁ = Σ|x[i] − y[i]|.
The asum sibling for a difference — the residual/convergence check GATO’s Schur loop wants without materializing x − y first. Inputs are read-only (non-destructive). Block forms mirror asum.cuh (low_memory serial-tail and high_speed warp-shuffle); warp::nrm1_diff mirrors warp::dot (returns the scalar broadcast to every lane). Thread-count invariant.
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void nrm1_diff_lowmem(uint32_t n, const T *x, const T *y, T *out)# out[0] = Σ|x[i] − y[i]|(‖x−y‖₁), low-memory variant.Writes the per-element absolute differences into
out, then thread 0 serially accumulates them intoout[0].x/yare untouched. NumPy equivalent:np.sum(np.abs(x - y)).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Input vector of length
n(read-only).y – Input vector of length
n(read-only).out – Length-
nscratch/output buffer; the result lands inout[0].
-
template<typename T, bool TRAILING_SYNC = true>
void nrm1_diff_fast(uint32_t n, const T *x, const T *y, T *out, T *s_scratch)# out[0] = Σ|x[i] − y[i]|(‖x−y‖₁), warp-shuffle variant.Reduces the absolute differences with a warp-shuffle reduction plus an inter-warp reduction through shared scratch; the result lands in
out[0].x/yare untouched. NumPy equivalent:np.sum(np.abs(x - y)).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Input vector of length
n(read-only).y – Input vector of length
n(read-only).out – Output; the result lands in
out[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void nrm1_diff_fast(const T *x, const T *y, T *out, T *s_scratch)# out[0] = Σ|x[i] − y[i]|(‖x−y‖₁), warp-shuffle, compile-time size.Compile-time-
Noverload of the warp-shufflenrm1_diff.x/yuntouched. NumPy equivalent:np.sum(np.abs(x - y)).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N(read-only).y – Input vector of length
N(read-only).out – Output; the result lands in
out[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T>
T nrm1_diff(uint32_t n, const T *x, const T *y)# ‖x − y‖₁within one warp: returnsΣ|x[i] − y[i]|on every lane.‖x − y‖₁on one thread: returnsΣ|x[i] − y[i]|, single-thread.One 32-lane warp forms the absolute differences and reduces with
__shfl_down_sync, then BROADCASTS the scalar total back to all 32 lanes via__shfl_sync(from a register, never a shared re-read — immune to the__restrict__stale-cache miscompile).x/yuntouched; no shared scratch, no__syncthreads. Full 32 lanes required; independent warps may run distinct problems concurrently. NumPy equivalent:np.sum(np.abs(x - y)).Serially accumulates the absolute differences, mirroring
warp::nrm1_diff(value-returning, non-destructive; one thread has no reduction strategy, so the tier ships no_fast/_lowmemtwins).x/yuntouched; no shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy equivalent:np.sum(np.abs(x - y)).- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Number of elements.
x – Input vector of length
n(read-only).y – Input vector of length
n(read-only).n – Number of elements.
x – Input vector of length
n(read-only).y – Input vector of length
n(read-only).
- Returns:
‖x − y‖₁, identical on every lane.- Returns:
‖x − y‖₁.
-
template<typename T, uint32_t N>
T nrm1_diff(const T *x, const T *y)# ‖x − y‖₁within one warp, compile-time size (returns it on every lane).‖x − y‖₁on one thread, compile-time size: returnsΣ|x[i] − y[i]|.Compile-time-
Noverload of the single-warpnrm1_diff. No shared scratch, no__syncthreads. NumPy equivalent:np.sum(np.abs(x - y)).Compile-time-
Noverload; the trip count folds and the loop unrolls, soxandymay be thread-local register arrays. Non-destructive. NumPy equivalent:np.sum(np.abs(x - y)).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N(read-only).y – Input vector of length
N(read-only).x – Input vector of length
N(read-only).y – Input vector of length
N(read-only).
- Returns:
‖x − y‖₁, identical on every lane.- Returns:
‖x − y‖₁.
-
namespace warp
-
namespace thread
Functions
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void infnorm(T *x)# Infinity norm:
x[0] = ‖x‖∞ = max|x[i]|, compile-time size.Compile-time-
Noverload (in-place, destructive). NumPy equivalent:np.max(np.abs(x)).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N; the result lands inx[0].
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void asum_lowmem(uint32_t n, T *x, T *out)# Sum of absolute values:
out[0] = Σ|x[i]|(ASUM), low-memory variant.Writes the per-element absolute values into
out, then thread 0 serially accumulates them intoout[0]. NumPy equivalent:np.sum(np.abs(x)).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Input vector of length
n.out – Length-
nscratch/output buffer; the result lands inout[0].
-
template<typename T, bool TRAILING_SYNC = true>
void asum_fast(uint32_t n, T *x, T *s_scratch)# Sum of absolute values:
x[0] = Σ|x[i]|(ASUM), warp-shuffle variant.Computes the absolute-value sum with a warp-shuffle reduction plus an inter-warp reduction through shared scratch. The result is written to
x[0](destructive — overwrites the input). NumPy equivalent:np.sum(np.abs(x)).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – In/out vector of length
n; result lands inx[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void asum_fast(T *x, T *s_scratch)# Sum of absolute values:
x[0] = Σ|x[i]|(ASUM), compile-time size.Compile-time-
Noverload of the warp-shuffle ASUM; the result is written tox[0](destructive). NumPy equivalent:np.sum(np.abs(x)).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N; result lands inx[0].s_scratch – Shared scratch of
ceil(blockDim/32)elements (one per warp) — size withreduce_fast_scratch_bytes<T>(blockDim).
-
template<typename T>
T asum(uint32_t n, const T *x)# Sum of absolute values within one warp: returns
Σ|x[i]|on every lane.Sum of absolute values on one thread: returns
Σ|x[i]|(ASUM), single-thread.Single-warp ASUM, mirroring
warp::dot: one 32-lane warp reduces the per-lane absolute-value partials with__shfl_down_syncand BROADCASTS the total to all 32 lanes via__shfl_sync(from a register — immune to the__restrict__stale-cache miscompile). Non-destructive (xuntouched), no shared scratch, no__syncthreads. Full 32 lanes required; independent warps may run distinct problems concurrently. NumPy equivalent:np.sum(np.abs(x)).Serially accumulates the absolute values, mirroring
warp::asum(value-returning, non-destructive — unlike the block_fast/_lowmemforms; one thread has no reduction strategy, so the tier ships no such twins). Inputs untouched; no shared scratch, no shuffles, no barriers, nothreadIdxread; operands may be thread-local register arrays. NumPy equivalent:np.sum(np.abs(x)).- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Number of elements.
x – Input vector of length
n(read-only).n – Number of elements.
x – Input vector of length
n(read-only).
- Returns:
Σ|x[i]|, identical on every lane.- Returns:
Σ|x[i]|.
-
template<typename T, uint32_t N>
T asum(const T *x)# Sum of absolute values within one warp, compile-time size (returns it on every lane).
Sum of absolute values on one thread, compile-time size: returns
Σ|x[i]|.Compile-time-
Noverload of the single-warp ASUM. Non-destructive, no shared scratch, no__syncthreads. NumPy equivalent:np.sum(np.abs(x)).Compile-time-
Noverload; the trip count folds and the loop unrolls, soxmay be a thread-local register array. Non-destructive. NumPy equivalent:np.sum(np.abs(x)).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Input vector of length
N(read-only).x – Input vector of length
N(read-only).
- Returns:
Σ|x[i]|, identical on every lane.- Returns:
Σ|x[i]|.
-
namespace warp
-
namespace thread
Index of max-abs (iamax)#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void iamax(uint32_t n, const T *x, uint32_t *out, T *s_scratch)# Index of the max-absolute-value element (BLAS i_amax), into
out[0].Non-destructive:
xis read-only and never clobbered. Computes the block-wide argmax over|x|(defaultthreadIdx-strided variant) and writes the winning index (uint32_t) toout[0]. NumPy equivalent:int(np.argmax(np.abs(x))).The routine ends on a trailing
__syncthreads(), soout[0]is block-visible on return.- Tie-break
On EQUAL absolute value the LOWER index wins (the BLAS rule). This tie-break is applied at every combine step, which is what makes the result identical for any block size (1 thread, a partial warp, or many warps).
- NaN policy
NaN inputs are SKIPPED (IEEE compares are false, so a NaN is never selected). This DIVERGES from
np.argmax(np.abs(x)), which propagates NaN; oracle tests must exclude NaN inputs. An all-zero vector returns index0.- Scratch sizing
This variant uses no shared scratch (a serial pass on thread 0). For the warp-shuffle
iamax_fastvariant size scratch viaiamax_fast_scratch_bytes.
- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Read-only input vector of length
n(not modified).out – Output:
out[0]receives the argmax index.s_scratch – Shared scratch of
iamax_scratch_byteselements (key + index lanes).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void iamax(const T *x, uint32_t *out, T *s_scratch)# Index of the max-absolute-value element (BLAS i_amax), compile-time size.
Compile-time-
Noverload of the default i_amax; non-destructive, writes the winning index toout[0]. NumPy equivalent:int(np.argmax(np.abs(x))). Tie-break (lower index wins on equal|x|), NaN-skip policy, and the trailing__syncthreads()are as in the runtime-noverload.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Read-only input vector of length
N(not modified).out – Output:
out[0]receives the argmax index.s_scratch – Shared scratch of
iamax_scratch_byteselements.
-
template<typename T, bool TRAILING_SYNC = true>
void iamax(uint32_t n, const T *x, uint32_t *out, T *out_val, T *s_scratch)# i_amax with the max absolute value also returned:
out_val[0] = max|x|.Like
iamaxbut additionally writes the winning absolute value toout_val[0](max|x|, NumPynp.max(np.abs(x))over the non-NaN entries). Non-destructive; lower-index tie-break; NaN skipped; trailing__syncthreads().- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Read-only input vector of length
n(not modified).out – Output:
out[0]receives the argmax index.out_val – Output:
out_val[0]receivesmax|x|.s_scratch – Shared scratch of
iamax_scratch_byteselements.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void iamax(const T *x, uint32_t *out, T *out_val, T *s_scratch)# i_amax with
max|x|returned, compile-time size.Compile-time-
Noverload of the value-returning i_amax. NumPy equivalents:out[0] = int(np.argmax(np.abs(x))),out_val[0] = np.max(np.abs(x)).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Read-only input vector of length
N(not modified).out – Output:
out[0]receives the argmax index.out_val – Output:
out_val[0]receivesmax|x|.s_scratch – Shared scratch of
iamax_scratch_byteselements.
-
template<typename T>
constexpr std::size_t iamax_scratch_bytes(uint32_t block_threads)# Shared-scratch size in bytes for the default/
low_memoryiamax.The default variant stores one abs-key (
T) and one index (uint32_t) per thread. Allocateiamax_scratch_bytes<T>(block_threads)bytes ofTfors_scratch(the index lanes are packed into the same buffer after the keys).- Template Parameters:
T – Scalar type.
- Parameters:
block_threads – Number of threads in the launching block.
- Returns:
Bytes to allocate for
s_scratch.
-
template<typename T>
constexpr std::size_t iamax_fast_scratch_bytes(uint32_t block_threads)# Shared-scratch size in bytes for
iamax_fast.The warp-shuffle variant reduces within each warp in registers and combines across warps through scratch, needing one (key,index) slot per warp:
ceil(block_threads/32)of each. Allocateiamax_fast_scratch_bytes<T>(block_threads)elements ofTfor itss_scratch.- Template Parameters:
T – Scalar type.
- Parameters:
block_threads – Number of threads in the launching block.
- Returns:
Bytes to allocate for the
iamax_fastscratch.
-
template<typename T, bool TRAILING_SYNC = true>
void iamax_lowmem(uint32_t n, const T *x, uint32_t *out)# i_amax, low-memory variant (no scratch).
Thread 0 serially scans
xfor the argmax over|x|, writing the index toout[0]; all other threads idle. Non-destructive. NumPy equivalent:int(np.argmax(np.abs(x))). Lower-index tie-break on equal|x|; NaN skipped (diverges fromnp.argmax, exclude NaN in tests); all-zero → 0. Ends on a trailing__syncthreads()soout[0]is block-visible.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Read-only input vector of length
n(not modified).out – Output:
out[0]receives the argmax index.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void iamax_lowmem(const T *x, uint32_t *out)# i_amax, low-memory variant, compile-time size.
Compile-time-
Noverload of the serial i_amax. NumPy equivalent:int(np.argmax(np.abs(x))). Same tie-break / NaN policy as the runtime form.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Read-only input vector of length
N(not modified).out – Output:
out[0]receives the argmax index.
-
template<typename T, bool TRAILING_SYNC = true>
void iamax_lowmem(uint32_t n, const T *x, uint32_t *out, T *out_val)# i_amax +
max|x|, low-memory variant (no scratch).As above but also writes
out_val[0] = max|x|. Non-destructive; thread 0 scans serially; lower-index tie-break; NaN skipped; all-zero → 0.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Read-only input vector of length
n(not modified).out – Output:
out[0]receives the argmax index.out_val – Output:
out_val[0]receivesmax|x|.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void iamax_lowmem(const T *x, uint32_t *out, T *out_val)# i_amax +
max|x|, low-memory variant, compile-time size.Compile-time-
Nvalue-returning serial overload.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Read-only input vector of length
N(not modified).out – Output:
out[0]receives the argmax index.out_val – Output:
out_val[0]receivesmax|x|.
-
template<typename T, bool TRAILING_SYNC = true>
void iamax_fast(uint32_t n, const T *x, uint32_t *out, T *s_scratch)# i_amax, warp-shuffle variant: index of
max|x|intoout[0].Each thread forms a strided per-thread argmax in registers, the warp folds it with
__shfl_down_sync(carrying the (key,index) pair), and the per-warp winners are combined throughs_scratch. Non-destructive. NumPy equivalent:int(np.argmax(np.abs(x))).- Tie-break / NaN
Lower index wins on equal
|x|at every shuffle/scratch combine (so the result is block-size invariant). NaN is skipped (diverges fromnp.argmax; exclude NaN in tests). All-zero vector → index0.- Scratch
s_scratchmust holdiamax_fast_scratch_bytes<T>(blockDim)elements (one (key,index) slot per warp). Ends on a trailing__syncthreads().
- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Read-only input vector of length
n(not modified).out – Output:
out[0]receives the argmax index.s_scratch – Shared scratch sized by
iamax_fast_scratch_bytes<T>(blockDim).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void iamax_fast(const T *x, uint32_t *out, T *s_scratch)# i_amax, warp-shuffle variant, compile-time size.
Compile-time-
Noverload of the warp-shuffle i_amax. NumPy equivalent:int(np.argmax(np.abs(x))). Scratch viaiamax_fast_scratch_bytes<T>(blockDim).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Read-only input vector of length
N(not modified).out – Output:
out[0]receives the argmax index.s_scratch – Shared scratch sized by
iamax_fast_scratch_bytes<T>(blockDim).
-
template<typename T, bool TRAILING_SYNC = true>
void iamax_fast(uint32_t n, const T *x, uint32_t *out, T *out_val, T *s_scratch)# i_amax +
max|x|, warp-shuffle variant.As the warp-shuffle
iamaxbut also writesout_val[0] = max|x|. Non-destructive; lower-index tie-break; NaN skipped; all-zero → 0.- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Read-only input vector of length
n(not modified).out – Output:
out[0]receives the argmax index.out_val – Output:
out_val[0]receivesmax|x|.s_scratch – Shared scratch sized by
iamax_fast_scratch_bytes<T>(blockDim).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void iamax_fast(const T *x, uint32_t *out, T *out_val, T *s_scratch)# i_amax +
max|x|, warp-shuffle variant, compile-time size.Compile-time-
Nvalue-returning warp-shuffle overload. NumPy equivalents:out[0] = int(np.argmax(np.abs(x))),out_val[0] = np.max(np.abs(x)).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Read-only input vector of length
N(not modified).out – Output:
out[0]receives the argmax index.out_val – Output:
out_val[0]receivesmax|x|.s_scratch – Shared scratch sized by
iamax_fast_scratch_bytes<T>(blockDim).
-
template<typename T>
uint32_t iamax(uint32_t n, const T *x)# Index of
max|x|(BLAS i_amax) within ONE warp, returned on every lane.A single 32-lane warp computes
argmax(|x|)and returns it (register return, broadcast to all lanes via__shfl_sync) — there is NOout[]write and NO shared scratch. Each lane forms a strided per-lane(abskey,index)argmax overfor (i = lane; i < n; i += 32), then the warp folds the pair with__shfl_down_sync(lower-index tie-break at EVERY step) and broadcasts lane 0’s index. NumPy equivalent:int(np.argmax(np.abs(x))).- Full-warp requirement
This routine assumes a FULL 32-lane warp is active (mask
0xffffffff); it must be called by all 32 lanes of the warp. Inactive lanes (those whoselane >= n, i.e. that never enter the strided loop) seedkey = 0, idx = UINT32_MAX, so they never win a tie. An all-zero vector therefore returns index0.- Multi-warp independence
Shared-free and
__syncthreads-free: many warps may run this concurrently in one block, each on its ownx, with no cross-warp interference. The result is also identical to the block-scopedglass::iamax(same(key,idx)lower-index combine).- Tie-break / NaN
On EQUAL
|x|the LOWER index wins (the BLAS rule), applied at every shuffle combine — so the result is lane/order independent. NaN inputs are SKIPPED (IEEE compares are false, so a NaN is never selected); this DIVERGES fromnp.argmax(np.abs(x)), which propagates NaN — oracle tests must exclude NaN.
- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – Read-only input vector of length
n(not modified).
- Returns:
The argmax index (
uint32_t), identical on every lane.
-
template<typename T, uint32_t N>
uint32_t iamax(const T *x)# Index of
max|x|(BLAS i_amax) within ONE warp, compile-time size.Compile-time-
Noverload of the single-warp i_amax. Returnsargmax(|x|)on every lane (register broadcast). NumPy equivalent:int(np.argmax(np.abs(x))). Same full-warp requirement, multi-warp independence, lower-index tie-break, and NaN-skip policy as the runtime-noverload.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – Read-only input vector of length
N(not modified).- Returns:
The argmax index (
uint32_t), identical on every lane.
-
namespace iamax_detail#
-
namespace warp
clip#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void clip(uint32_t n, T *x, T *l, T *u)# Element-wise clamp in place:
x = clamp(x, l, u).Each element is bounded below by the corresponding
l[i]and above byu[i]. NumPy equivalent:np.clip(x, l, u).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
x – In/out vector of length
n(overwritten with the clamped values).l – Per-element lower bounds, length
n.u – Per-element upper bounds, length
n.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void clip(T *x, T *l, T *u)# Element-wise clamp in place:
x = clamp(x, l, u), compile-time size.Compile-time-
Noverload of clip. NumPy equivalent:np.clip(x, l, u).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
x – In/out vector of length
N(overwritten with the clamped values).l – Per-element lower bounds, length
N.u – Per-element upper bounds, length
N.
set_const#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void set_const(uint32_t n, T alpha, T *x)# Fill a vector with a constant:
x[i] = alpha.NumPy equivalent:
x = np.full(n, alpha).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Number of elements.
alpha – Value to broadcast into every element.
x – Output vector of length
n.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void set_const(T alpha, T *x)# Fill a vector with a constant:
x[i] = alpha, compile-time size.Compile-time-
Noverload. NumPy equivalent:x = np.full(N, alpha).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
alpha – Value to broadcast into every element.
x – Output vector of length
N.
identity#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void set_identity(uint32_t n, T *A)# Load the identity matrix:
A = I_n(column-major).Writes the
n×nidentity intoAin column-major order. NumPy equivalent:A = np.eye(n).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Matrix dimension (number of rows/columns).
A – Output matrix of
n*nelements (column-major).
-
template<typename T, bool TRAILING_SYNC = true>
void add_identity(uint32_t n, T *A, T alpha)# Add a scaled identity to a matrix in place:
A += alpha * I.Adds
alphato the diagonal of then×n(column-major) matrixA. NumPy equivalent:A += alpha * np.eye(n).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Matrix dimension (number of rows/columns).
A – In/out matrix of
n*nelements (column-major).alpha – Scalar added to each diagonal entry.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void set_identity(T *A)# Load the identity matrix:
A = I_N(column-major), compile-time size.Compile-time-
Noverload. NumPy equivalent:A = np.eye(N).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Matrix dimension (compile-time constant).
- Parameters:
A – Output matrix of
N*Nelements (column-major).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void add_identity(T *A, T alpha)# Add a scaled identity in place:
A += alpha * I, compile-time size.Compile-time-
Noverload. NumPy equivalent:A += alpha * np.eye(N).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Matrix dimension (compile-time constant).
- Parameters:
A – In/out matrix of
N*Nelements (column-major).alpha – Scalar added to each diagonal entry.
-
template<typename T, bool TRAILING_SYNC = true>
void add_identity_partial(uint32_t n, T *A, T alpha, uint32_t diag_count)# Add a scaled identity to the leading diagonal block:
A[:d,:d] += alpha*I.Adds
alphato only the firstdiag_countdiagonal entries of then×n(column-major) matrixA, leaving the trailingn-diag_countdiagonal entries untouched. Use to regularize a leading sub-block — e.g. the position block of a stacked[q; v]state, wherediag_count = n/2. NumPy equivalent:A[:d, :d] += alpha * np.eye(d).- Template Parameters:
T – Scalar type (e.g.
float,double).- Parameters:
n – Matrix dimension (number of rows/columns).
A – In/out matrix of
n*nelements (column-major).alpha – Scalar added to each of the leading diagonal entries.
diag_count – Number of leading diagonal entries to bump (
<= n).
-
template<typename T, uint32_t N, uint32_t DIAG_COUNT, bool TRAILING_SYNC = true>
void add_identity_partial(T *A, T alpha)# Add a scaled identity to the leading diagonal block, compile-time size.
Compile-time
<N, DIAG_COUNT>overload of add_identity_partial. NumPy equivalent:A[:DIAG_COUNT, :DIAG_COUNT] += alpha * np.eye(DIAG_COUNT).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Matrix dimension (compile-time constant).
DIAG_COUNT – Number of leading diagonal entries to bump (
<= N).
- Parameters:
A – In/out matrix of
N*Nelements (column-major).alpha – Scalar added to each of the leading diagonal entries.
symmetrize#
In-place symmetrization A := 0.5*(A + Aᵀ) for a square matrix.
Numerically enforces symmetry on an n×n column-major matrix — the standard cleanup after a product chain (e.g. a Schur-complement gemm sequence) whose result is symmetric in exact arithmetic but drifts under floating point. MPCGPU hand-rolls exactly this after its Schur assembly (without it, CG stagnates on the slightly-asymmetric operator); this is that loop, once.
Each strictly-lower (i>j) pair owner reads BOTH mirror elements and writes BOTH — every (i,j)/(j,i) pair is touched by exactly one thread, the diagonal is untouched, so there is no cross-thread hazard and the op is trivially thread-count invariant. Block + warp:: + cgrps::.
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void symmetrize(uint32_t n, T *A)# Symmetrize a square matrix in place:
A = 0.5*(A + Aᵀ).Averages each strictly-off-diagonal mirror pair of the
n×ncolumn-major matrixA; the diagonal is untouched. NumPy equivalent:A = 0.5*(A + A.T).- Template Parameters:
T – Scalar type (e.g.
float,double).TRAILING_SYNC – Emit a trailing
__syncthreads()(default true).
- Parameters:
n – Matrix dimension (number of rows/columns).
A – In/out matrix of
n*nelements (column-major).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void symmetrize(T *A)# Symmetrize in place:
A = 0.5*(A + Aᵀ), compile-time size.Compile-time-
Noverload. NumPy equivalent:A = 0.5*(A + A.T).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Matrix dimension (compile-time constant).
TRAILING_SYNC – Emit a trailing
__syncthreads()(default true).
- Parameters:
A – In/out matrix of
N*Nelements (column-major).
-
template<typename T>
void symmetrize(uint32_t n, T *A)# Symmetrize within one warp:
A = 0.5*(A + Aᵀ), single-warp.Symmetrize on one thread:
A = 0.5*(A + Aᵀ), single-thread.One 32-lane warp averages the mirror pairs of the
n×ncolumn-major matrix in place; the diagonal is untouched. Each pair owned by exactly one lane; trailing__syncwarp(). NumPy equivalent:A = 0.5*(A + A.T).One thread averages each strictly-off-diagonal mirror pair of the
n×ncolumn-major matrix serially; the diagonal is untouched. No shared scratch, no shuffles, no barriers, nothreadIdxread;Amay be a thread-local register array. NumPy equivalent:A = 0.5*(A + A.T).- Template Parameters:
T – Scalar type (e.g.
float,double).T – Scalar type (e.g.
float,double).
- Parameters:
n – Matrix dimension (number of rows/columns).
A – In/out matrix of
n*nelements (column-major).n – Matrix dimension (number of rows/columns).
A – In/out matrix of
n*nelements (column-major).
-
template<typename T, uint32_t N>
void symmetrize(T *A)# Symmetrize within one warp:
A = 0.5*(A + Aᵀ), compile-time size.Symmetrize on one thread:
A = 0.5*(A + Aᵀ), single-thread, compile-time size.Compile-time-
Noverload of the single-warp symmetrize. NumPy equivalent:A = 0.5*(A + A.T).Compile-time-
Noverload; the trip count folds and the loop unrolls, soAmay be a thread-local register array. NumPy equivalent:A = 0.5*(A + A.T).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Matrix dimension (compile-time constant).
T – Scalar type (e.g.
float,double).N – Matrix dimension (compile-time constant).
- Parameters:
A – In/out matrix of
N*Nelements (column-major).A – In/out matrix of
N*Nelements (column-major).
-
namespace warp
-
namespace thread
transpose#
Functions
-
template<typename T, uint32_t N, uint32_t M, bool TRAILING_SYNC = true>
void transpose(T *a, T *b)# Out-of-place matrix transpose:
b = aᵀ, compile-time size.Compile-time-
N,Moverload; transposes theN×Mcolumn-major matrixainto theM×Ncolumn-major matrixb. NumPy equivalent:b = a.T.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of rows of
a(columns ofb), compile-time constant.M – Number of columns of
a(rows ofb), compile-time constant.
- Parameters:
a – Input matrix of
N*Melements (column-major).b – Output matrix of
M*Nelements (column-major).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void transpose(T *a)# In-place square matrix transpose:
a = aᵀ, compile-time size.Compile-time-
Noverload; transposes theN×Ncolumn-major matrixain place. NumPy equivalent:a = a.T.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Matrix dimension (compile-time constant).
- Parameters:
a – In/out matrix of
N*Nelements (column-major).
Elementwise logic#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_less_than(uint32_t N, T *a, T *b, T *c)#
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_more_than(uint32_t N, T *a, T *b, T *c)#
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_less_than_or_eq(uint32_t N, T *a, T *b, T *c)#
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_less_than_scalar(uint32_t N, T *a, T b, T *c)#
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_mult_scalar(uint32_t N, T *a, T b, T *c)#
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_max_scalar(uint32_t N, T *a, T b, T *c)#
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_min_scalar(uint32_t N, T *a, T b, T *c)#
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void elementwise_max(T *a, T *b, T *c)# Element-wise maximum:
c = max(a, b), compile-time size.Compile-time-
Noverload. NumPy equivalent:np.maximum(a, b).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
a – Input vector of length
N.b – Input vector of length
N.c – Output vector of length
N.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void elementwise_min(T *a, T *b, T *c)# Element-wise minimum:
c = min(a, b), compile-time size.Compile-time-
Noverload. NumPy equivalent:np.minimum(a, b).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
a – Input vector of length
N.b – Input vector of length
N.c – Output vector of length
N.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void elementwise_abs(T *a, T *b)# Element-wise absolute value:
b = |a|, compile-time size.Compile-time-
Noverload. NumPy equivalent:b = np.abs(a).- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
a – Input vector of length
N.b – Output vector of length
N.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void elementwise_mult(T *a, T *b, T *c)# Element-wise (Hadamard) product:
c = a ⊙ b, compile-time size.Compile-time-
Noverload. NumPy equivalent:c = a * b.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
a – Input vector of length
N.b – Input vector of length
N.c – Output vector of length
N.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void elementwise_sub(T *a, T *b, T *c)# Element-wise subtraction:
c = a - b, compile-time size.Compile-time-
Noverload. NumPy equivalent:c = a - b.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
a – Input vector of length
N.b – Input vector of length
N.c – Output vector of length
N.
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void elementwise_add(T *a, T *b, T *c)# Element-wise addition:
c = a + b, compile-time size.Compile-time-
Noverload. NumPy equivalent:c = a + b.- Template Parameters:
T – Scalar type (e.g.
float,double).N – Number of elements (compile-time constant).
- Parameters:
a – Input vector of length
N.b – Input vector of length
N.c – Output vector of length
N.
Cooperative-groups variants (glass::cgrps::)#
Functions
-
template<typename T, bool TRAILING_SYNC = true>
void axpy(uint32_t n, T alpha, T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# AXPY
y = alpha*x + y(cgrps variant; see glass::axpy).
-
template<typename T, bool TRAILING_SYNC = true>
void axpy(uint32_t n, T alpha, T *x, T *y, T *z, cgrps::thread_group g = cgrps::this_thread_block())# Out-of-place AXPY
z = alpha*x + y(cgrps variant; see glass::axpy).
-
template<typename T, bool TRAILING_SYNC = true>
void axpby(uint32_t n, T alpha, T *x, T beta, T *y, T *z, cgrps::thread_group g = cgrps::this_thread_block())# AXPBY
z = alpha*x + beta*y(cgrps variant; see glass::axpby).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void axpy(T alpha, T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size AXPY
y = alpha*x + y(cgrps variant).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void axpy(T alpha, T *x, T *y, T *z, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size out-of-place AXPY
z = alpha*x + y(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void copy(uint32_t n, T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Vector copy
y = x(cgrps variant; see glass::copy).
-
template<typename T, bool TRAILING_SYNC = true>
void copy(uint32_t n, T alpha, T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Scaled copy
y = alpha*x(cgrps variant; see glass::copy).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void copy(T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size vector copy
y = x(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void scal(uint32_t n, T alpha, T *x, cgrps::thread_group g = cgrps::this_thread_block())# In-place scale
x = alpha*x(cgrps variant; see glass::scal).
-
template<typename T, bool TRAILING_SYNC = true>
void scal(uint32_t n, T alpha, T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Out-of-place scale
y = alpha*x(cgrps variant; see glass::scal).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void scal(T alpha, T *x, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size in-place scale
x = alpha*x(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void swap(uint32_t n, T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Swap two vectors
x <-> y(cgrps variant; see glass::swap).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void swap(T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size swap
x <-> y(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void clip(uint32_t n, T *x, T *l, T *u, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise clamp
x = clamp(x, l, u)(cgrps variant; see glass::clip).
-
template<typename T, bool TRAILING_SYNC = true>
void set_const(uint32_t n, T alpha, T *x, cgrps::thread_group g = cgrps::this_thread_block())# Fill with a constant
x = alpha(cgrps variant; see glass::set_const).
-
template<typename T, bool TRAILING_SYNC = true>
void set_identity(uint32_t n, T *A, cgrps::thread_group g = cgrps::this_thread_block())# Load the identity
A = I_n(cgrps variant; see glass::set_identity).
-
template<typename T, bool TRAILING_SYNC = true>
void add_identity(uint32_t n, T *A, T alpha, cgrps::thread_group g = cgrps::this_thread_block())# Add a scaled identity
A += alpha*I(cgrps variant; see glass::add_identity).
-
template<typename T, bool TRAILING_SYNC = true>
void reduce(uint32_t n, T *x, cgrps::thread_group g = cgrps::this_thread_block())# Sum reduction
x[0] = sum(x)(cgrps variant; see glass::reduce).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void reduce(T *x, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size sum reduction
x[0] = sum(x)(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void dot(uint32_t n, T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Dot product
y[0] = dot(x, y)(destructive; cgrps variant; see glass::dot).
-
template<typename T, uint32_t N, bool TRAILING_SYNC = true>
void dot(T *x, T *y, cgrps::thread_group g = cgrps::this_thread_block())# Compile-time-size dot product
y[0] = dot(x, y)(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void transpose(uint32_t N, uint32_t M, T *a, T *b, cgrps::thread_group g = cgrps::this_thread_block())# Out-of-place transpose
b = a^T(cgrps variant; see glass::transpose).
-
template<typename T, bool TRAILING_SYNC = true>
void transpose(uint32_t N, T *a, cgrps::thread_group g = cgrps::this_thread_block())# In-place square transpose
a = a^T(cgrps variant; see glass::transpose).
-
template<typename T, bool TRAILING_SYNC = true>
void symmetrize(uint32_t n, T *A, cgrps::thread_group g = cgrps::this_thread_block())# In-place symmetrization
A = 0.5*(A + Aᵀ)(cgrps variant; see glass::symmetrize).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_max(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise max
c = max(a, b)(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_min(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise min
c = min(a, b)(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_less_than(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise less-than
c = (a < b)(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_more_than(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise greater-than
c = (a > b)(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_less_than_or_eq(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise less-than-or-equal
c = (a <= b)(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_and(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise logical AND
c = (a && b)(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_not(uint32_t N, T *a, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise logical NOT
c = !a(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_abs(uint32_t N, T *a, T *b, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise absolute value
b = |a|(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_mult(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise (Hadamard) product
c = a * b(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_sub(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise subtraction
c = a - b(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_add(uint32_t N, T *a, T *b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise addition
c = a + b(cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_mult_scalar(uint32_t N, T *a, T b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise scalar multiply
c = a * b(scalar b; cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_max_scalar(uint32_t N, T *a, T b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise max against a scalar
c = max(a, b)(scalar b; cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void elementwise_min_scalar(uint32_t N, T *a, T b, T *c, cgrps::thread_group g = cgrps::this_thread_block())# Element-wise min against a scalar
c = min(a, b)(scalar b; cgrps variant).
-
template<typename T, bool TRAILING_SYNC = true>
void nrm2(uint32_t n, T *x, cgrps::thread_group g = cgrps::this_thread_block())# Euclidean (L2) norm
x[0] = ||x||_2(destructive; cgrps variant; see glass::nrm2_impl).