Skip to main content

Crate ruxla_prims

Crate ruxla_prims 

Source
Expand description

The primitives of ruxla: shape inference, evaluation (with ruxla-kernels), lowering to StableHLO, batching rules (vmap, following JAX’s rules; see batching), and differentiation rules (jvp and transpose, ported from JAX’s).

The set follows jax.lax. Elementwise primitives are entries of tables keyed by the operations of ruxla-kernels (unary_prim, binary_prim, compare_prim).

Re-exports§

pub use random::THREEFRY2X32;

Modules§

ad
Helpers for differentiation rules, shared by the primitives and the drivers in ruxla-transforms.
batching
Helpers for batching rules (vmap), shared by the primitives and the vmap driver in ruxla-transforms.

Statics§

ABS
|x|.
ADD
x + y.
AND
Logical or bitwise and.
ARGMAX
The index of the largest element along an axis (Params::ArgMinMax).
ARGMIN
The index of the smallest element along an axis.
ATAN2
atan2(x, y).
BESSEL_I0E
exp(-|x|) I0(x).
BESSEL_I1E
exp(-|x|) I1(x).
BITCAST_CONVERT_TYPE
Reinterpret the bits as another type of the same size.
BROADCAST_IN_DIM
Broadcasts to a larger shape (Params::BroadcastInDim).
CBRT
Cube root.
CEIL
Round up.
CHECKPOINT
Calls a function whose intermediate values reverse mode recomputes instead of storing (Params::Checkpoint, jax.checkpoint).
CHOLESKY
The Cholesky factor L (A = L L^T) of each symmetric positive definite matrix, read from its lower triangle; the strictly upper triangle of the result is that of the input, and matrices that are not positive definite give NaNs (as JAX’s cholesky_p on CPU and GPU).
CHOLESKY_UPDATE
The rank-1 update of each upper triangular Cholesky factor r (a = r^T r) by the vector w: the factor of a + w w^T, as JAX’s cholesky_update_p (real matrices; Givens rotations, as JAX computes it on CPU). Not differentiable, as in JAX.
CLAMP
Clamp to bounds.
COMPLEX
Complex numbers from their real and imaginary parts.
CONCATENATE
Joins arrays along a dimension.
COND
Calls the branch chosen by an i32 index, passing the other operands (Params::Cond). An index out of range calls the last branch, as stablehlo.case does.
CONJ
The complex conjugate.
CONVERT_ELEMENT_TYPE
Convert to another element type (Params::Convert).
CONV_GENERAL_DILATED
A convolution with strides, padding, input and kernel dilation, and feature and batch groups (Params::ConvGeneralDilated), as XLA’s Conv.
COS
Cosine.
CUMLOGSUMEXP
The cumulative logsumexp along an axis (floats only).
CUMMAX
The cumulative maximum along an axis, propagating NaN.
CUMMIN
The cumulative minimum along an axis, propagating NaN.
CUMPROD
The cumulative product along an axis.
CUMSUM
The cumulative sum along an axis (Params::Cumulative).
CUSTOM_JVP_CALL
Calls a function with a JVP rule written by the user (Params::CustomJvp).
CUSTOM_LIN
The tangents of the outputs of a custom_vjp_call (Params::CustomLin): linear in the tangents of the arguments, and defined only by its transpose, the backward function. It cannot be evaluated: forward-mode differentiation of a custom_vjp function is not supported, as in JAX.
CUSTOM_VJP_CALL
Calls a function with a VJP rule written by the user (Params::CustomVjp).
DIGAMMA
The digamma function.
DIV
x / y.
DOT_GENERAL
Sums of products over contracting dimensions (Params::DotGeneral).
DYNAMIC_SLICE
A slice at run-time start indices (one integer scalar per dimension), clamped to stay in bounds.
DYNAMIC_UPDATE_SLICE
Writes an update at run-time start indices, clamped to stay in bounds.
EIG
The eigendecomposition of each general matrix (Params::Eig): the complex eigenvalues ([..., n]), and the left and right eigenvectors ([..., n, n], one per column) that are requested, of the complex type of the input, as JAX’s eig_p, which it computes with LAPACK’s geev (see ruxla_kernels::linalg::eig for the conventions).
EIGH
The eigendecomposition of each symmetric matrix, read from the triangle given by lower (Params::Eigh): the eigenvectors v (columns) and the eigenvalues w in ascending order, as JAX’s eigh_p (which returns v first). With subset_by_index, the eigenvalues of that range of indices and their eigenvectors (computed from the whole decomposition; JAX supports it on TPU only).
EQ
x == y.
ERF
The error function.
ERFC
The complementary error function.
ERF_INV
The inverse error function.
EXP
e^x.
EXPM1
e^x - 1.
EXTERN_CALL
Calls the public main of a StableHLO module written by another program, such as a JAX model exported with jax.export (Params::Extern). XLA links the module with the caller and compiles them together; the interpreter and the native backend cannot run it.
FFT
Fourier transforms of the trailing axes (Params::Fft).
FLOOR
Round down.
GATHER
Slices at run-time start indices (Params::Gather).
GE
x >= y.
GT
x > y.
HESSENBERG
The reduction of each square matrix to upper Hessenberg form, as JAX’s hessenberg_p (LAPACK’s gehrd): the matrix with h on and above the subdiagonal and the Householder reflectors below it, and the n - 1 factors tau. Not differentiable, as in JAX.
HOST_CALLBACK
Calls a Rust function on host arrays (Params::HostCallback): the interpreter calls it directly, XLA through the FFI handler ruxla_host_callback of ruxla-pjrt (on CUDA, around copies to the host), which finds it by its id. The function must be pure (it may run any number of times). Not differentiable; batched by a loop over the examples (scan, as pure_callback with vmap_method="sequential"). Programs with host callbacks cannot be serialized, embedded in JAX, or compiled to Rust.
HOUSEHOLDER_PRODUCT
The first n columns of the product of the Householder reflectors below the diagonal of a ([..., m, n], m >= n) with the factors taus ([..., k], k <= n), as JAX’s householder_product_p (LAPACK’s orgqr). Not differentiable, as in JAX.
IGAMMA
The regularized lower incomplete gamma function.
IGAMMAC
The regularized upper incomplete gamma function.
IGAMMA_GRAD_A
The derivative of igamma with respect to its first operand.
IMAG
The imaginary part of complex numbers.
INTEGER_POW
x^y for a static integer y (Params::IntegerPow).
IOTA
The indices along a dimension.
IS_FINITE
Whether each element is finite.
JIT
Calls a function compiled as a unit (Params::Jit).
LE
x <= y.
LGAMMA
The logarithm of the absolute value of the gamma function.
LOG
Natural logarithm.
LOG1P
log(1 + x).
LOGISTIC
The logistic sigmoid.
LT
x < y.
LU
The LU factorization with partial pivoting of each matrix: the factors (L below the diagonal with an implicit unit diagonal, U on and above it), the pivots (i32[..., min(m, n)], 0-based row swaps), and the permutation (i32[..., m]), as JAX’s lu_p.
LU_PIVOTS_TO_PERMUTATION
Converts the pivots of lu (i32[..., k]) to permutations (i32[..., permutation_size]): starting from the identity, swaps element i with element pivots[i] for each i in order (Params::LuPivotsToPermutation).
MAX
Maximum.
MIN
Minimum.
MUL
x * y.
NE
x != y.
NEG
-x.
NOT
Logical or bitwise not.
OR
Logical or bitwise or.
ORMQR
The product of c with Q (or Q^H) of the Householder reflectors of a and the factors taus, from the left or the right (Params::Ormqr), without forming Q, as JAX’s ormqr_p (LAPACK’s ormqr). Not differentiable, as in JAX.
PAD
Pads with a scalar value; negative padding removes elements.
POLYGAMMA
The polygamma function.
POW
x^y.
QR
The QR decomposition of each matrix (Params::Qr): q with orthonormal columns and an upper triangular r, with the signs of LAPACK’s Householder reflectors (as JAX’s qr_p, which it computes with geqrf and orgqr). With pivoting, the decomposition of the columns permuted by LAPACK’s geqp3 (x[..., p] = q r) and the permutation p (i32[..., n]) as a third output.
RANDOM_GAMMA_GRAD
The derivative of a sample of Gamma(a, 1) with respect to a.
REAL
The real part of complex numbers.
REDUCE_MAX
The maximum over axes, propagating NaN (logical or for booleans).
REDUCE_MIN
The minimum over axes, propagating NaN (logical and for booleans).
REDUCE_SUM
Sums over axes (Params::Reduce).
REDUCE_WINDOW_MAX
The maximum over windows, propagating NaN.
REDUCE_WINDOW_MIN
The minimum over windows, propagating NaN.
REDUCE_WINDOW_SUM
Sums over windows (Params::ReduceWindow).
REGULARIZED_INCOMPLETE_BETA
The regularized incomplete beta function I_x(a, b) of (a, b, x).
REM
Remainder.
RESHAPE
Changes the shape, keeping the elements in row-major order.
REV
Reverses dimensions.
ROUND
Round to an integer (Params::Round).
RSQRT
1 / sqrt(x).
SCAN
A loop over the leading dimension of the scanned inputs (Params::Scan).
SCATTER
Writes updates at run-time start indices (Params::Scatter). With repeated indices, which update wins is unspecified.
SCATTER_ADD
Adds updates at run-time start indices.
SCATTER_MAX
Takes the maximum with updates at run-time start indices.
SCATTER_MIN
Takes the minimum with updates at run-time start indices.
SCATTER_MUL
Multiplies by updates at run-time start indices.
SCHUR
The Schur decomposition x = z t z^H of each square matrix (Params::Schur): t (quasi-triangular with standardized 2 x 2 blocks for real matrices, triangular for complex ones) and, if requested, the Schur vectors z, as JAX’s schur_p (LAPACK’s gees, without sorting). Not differentiable, as in JAX.
SELECT_AND_GATHER_ADD
For each window of the operand (the second input), the element of the tangents (the first input) at the selected element: the JVP of max (ge) or min (le) pooling (Params::SelectAndGatherAdd).
SELECT_AND_SCATTER_ADD
For each window of the operand (the second input), adds the source element (the first input) at the selected element: the gradient of max (ge) or min (le) pooling (Params::SelectAndScatterAdd).
SELECT_N
Select elements from cases.
SHIFT_LEFT
x << y.
SHIFT_RIGHT_ARITHMETIC
x >> y, filling with the sign bit.
SHIFT_RIGHT_LOGICAL
x >> y, filling with zeros.
SIGN
The sign.
SIN
Sine.
SLICE
A static slice, with strides.
SORT
Sorts operands of the same shape along a dimension, lexicographically by the first num_keys of them (Params::Sort). Floats are ordered as -inf < ... < 0 < ... < inf < NaN, with -0.0 equal to 0.0 and all NaNs equal, as in JAX.
SQRT
Square root.
SQUARE
x * x.
SUB
x - y.
SVD
The singular value decomposition of each matrix (Params::Svd): the singular values s in descending order, and with compute_uv, u and vt (a = u diag(s) vt), as JAX’s svd_p. With subset_by_index (not with full_matrices), the singular values of that range of indices and their vectors (computed from the whole decomposition; JAX supports it on TPU only).
SYMMETRIC_PRODUCT
alpha a a^T + beta c for each real a ([..., m, n]) and c ([..., m, m]) (Params::SymmetricProduct), as JAX’s symmetric_product_p: the whole matrix, as JAX computes it on CPU (on GPU, where JAX calls cuBLAS’s syrk, only the lower triangle is guaranteed, as in JAX). Not differentiable, as in JAX.
TAN
Tangent.
TANH
Hyperbolic tangent.
THREEFRY2X32
The threefry2x32 hash of the counters (x1, x2) with the key (k1, k2), elementwise; operands of rank 0 are broadcast to the shape of the others, as in JAX.
TOP_K
The k largest elements along an axis in descending order, and their indices as i32 (Params::TopK). Floats are ordered by XLA’s total order -NaN < -inf < ... < -0.0 < 0.0 < ... < inf < NaN; equal elements keep their order.
TRANSPOSE
Permutes the dimensions.
TRIANGULAR_SOLVE
Solves op(a) x = b or x op(a) = b for a triangular a (Params::TriangularSolve); only the triangle of a given by lower is read (without the diagonal for unit_diagonal).
TRIDIAGONAL
The reduction of each Hermitian (symmetric) matrix, read from its lower (or upper) triangle (Params::Tridiagonal), to real tridiagonal form by a unitary similarity, as JAX’s tridiagonal_p (LAPACK’s sytrd and hetrd): the matrix with the tridiagonal form and the Householder reflectors in that triangle (the other one untouched), the real diagonal d, the real off-diagonal e, and the n - 1 factors taus. Not differentiable, as in JAX.
TRIDIAGONAL_SOLVE
The solution x of A x = b for each tridiagonal matrix A, given by its diagonals dl (dl[..., i] = A[i, i - 1], dl[..., 0] ignored), d, and du (du[..., i] = A[i, i + 1], the last one ignored), each [..., m], and b ([..., m, n]), as JAX’s tridiagonal_solve_p (Params::TridiagonalSolve): Gaussian elimination with partial pivoting, where singular systems give NaNs, or with perturb_singular, tiny pivots perturbed so that numerically singular systems give finite solutions. Differentiable in all inputs, linear in b.
WHILE
Repeats the body while the predicate holds (Params::While).
XOR
Logical or bitwise exclusive or.
ZETA
The Hurwitz zeta function.

Functions§

all
Returns every primitive.
binary_prim
Returns the primitive of a BinaryOp.
by_name
Returns the primitive with the given name.
compare_prim
Returns the primitive of a CompareOp.
ternary_prim
Returns the primitive of a TernaryOp.
unary_prim
Returns the primitive of a UnaryOp (round and round_even map to the round primitive with a method).