Repository navigation
Description
Stage 4 of #56. The single-launch packed-GPU kernels for the compact flux-form Diffusion leaf, and the conservative-transfer work regrid! needs before a conserved field can ride an adaptive forest. Depends on stage 3.
Packed-GPU kernels
Add _forest_sweep! and _forest_adjoint_sweep! overrides for Diffusion over a PackedBlockField, in src/operators/forest_packed.jl. Follow the file's established shape:
- open with the standard guard —
backend isa KernelAbstractions.GPU || return _forest_sweep_leaves!(...)— because broadcast fusion beats KernelAbstractions CPU codegen by roughly 1.6× measured, so the CPU path must keep falling back; - reuse the same per-cell stencil body the broadcast path uses (
_diff_at/diffusion_stencil) so the numerical definition cannot fork, exactly as the existing kernels reuse_lap_at; - recompute per-leaf geometry from the levels SoA via
_leaf_inv_h2/_halo_cell, and read κ at the halo-offset interior index the way_scalefield_forest_kernel!does.
Note that Advection currently has no packed adjoint kernel and degrades to the per-leaf sweep; Diffusion should ship both directions rather than inherit that gap.
PackedBlockField coefficient packing lands in stage 3 via _prepare_tree; this stage makes the kernels use it.
AMR conservation (#54 §4)
Independent of the kernels, and the reason this stage is not purely a performance change. Today regrid! coarsens with a conservative 2^-N child mean but prolongs with linear interpolation, which does not preserve the volume-weighted mean of the children.
- Add mean-preserving prolongation: the volume-weighted mean of the new children must equal the old parent exactly, including at block and physical boundaries.
- Keep the existing linear-exact interpolation available for non-conserved smooth fields — it is the right transfer for those, and this is not a replacement.
- Add a slope-limited prolongation policy before using this path for discontinuous solutions.
- Make conservation semantics explicit per field, so geometric indicators, coefficients, and conserved state do not all silently inherit the same transfer policy. This is the piece most likely to cause a quiet wrong answer later; it should not be a default.
- The policy must not add runtime branching to operator hot paths — attach it to the field, resolve it at transfer time.
Acceptance
- CPU/GPU and packed/reference parity within existing tolerances, for forward and adjoint, both averaging policies. Gated tests only run under
MFO_TEST_GPU=truewith CUDA available, so a green local suite proves nothing here — read the CI matrix. - Prepared applications stay allocation-free on the established CPU hot paths and keep a leaf-count-independent launch structure on packed GPUs.
Σ V·uis preserved to roundoff across refinement and coarsening for fields using conservative transfer, including balance-induced refinements (the 2:1 balance pass can refine blocks the user never marked).- The adapted Niederer-style benchmark performs no more halo exchanges per diffusion application than before, with a phase breakdown comparable to meta(amr): forest performance — the coarse–fine exchange, not regridding, is the AMR tax #49.
Activity