Repository navigation
Residency and IO
Back to Home · Previous: Multi-GPU & Large Grids · Next: SBI & Batch Pipeline
21cmCU minimizes PCIe host-to-device (H2D) and device-to-host (D2H) copies as well as disk I/O bottlenecks across multi-redshift simulations.
In default (eager) mode, fields produced by GPU stages are copied back to host NumPy arrays while retaining a synchronized GPU copy in DeviceFieldRegistry keyed by parallel 16 KB chunk-tree cryptographic fingerprints.
When opt-in CUDA_LAZY_D2H=True is enabled (P21_CUDA_LAZY_D2H=1 or use_mode(..., lazy_d2h=True)):
- Intermediate fields (
EmissivityFields,RadiationFields, and coeval stages) remain GPU-resident only (_CudaBufferOwner) until explicitly read back by Python (array[...]), evicted by LRU under VRAM pressure, or needed by a CPU fallback. - Verified on
512/2563zL-INTEGRAL + TScoeval (1× RTX 4090):-
D2H traffic:
7,113.54 MB→5,570.04 MB(-21.7%,0.00 GBH2D,408registry hits) -
Runtime:
4.477 s→3.904 s(-12.8%)
-
D2H traffic:
- Verified on
256/128L-INTEGRAL + TSlightcone (z=7–11): D2H drops24.3%(1,723.60 MB → 1,304.17 MB) and runtime improves1.45×(1.912 s → 1.322 s).
export P21_CUDA_REGISTRY_MB=4096 # Cap device registry budget in MiB
export P21_CUDA_REGISTRY_MAX_ENTRY_MB=2048import py21cmcu as p21
print(p21.cuda_stats()) # inspect registry_hits, registry_d2h_bytes, etc.
p21.cleanup_cuda() # release pooled VRAM, cuFFT plans, and registry buffersLarge float32 lightcone cubes bottleneck on CPU HDF5 compression (h5py LZF). 21cmCU implements HDF5-native byte-shuffled liblzf compression directly on the GPU (cuda_io.cu):
import py21cmcu as p21
p21.save_lightcone(lc, "lightcone.h5", compression="device-lzf")- Output files use standard HDF5 LZF chunks readable by any Python/
h5pyclient with zero custom HDF5 plugins required. - Automatically flags non-finite values, falls back per chunk on incompressible noise (
filter_mask), and falls back to CPU ifUSE_CUDA=False. - Verified on
256 × 256 × 512(256.0 MBraw,chunk_z=32):476.3 MB/swrite (0.5375 s,2.75×ratio) vs259.6 MB/s(0.9860 s,3.30×) CPUh5pyLZF (1.83×faster).
When running V_CB_MODEL="FLUCTS" (CLASS transfer tables) or AngularLightconer, cold CosmoTables construction is cached across Python calls (in-memory LRU) and across processes (atomic .npz cache under config["direc"]/class_tables_cache):
- Cold
CosmoTablesbuild:0.634 s→0.000311 smemory hit /0.0027 sdisk hit (results_rtx4090_v060.json); full192/64CHMF-SAMPLER + CLASStable build17.1857 s→0.002208 smemory (7,783×) /0.0028 sdisk (6,214×). - Control via
P21_CLASS_CACHE,P21_CLASS_DISK_CACHE, and clear in-memory caches viapy21cmcu.clear_class_cache().
21cmCU v1.0.0 · Native C/CUDA + cuFFT Engine for 21cmFAST v4 · See CHANGELOG.md and BENCHMARKS.md in the main repository.
Getting Started
Simulation & Science Pipelines
- Precision Modes & Calibration
- Multi-GPU & Large Grids
- Distributed NCCL & Multi-Node
- Residency & I/O
- SBI & Batch Pipeline
- Bayesian Inference & Samplers
- Multi-Probe, Fisher & Topology
- Interferometer Mock & Forecast
- Lightcone Optimization & 3D Viz
Reference