Repository navigation
Architecture Overview
Amadeus edited this page Nov 29, 2026
·
3 revisions
Back to Home · Previous: CLI & API Reference · Next: Troubleshooting & FAQ
Instead of dispatching PyTorch/CuPy arrays across Python bindings, 21cmCU compiles all CUDA C/C++ kernels directly inside src/py21cmfast/c_21cmfast via build_cffi.py:
-
Memory & Caching:
-
cuda_mempool.cu:cudaMemPoolarena allocator,DeviceFieldRegistrykeyed by 16 KB parallel GPU chunk-tree cryptographic hashes (F_hash), LRU stale eviction (reclaim_stale_registry_for_oom), and cuFFT plan LRU (up to 16 cached plans). - 64-bit element indexing across all 3D kernels eliminates 32-bit overflow above
$2^{31}$ voxels (1536³–2048³).
-
-
Physical Simulation Stages:
-
cuda_ic.cu&cuda_philox.cuh: parallel Philox4×32-10RNG,EH/CLASS(FLUCTS) power-spectrum seeding, Zel'dovich & low-VRAM 2LPT potential scheduling. -
cuda_perturb.cu: adaptive float32/float64 displacement/velocity perturbation (slab-Xstreaming). -
cuda_tables_build.cu,cuda_sampler.cu,cuda_halos.cu,cuda_dexm.cu,cuda_sources.cu: discrete halo realizations (CHMF-SAMPLER,DEXM-ESF,L-INTEGRAL,USE_MCGS). -
cuda_radiation.cu,cuda_spin_temp.cu,cuda_ionization.cu,cuda_brightness.cu: spin temperature (LYA_MULTIPLE_SCATTERING), inhomogeneous recombinations,E-INTEGRAL/CONST-ION-EFF/L-INTEGRALionization, and brightness temperature.
-
-
Analysis, Lightcones, Topology, Multi-Probe & Multi-GPU:
- Shared RAII & grid-stride infrastructure (
cuda_analysis_common.cuh:P21_GRID_STRIDE_LOOP,p21_grid_blocks,ScopedFloatView,ScopedPoolBuf). - Domain-split
.cumodules:cuda_lightcone_ps.cu(include_dvdr_in_tau21, column-parallelrsds_shift,RectilinearLightconer/AngularLightconer, 1D/2D single-GPU & multi-GPU PS),cuda_observables.cu(wedge filter, Philox thermal noise, moments/PDF, single-pass interferometer mocks, field mean),cuda_topology.cu(3D bispectrum, Philox MFP BSD, Minkowski functionals), andcuda_multiprobe.cu(periodic 3D CIC deposition). -
cuda_filters.cuh: shared GPUk-space filter helpers. -
cuda_io.cu: GPU byte-shuffledliblzfHDF5 chunk compressor (DeviceLZF). -
cuda_mgpu.cu&cuda_nccl.cuh: Y-slab distributed 3D cuFFT, zero-compile-depdlopenNCCL 2.x collective exchange (P21_CUDA_MGPU_BACKEND=auto|nccl|p2p|host), 64 MiB pinned portable bounce buffers (MgpuHostBounce),std::threadsub-tiled transposes, single-work-slab streaming, and Direction P host-streaming (p21_cuda_mgpu_filter_box_host,<160 GiB2048³2LPT).
- Shared RAII & grid-stride infrastructure (
-
Native C99 Bayesian Inference Engine (
inference_samplers.c):- Compiled directly into
_21cmfastCFFI with-O3 -ffast-math -fno-finite-math-only(preserving exact±inf/NaNboundary rejection and zero-variance constant-chain detection), providing multi-ellipsoid clustering, slice sampling, variable-$N_{\mathrm{live}}$ Skilling quadrature, Goodman–Weare Stretch + DE-MC proposals, split-$\widehat{R}$, and Sokal IAT/ESS diagnostics.
- Compiled directly into
-
Build & ABI Tooling (
build_cffi.py,scripts/check_cuda_abi.py):- Parallel
nvcccompilation (P21_NVCC_JOBS), incremental.flags.stamp+ header mtime tracking, and generatedbuild/compile_commands.jsonfor IDE/clangd indexing. - Automated CI verification via
scripts/check_cuda_abi.pyguaranteeing 1:1 parity acrosscuda_api.h(90APIs),cuda_stubs.c(90),cuda/*.cu(90across 21.cufiles), and_functionprototypes_wrapper.h(54CFFI exports).
- Parallel
-
Modular Python Facade (
src/py21cmcu/):- PEP 621 single-source versioning (
_version.py), PEP 561py.typed, isolated runtime helpers (_runtime.py), PEP 562 lazy top-level imports (__init__.py), shared internal utilities (_internal.py), andMapping-compatible frozen dataclasses (_results.py:PowerSpectrum1DResult,PowerSpectrum2DResult,BispectrumResult,MFPResult,MinkowskiResult,CrossPowerResult,KSZMapResult,NestedSamplingResult,PosteriorAuditResult). - Domain modules:
observables.py,analysis.py,instrument.py,topology.py,multiprobe.py,fisher.py,inference.py,samplers.py,distributed.py,batch.py,shortcuts.py,viz.py,doctor.py,cli.py.
- PEP 621 single-source versioning (
-
Photon-conservation calibration arrays (
photoncons.py): aligned redshift and neutral-fraction lengths acrosscompute_fesc_calibrations/ spline construction. -
st_taylor_factornull guard (hmf.c): safe guard for optional null outputs whenSAMPLE_METHOD="PARTITION". -
Previous-redshift ACG table separation (
interp_tables.c/cuda_ionization.cu): dedicatedNion_conditional_table1D_acg_prevprevents cross-step table contamination underE-INTEGRAL+USE_MCGS=Truewithout photoheating feedback.
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