Skip to main content

Module tiled

Module tiled 

Source
Expand description

Overlap-tiled inference for fully-convolutional deep-learning inversions (onnx).

Whole-volume nets (e.g. xQSM, QSMnet) allocate activations proportional to the entire volume, which overflows a 32-bit WASM heap (4 GB ceiling) on clinical-size data. Because these nets are fully convolutional, they can instead be run patch-by-patch: each output “core” is produced from a patch that includes a halo of surrounding context, then written back — the classic U-Net overlap-tile strategy. Peak memory is bounded by a single patch regardless of volume size.

NOTE: tiling a net trained on whole volumes is an approximation. Dipole inversion is a global operation, so a patch is blind to distant susceptibility sources; a larger halo reduces the resulting low-frequency / boundary error but does not eliminate it.

Tiles run in parallel with the parallel feature. One patch bounds memory only if the number of concurrent patches is bounded too, which on a 32-bit WASM heap it has to be — see tile_concurrency.

Re-exports§

pub use super::tile_budget::*;

Functions§

check_wasm_patch_fits
Refuse a tile config whose patch is too big for a WASM heap even on its own.
tile_concurrency
How many tiles tiled_scatter keeps in flight at once.
tile_cost_of 🔒
The cost a tiled network’s wrapper budgets with, from its registry entry (ModelSpec::tile_cost). Every tiled network has one (a test below checks), so a missing figure is a bug in the registry, not a runtime condition.
tiled_field_inversion
Run a fully-convolutional field→χ ONNX net patch-by-patch with a context halo, bounding peak memory to a single patch.
tiled_scatter
Shared overlap-tiling driver. Enumerates the core-aligned tiles that actually touch mask (all-background tiles are skipped → work is restricted to the mask bounding box for free), runs each through run_tile, and scatters the results back into a full-volume buffer (masked). Handles the empty-tile skip, parallel batching, and progress reporting so each model only supplies its own per-patch logic.
tiled_volume_algorithm
Overlap-tile an entire volume→volume algorithm (not just one forward pass). For each tile, a padded p³ sub-volume of field/mask is cut out (with halo context, zero outside the volume), run_patch(field_patch, mask_patch, patch_grid) is run on it, and the central core is written back. Use this for the FFT-unrolled nets (lpcnn/modl-qsm/nextqsm) whose Rust-side physics loop wraps a whole-volume CNN — running the whole algorithm per patch bounds memory. Strongly off-design (the dipole/k-space step then sees only a patch), so results are approximate; callers should warn and steer users to a full-volume run for real work. cost is the network’s tile cost, as for tiled_scatter; its divisor pads each patch.

Type Aliases§

Tile
A core-aligned tile: (x0, y0, z0, cx, cy, cz) — origin + core extent (clamped at edges).