Parent: trueno-spec.md Sections 3, 4
Backend::Auto resolves at Vector creation time via is_x86_feature_detected!(). This runs once — not per-operation.
Priority order:
- CUDA (NVIDIA GPU + parallel workload)
- wgpu (cross-platform GPU + >100K elements)
- AVX-512 (Zen4/Sapphire Rapids+)
- AVX2+FMA (preferred x86_64)
- AVX
- SSE2 (baseline x86_64)
- NEON (ARM64)
- SIMD128 (WASM)
- Scalar (always available)
GPU dispatch thresholds depend on operation complexity:
| Complexity | Examples | GPU threshold |
|---|---|---|
| Low | add, mul, relu | >1M elements |
| Medium | dot, reduce, softmax | >100K elements |
| High | matmul, conv2d, attention | >10K elements |
Below threshold → SIMD. Above → GPU (if available).
Every operation MUST work on ALL backends. No exceptions.
Implementation checklist for new operation frobulate():
- Contract first:
contracts/frobulate-v1.yaml - Register binding:
../provable-contracts/contracts/trueno/binding.yaml - Trait method:
VectorBackend::frobulate()insrc/backends/mod.rs - Scalar:
src/backends/scalar/— pure Rust, baseline correctness - SSE2:
src/backends/sse2/— 4x f32 per iteration - AVX2:
src/backends/avx2/— 8x f32, FMA if applicable - AVX-512:
src/backends/avx512/— 16x f32 - NEON:
src/backends/neon/— 4x f32 (ARM) - WASM:
src/backends/wasm/— 4x f32 (SIMD128) - wgpu shader:
src/backends/gpu/shaders/ - wgpu device:
src/backends/gpu/device/— sync + async methods - Integration test:
tests/backend_story.rs
If GPU acceleration is not beneficial (e.g., inherently sequential), the GPU method MUST:
- Fall back to CPU implementation
- Document why in a comment
- Still pass the backend story test
// src/backends/mod.rs — simplified dispatch pattern
match self.backend {
Backend::Avx512 => unsafe { avx512::frobulate(a, result) },
Backend::Avx2 => unsafe { avx2::frobulate(a, result) },
Backend::Sse2 => unsafe { sse2::frobulate(a, result) },
Backend::Neon => unsafe { neon::frobulate(a, result) },
Backend::Wasm => unsafe { wasm::frobulate(a, result) },
Backend::Scalar => scalar::frobulate(a, result),
}- Integration test:
tests/backend_story.rstests all backends - CI: runs backend story tests on every PR
- Contract: FALSIFY tests verify backend equivalence (tolerance < 1e-5)