Dropping C HDF5, Fixed-Chunk Determinism, and Where the GPU Code Stands
Replacing libhdf5 and CMake with pure-Rust storage, keeping parallel reductions bitwise identical, and separating today's WGSL shaders from long-term Rust GPU plans.
Scientific Rust tools often claim pure-Rust portability until you inspect how they read and write field data — at which point CMake, a C compiler, and a platform hdf5.dll or libhdf5.so quietly reappear. nyx spent its first phases linking hdf5-metno, forcing contributors and CI runners to wrestle with HDF5_DIR while producing results files whose layout fractured badly on 3D quadratic meshes (ADR 0107).
In that original layout (L1LegacyGzip3), saving a 14-mode 3D mechanical or electromagnetic run created $O(16 \times M)$ separate B-tree dataset headers compressed individually with Deflate(3). Files grew to 69–600 MB with only 1.07×–2.45× compression on cell_fields, reading one quantity buffered the whole archive into memory, and long parameter sweeps had no way to append points incrementally.
Zero-C hdf5-pure and a Packed 5D Layout
ADR 0107 replaced hdf5-metno across the workspace with crates/nyx-storage, built on pure-Rust hdf5-pure and pure-Rust SIMD zlib-rs (with fast-deflate deliberately disabled so C zlib-ng cannot sneak into the build graph). CI Gate EC-00 enforces zero C toolchain involvement directly by compiling with poisoned CC, CXX, and CMAKE variables.
Just swapping the reader was not enough; changing the on-disk layout solved the scaling bottleneck (FieldStorageLayout::L2ShuffleLzfPacked):
- All $M$ modes of a physics study pack into one 5D dataset,
/results/<physics>/cell_fields_packed, shaped[M, C, N_c, N_v, R](R = 1for real fields,R = 2when any component is complex). - Each mode occupies one chunk
[1, C, N_c, N_v, R]filtered with HDF5’s standard byte-shuffle (id = 2) followed byLZF(id = 32000), leaving every file readable directly by vanilla Pythonh5pywithout custom filter plugins. - Byte-shuffling IEEE-754 mantissa and exponent lanes ahead of
LZFcut file size by 3.2× (reaching 16.3× compression on 3DTet10meshes) and accelerated writes 4.2× compared toDeflate(3). - Positional streaming (
open_streamingplusReadBudgetConfig) letsnyxslice a single 60 MB mode from a 600 MB 3D solve with ~57.2 MB peak RSS delta while assertingCHECKEDinteger bounds on corrupted headers before allocating memory.
One legacy promise was cut cleanly during that work: the old phdf5 MPI-IO parallel write flag had never been built or run (RESULTS_FORMAT_STUDY.md), so H5Mode::Parallel now stays an explicit zero-C stub returning an error in favour of atomic whole-file renames and in-place sweep checkpoints (SweepCheckpoint).
Fixed-Chunk Parallelism — and Where Determinism Stops
Reproducing regression baselines requires numerical answers not to wander when a run moves from 1 core to 8. Standard parallel .sum() folds over rayon iterators reassociate floating-point rounding differently whenever work-stealing schedules shift chunks between threads.
ADR 0011 solved thread-count drift by enforcing fixed-size chunking in femcore::par and femcore::linalg::par: parallel element assembly and vector reductions always partition into chunk sizes independent of thread count (NYX_THREADS), accumulate per-chunk partials, and fold chunks strictly in index order. Across electrostatics, adaptation, DGTD, FDTD, and post-processing, NYX_THREADS=1 and NYX_THREADS=8 match to zero ULPs.
Where determinism does not hold is documented just as explicitly:
- Cross-machine BLAS/FMA differences: High-throughput CPU BLAS kernels vary FMA contraction and cache blocking by instruction set (
--features portable-kernelstrades some restart-multiply speed for cross-CPU parity under< 1e-13differential gates). - Parallel 3D sparse direct factorisations (
faer): Multi-threadedfaersparse LU/LDLT in 3Demsexhibits3.59e-10to1.15e-7relative eigenvalue drift between 1 and 8 threads due to internal task scheduling.
Where the GPU Code Stands Today
Recent additions (ADR 0146) added GPU execution to nyx, and it is important to be clear about what language actually runs on the hardware today.
Default builds (cargo build --release) remain 100% pure Rust on the CPU with zero GPU dependencies compiled into the workspace. Passing --features gpu enables a shared wgpu runtime across Vulkan, DirectX 12, and Metal targeting two time-domain electromagnetic solvers (Study::Fdtd and Study::Dgtd) plus mixed-precision AmgF32/SellCSigma linear operators (femcore::linalg::gpu). Those compute kernels are currently written as WGSL shaders executed through wgpu, not Rust code compiled directly to the GPU.1.To preserve repeatability across GPU runs, energy integrals and vector inner products avoid floating-point atomics and use two-level workgroup shared-memory binary reduction trees (@workgroup_size(64) and @workgroup_size(256)).
Several explicit guardrails govern when gpu falls back to CPU with a gpu_fallback_to_cpu warning:
- Double precision hardware support:
backend = "auto"picksf32for large linear time-domain grids (>= 250,000FDTD cells or>= 50,000DGTD DOFs on discrete GPUs), selectingf64only when nonlinear optics is enabled and the adapter exposeswgpu::Features::SHADER_F64. Requestingprecision = "f64"on a card withoutSHADER_F64drops cleanly back to CPUf64. - Advanced features still CPU-only: Multi-tier Local Time-Stepping (
n_lts_tiers > 1) inDgtdand dispersive Drude/Lorentz ADE poles currently execute on the CPU rather than maintaining diverging shader paths.
Because solvers program against femcore::linalg::device’s backend-agnostic Vector, DeviceLinearOperator, and DevicePreconditioner traits rather than raw buffer handles, wgpu/WGSL acts as a portable Tier-1 layer. Longer term, the roadmap plans to move compute kernels to Rust-native GPU toolchains (such as CubeCL or rust-gpu) once portable f64 support stabilises, alongside native CUDA/ROCm/cluster backends.