Skip to content

Rework the einsum f32 JIT with static backend dispatch per spec pattern - #115

Open
MesTTo wants to merge 3 commits into
trueagi-io:mainfrom
MesTTo:pr/linalg-jit-einsum
Open

Rework the einsum f32 JIT with static backend dispatch per spec pattern#115
MesTTo wants to merge 3 commits into
trueagi-io:mainfrom
MesTTo:pr/linalg-jit-einsum

Conversation

@MesTTo

@MesTTo MesTTo commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Adds a plan layer over the existing Cranelift einsum JIT: EinsumF32Plan / einsum_auto, typed fallible execution (try_run, JitRunError) replacing panic-only run, a native sparse-dense matmul routine, and recognizers that route GEMM-shaped and attention-shaped specs to the BLAS kernels when the blas feature is on.

The dispatch is static and structural, decided once at plan-compile time — a fixed precedence (sparse-dense matmul pattern, then BLAS-recognized dense patterns under #[cfg(feature = "blas")], else the general JIT loop nest), keyed purely on the spec's subscript structure and input kinds. There is no cost model, no runtime data, no thresholds — the same shape-recognition dispatch numpy/torch do for GEMM-shaped einsums.

Depends on #111 (the OpenBLAS backend module): building --features jit,blas without it fails to resolve crate::blas_backend, so #111 should merge first. Validation: --features jit 69/0 green standalone; with #111, --features jit,blas 63/0 green including the four plan_selects_* dispatch tests. #121's graph_tensor consumes einsum_auto for its GCN SpMM.

@MesTTo MesTTo changed the title Rework einsum f32 JIT with backend kernel selection Rework the einsum f32 JIT with static backend dispatch per spec pattern Jul 4, 2026
The owned Dense|Csr enum had no consumers (the benches use any::Tensor, which
already covers these variants plus DenseMut) and it shadowed that name. The
benches/graph.rs hunk was pure reformatting of code this branch does not
otherwise touch; restore main's formatting so the diff is only the plan layer.
@Adam-Vandervorst

Copy link
Copy Markdown
Collaborator

Awesome! We'll want to stabilize and generalize the JIT before integrating this change (see #132 )

@MesTTo

MesTTo commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

that makes sense to me, and i am in no rush on this one. i think it sits behind #132 either way,
since the static-dispatch rework here assumes the spec-pattern classification that #132 is changing.
i will rebase once the JIT generalization lands rather than have you carry a conflict.

the VM monomorphization i measured on #132 (-6.84% instructions, (Sum, Mul) only) is orthogonal to
this PR and does not need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants