# Welcome to the 21cmCU Wiki **21cmCU** (`py21cmcu` `v1.0.0`, `90` native CUDA APIs / `54` CFFI exports) is a native **C/CUDA + cuFFT** cosmological 21cm simulation, inference, and multi-probe analysis engine with full **21cmFAST v4** API/CLI compatibility and **zero CuPy or Numba runtime dependency**. ### Quick Facts at a Glance - **Drop-in `21cmFAST v4` API & CLI**: Re-exports `py21cmfast.*` while adding `strict` (CPU-matched IEEE FP32) and 6-seed calibrated `fast` GPU modes (`use_mode("fast", lazy_d2h=True)`). - **Scale**: Single-GPU mocks/coevals/lightcones up to `768³–1024³`, and Y-slab multi-GPU FFT/IC up to `2048³` (`58.47 s` Zel'dovich on `3× RTX 4090`, `<160 GiB` Direction P host-streamed 2LPT) plus runtime `dlopen` NCCL 2.x (`cuda_nccl.cuh`). - **Science Stack Built In**: Interferometer mocks (`SKA1-Low`/`HERA-350`), 21cm×galaxy cross-power, patchy kSZ, 3D bispectrum/MFP/Minkowski, CRN Fisher, `OnlineSBIDataset`, compiled C99 Nested Sampling & Ensemble MCMC (`21cmcu infer`). - **Project Resources**: [GitHub Releases](https://github.com/HainaHuang729/21cmCU/releases) · [Citation (`CITATION.cff`)](../../CITATION.cff) · [Machine-Readable Index (`llms.txt`)](../../llms.txt) · [Methods Paper](../paper/21cmcu_paper.md) ## Headline Performance (`v0.6.0–v1.0.0` on RTX 4090 & Tesla T4 vs CPU) | Workload | CPU 16T | `21cmCU` GPU (`fast`) | Speedup | | --- | ---: | ---: | ---: | | `apply_rsds` (`128 × 128 × 512`) | `0.0967 s` (`C/OpenMP`, `395.26×` vs `38.2230 s` Py) | `0.0764 s` (`1× 4090`) | **`492.74×` GPU / `395.26×` CPU** | | Rectilinear Lightcone (`256/128`, `z=6.5–11`, RSD+dvdr) | `248.773 s` | `3.032 s` (`1× 4090`) | **`82.05×`** | | `SKA1-Low / HERA-350` 3D Mock (`256³`) | `1.651 s / 1.616 s` | `23.04 ms / 22.48 ms` | **`71.65× / 71.88×`** | | 1-Point Moments+PDF / Wedge Filter (`256³`) | — | `26.43× / 23.86×` vs CPU | **`26.43× / 23.86×`** | | `AngularLightconer` (`256/128`, `z=7.8–9.8`, RSD+dvdr) | `97.018 s` | `4.698 s` (`1× 4090`) | **`20.65×`** | | Coeval 3z (`512/256`, `L-INTEGRAL + TS`) | `55.079 s` | `4.456 s` (`1× 4090`) | **`12.36×`** | | Concurrent Batch (`4 × 192/96`, `w=2`) | `14.184 s` | `3.097 s` (`1× 4090`) | **`4.58×`** | | `2048³` (`8.590 B` voxels) Zel'dovich IC | `216.665 s` (`v0.5.0` host) | `58.467 s` (`3× 4090` native VRAM) | **`3.71×`** | | SBI Batch Sweep (`16 × 192/96`, `2× 4090`) | — | `5.888 s` (`9,782.0 tasks/h`) | **`1.41×` vs 1 GPU** | | Zero-D2H Lightcone (`256/128`, 12z `L-INTEGRAL`) | `1.496 s` (`lazy_d2h=False`) | `1.169 s` (`1× 4090`, `lazy_d2h=True`) | **`-21.9%` time / `-8.5%` D2H** | | `cic_deposit_3d` / `cross_power_21cm_galaxy` (`256³`, 1M halos) | `1.463 s / 3.003 s` (T4 host CPU) | `0.037 s / 0.109 s` (`1× T4`, dev pre-1.0) | **`39.40× / 27.67×`** | ### What's New in `v1.0.0` - **Dynamic-`dlopen` NCCL 2.x Collective Backend**: Zero-compile-dependency runtime resolution of `libnccl.so.2` (`>= 2.7`) in `cuda_nccl.cuh`, `P21_CUDA_MGPU_BACKEND=auto|nccl|p2p|host` slab exchange, and [`py21cmcu.distributed`](Distributed-NCCL-and-Multi-Node.md) (`NcclContext`, `nccl_alltoall_f32`, `nccl_allreduce_f64`, `distributed_batch_partition`, `reduce_fisher_results`). Single-GPU single-rank (`n_ranks=1`) host-staged dispatch was validated on Colab Tesla T4 (`NCCL 2.28.3`, `23/23` native GPU tests passed), while true multi-GPU slab scaling (`1536³–2048³`) is established across `2×–3× RTX 4090`. - **Hardened C99 Bayesian Inference Engine & `21cmcu infer` CLI**: Compiled C99 Multi-Ellipsoid + Slice Nested Sampling (`run_nested_sampling`) and Stretch + DE-MC Ensemble MCMC (`run_native_mcmc`) compiled with `-O3 -ffast-math -fno-finite-math-only`, plateau bulk-eviction, provenance-checked HDF5 checkpoints, autocorrelation-adjusted ESS & stuck-chain detection, and `audit_posterior_native`. - **Multi-Probe Cross-Correlations, kSZ, CRN Fisher & 3D Topology**: `load_gravitycu_halos`, GPU `cic_deposit_3d`, weighted shot-noise `cross_power_21cm_galaxy`, `ksz_momentum_map`, `bispectrum_3d`, `bubble_size_distribution_mfp`, `minkowski_functionals_3d`, and degenerate-safe `fisher_forecast_21cm`. - **Hardened SBI & `Likelihood21cm`**: Fixed observation masking (`NaN -> -inf`), scale-invariant Schur-complement `cov_inv` marginalization, `model_error_frac` Gaussian normalization, unified coeval `out_redshift` selection, lightcone `wedge_filter`, unified lightcone chunking, and SHA-256 fingerprint validation on `run_batch(..., resume=True)`. --- ## Wiki Navigation | Guide | Topic | | --- | --- | | [Installation & Containers](Installation-and-Containers.md) | One-command `install.sh`, `USE_CUDA=1` build, Docker & Apptainer (Slurm), `21cmcu doctor` | | [Quickstart](Quickstart.md) | 5-minute Python & CLI walkthrough + runnable `examples/01–10` & Jupyter Notebook | | [Precision Modes & Calibration](Precision-Modes-and-Calibration.md) | `strict` vs `fast` mode parity & 6-seed statistical calibration | | [Multi-GPU & Large Grids](Multi-GPU-and-Large-Grids.md) | `CUDA_DEVICES`, Y-slab FFT, Direction P `<160 GiB` 2LPT, single-slab `2048³` | | [Residency & I/O](Residency-and-IO.md) | `CUDA_LAZY_D2H`, `DeviceFieldRegistry`, `DeviceLZF` HDF5, and `CLASS` table cache | | [SBI & Batch Pipeline](SBI-and-Batch-Pipeline.md) | Horizon wedge, thermal noise, warm `BatchPool`, SHA-256 `resume`, `SBISimulator`, `OnlineSBIDataset` | | [Bayesian Inference & Samplers](Bayesian-Inference-and-Samplers.md) | `Likelihood21cm`, `JointLikelihood`, C99 `run_nested_sampling` & `run_native_mcmc`, `21cmcu infer`, `audit_posterior_native` | | [Multi-Probe, Fisher & Topology](Multi-Probe-Fisher-and-Topology.md) | `gravityCU` halos, GPU CIC, 21cm×galaxy cross-PS, patchy kSZ, 3D bispectrum/MFP/Minkowski, CRN Fisher | | [Distributed NCCL & Multi-Node](Distributed-NCCL-and-Multi-Node.md) | Zero-compile-dep `dlopen` NCCL 2.x, `NcclContext`, `distributed_batch_partition`, `reduce_fisher_results` | | [Interferometer Mock & Forecast](Interferometer-Mock-and-Forecast.md) | `SKA1-Low`/`HERA-350`/`MWA-II`/`LOFAR`, single-pass GPU mock observations, 1D/2D SNR forecasts | | [Lightcone Optimization & 3D Viz](Lightcone-Optimization-and-3D-Viz.md) | One-line `quick_lightcone`, zero-D2H lightcones, `to_torch` DLPack, and offline WebGL2 3D viewer | | [CLI & API Reference](CLI-and-API-Reference.md) | `21cmcu` subcommands (`batch`, `infer`, `doctor`, `version`), `P21_*` env vars, and `py21cmcu` exports | | [Upstream & CPU Optimization](Upstream-Comparison-and-CPU-Optimization.md) | Upstream 21cmFAST v4 roadmap, CPU fallbacks, implemented bit-exact CPU optimizations, & accuracy summary | | [Architecture Overview](Architecture-Overview.md) | Native CFFI CUDA engine layout (`cuda_nccl.cuh`, `inference_samplers.c`), Philox RNG, 64-bit indexing | | [Troubleshooting & FAQ](Troubleshooting-and-FAQ.md) | Common HPC build issues, NCCL discovery, `resume` fingerprints, v4 `_ACG` naming, OOM tuning | --- ## Syncing This Wiki to GitHub (`*.wiki.git`) Repository maintainers can publish updates from `docs/wiki/` to the GitHub Wiki remote directly: ```bash git clone git@github.com:HainaHuang729/21cmCU.wiki.git /tmp/21cmCU.wiki cp docs/wiki/*.md /tmp/21cmCU.wiki/ cd /tmp/21cmCU.wiki && git add -A && git commit -m "Sync v1.0.0 wiki" && git push ``` ## Function Wiki and examples - [[Source Function Reference]] - [Basic examples by feature](https://github.com/HainaHuang729/21cmCU/blob/main/docs/examples/README.md) - [Documentation home](https://github.com/HainaHuang729/21cmCU/blob/main/docs/Documentation.md)