Overview
The system watches lane position from a forward camera and classifies the driver as calm, alert, stressed or in panic, sample by sample, on an ARM Cortex-M4F. Lane position also depends on the road, so a host machine fits a model of how each stretch of the route shifts the car's position and sends the device one int16 correction per site. The device never sees the route model, only those corrections.
The work splits by cost. Fitting the route model means repeatedly solving a large sparse linear system, which belongs on a host or GPU and runs every few seconds to minutes. Classification is one small update per sample, sized for a microcontroller: 40 multiply-accumulates and 1,802 bytes of flash, in int8.
The question that decides whether the design holds is whether the int8 classifier makes the same calls as a full-precision one. On simulated drives it does: they agree on 99.66% of 5,000 samples, the gap stays under 0.04 points when sensor noise doubles, and the device catches 151 of 157 panic episodes. A live demo steps through a drive.
| Component | Status |
|---|---|
| Python reference: route model, sparse solve, per-site corrections, float and int8 classifiers | 20 pytest tests pass |
| CUDA route-model fit with cuSPARSE and cuDSS | Compiles with nvcc 12.9 against cuDSS 0.7.1.6; not linked or run, as CI has no GPU |
| Int8 classifier on Cortex-M4F | Bit-exact with the Python reference under QEMU, portable C and CMSIS-NN v8.0.0; not run on hardware |
| GPU timings, on-device latency, accuracy on recorded drives | Not measured. An operation count is not a latency |
All data are simulated with fixed seeds. Figures 2 to 9 come from the captures workflow on an ubuntu-24.04 runner.
Design rationale
Partition

C and G are assembled once; the GPU rebuilds and factorises Q(θ) and returns θ̂ and x̂ for lifting and quantisation. The figure names cuSOLVER for the factorisation; the repository uses cuDSS.cuSPARSE holds Q in CSR and performs the sparse products; cuDSS performs the SPD Cholesky factorisation, with the analysis phase executed once and the refactorisation and solve phases executed per θ. The cuSOLVER sparse Cholesky module is deprecated by NVIDIA and is not used. θ = (κ, τ) has two components and is optimised on the host.
Precision structure and ordering
The SPDE precision for α = 2 is Q = τ² (κ⁴ C + 2κ² G + G C⁻¹ G); its per-row nonzero count is invariant in grid size, whereas Cholesky fill-in is ordering dependent. The factorisation shall use a fill-reducing ordering (reverse Cuthill-McKee, AMD or METIS nested dissection) before any port to the GPU. The symbolic phase shall be hoisted out of the likelihood loop.
Lifting
The projector P is sparse: each sensor row holds the three barycentric weights of its enclosing triangle, summing to one. nnz(P) is 600 for 200 sensors; nnz(P_dev) is 192 for 64 sites. The device receives one int16 offset per site and never the grid.
Device recursion
With K = 4, the step is α_t(k) ∝ b_k(y_t) Σ_j a_jk α_(t-1)(j). Aᵀ α_(t-1) has fully connected layer shape and executes as arm_fully_connected_s8 when HMM_USE_CMSIS_NN is defined, otherwise as a portable C99 kernel with identical integer semantics.
Results
Reference test suite

python/tests/, run with CC=gcc to enable the C kernel cross-check; 20 pass in 6.50 s. Printed lines: estimates of κ and τ, factor counts for seeds 0, 1 and 2, int8 against float agreement.- Estimation:
κ̂ = 4.5744against 4.7140 (relative error 3.0%),τ̂ = 0.001452against 0.001496 (2.9%); 177 numeric factorisations after 2 symbolic analyses, the same analyse-once, refactorise-per-θpattern as the cuDSS path. - Fill-in: scrambled order 45,258, 44,510 and 43,640 factor nonzeros for seeds 0, 1 and 2; reverse Cuthill-McKee 11,378 in each case.
- Filtering: int8 against float argmax agreement 0.9966 over 5,000 samples, 0 floor hits.
The suite asserts the structural invariants: three projector weights per row summing to one, sparse and local posterior precision, a retained direct calm-to-panic transition, and bit-exactness of the C kernel with the Python mirror.
Operation counts

python/tools/mac_table.py, computed from each sparsity pattern: host stages per evaluation of θ on the 16 by 16 grid and the 20 by 20 lattice; device stages per sample.| Stage | Matrix | nnz | MACs | Per |
|---|---|---|---|---|
Cholesky of Q, RCM |
L of Q, 16 by 16 grid |
5,896 | 72,538 | θ |
| Cholesky, 20 by 20 lattice, RCM | L of Q |
11,378 | 174,362 | θ |
| Cholesky, 20 by 20 lattice, scrambled (seed 0) | L of Q |
45,258 | 3,877,939 | θ |
| Device, total per sample | Aᵀ (4 by 4, int8), emission, update |
40 | sample |
Device cost is 40 MACs per sample independent of grid size; a test asserts this for 8 by 8 and 16 by 16 grides.
Field estimate

spdegmrf.export.run_pipeline (seed 2026), 16 by 16 grid over 1.5 km, n = 256. Left: 200 sensor observations of the eighth replicate, σ = 15 mm. Centre: simulated field, κ = 4.714, τ = 0.00150. Right: posterior mean at κ̂ = 4.574, τ̂ = 0.00145, with 64 route sites coloured by P_dev x̂, from -88.6 to 9.6 mm.Marginal likelihood

Estimator.loglik on a 25 by 25 grid of (κ, τ), relative to the grid maximum, contours at -2, -5, -10 and -20. Cross: Nelder-Mead estimate. Plus sign: simulation value.Each evaluation rebuilds the values of Q(θ) on a fixed sparsity pattern, factorises, and reads log|Q| = 2 Σ log L_ii from the factor diagonal. 625 evaluations required 1,250 numeric factorisations and 2 symbolic analyses.
Sparsity

Q on the 10 by 10 lattice, 1,104 nonzeros, at most 13 per row. Centre and right: Cholesky factor of Q on the 20 by 20 lattice after the seed 0 relabelling, 45,258 nonzeros, and after reverse Cuthill-McKee, 11,378 nonzeros.Fill-in distribution

Forward filters

python/tests/test_forward_filter.py (seed 7), first 600 of 5,000 samples. Panels: observation channels; simulated regime and int8 mode; float forward posterior; int8 belief of quant.Int8Filter, dequantised as (α + 128) / 255 and normalised.| Metric | Value |
|---|---|
| Argmax agreement, 5,000 samples | 99.66% |
| Mean absolute belief error | 0.0020 |
| Floor hits | 0 |
| Agreement, 600 committed firmware vectors | 0.9933 |
qemu-arm -cpu cortex-m4, portable and CMSIS-NN kernels |
Bit-exact with the Python mirror |
CUDA compilation

gpu/src/spde_gpu.cu against the cuDSS 0.7.1.6 headers. Against cuDSS 1.0.0.35 it fails with eight errors at lines 179 and 181, where cudssMatrixCreateCsr takes an additional offsetType argument.Stress tests


κ) and 3.8% for the variance scale (τ); every estimate within 20% of truth. The two errors are negatively correlated (r = -0.73). Data: Hugging Face dataset, linked below.Observations
- Ordering dominates host cost: RCM reduces the 20 by 20 lattice factorisation from 3,877,939 MACs to 174,362, and the scrambled factor carries roughly four times the RCM nonzeros.
- The likelihood surface is the target GPU workload; the 1,250 to 2 ratio of numeric factorisations to symbolic analyses confirms that symbolic reuse is mandatory.
- The case study scrambled count of 37,615 is a valid but atypical draw: 2.5% of the 1,000 relabellings yield that many nonzeros or fewer. This post uses the repository values, 45,258 scrambled and 11,378 after RCM.
- int8 quantisation does not alter the MAP decision; the lower two panels of Figure 8 are indistinguishable at plot scale.
- The CUDA source typechecks against cuDSS 0.7.1.6 and is broken by the cuDSS 1.0.0.35 API change. Figure 9 establishes nothing about GPU performance.
Limitations
- The CUDA object is compiled only, not linked and never run on a GPU. Before any GPU result is reported, the GPU path shall be checked against
gpu/compare.pyon a GPU. - No latency claim shall be derived from MAC counts without a measurement on the target. QEMU provides no cycle counts.
- RCM yields 11,378 or 11,370 nonzeros depending on input labelling: 500 and 500 of 1,000 seeds in this run, 502 and 498 in an earlier run. The cause of the inter-run variation has not been established. Seeds 0, 1 and 2, used by the tests, gave 11,378 in every run.
- GPU estimation and on-device timing remain unmeasured; no result above substitutes for either.
Source:



