Skip to main content

tiled_scatter

Function tiled_scatter 

Source
pub fn tiled_scatter(
    grid: &Grid,
    mask: &[u8],
    cfg: &TileConfig,
    cost: &TileCost,
    run_tile: impl Fn(&Tile) -> Result<Vec<f64>, OnnxError> + Sync,
    progress: impl FnMut(usize, usize),
) -> Result<Vec<f64>, OnnxError>
Expand description

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.

run_tile(&tile) must return the tile’s post-processed core block — row-major oi,oj,ok, length cx·cy·cz — and be pure + Sync: it runs on up to tile_concurrency threads at once, each holding one patch’s activations, which on WASM share a single 4 GB heap. cost is what one tile of the network costs (ModelSpec::tile_cost), which sets how many fit at once. progress(done, total) is called from the driver thread only (the JS callback isn’t Sync).