Repository navigation
Multi GPU and Large Grids
Back to Home · Previous: Precision Modes & Calibration · Next: Distributed NCCL & Multi-Node
21cmCU scales beyond single-card 24 GB VRAM through 1D Y-slab distributed 3D cuFFT, dynamic-dlopen NCCL 2.x collective slab exchange (cuda_nccl.cuh), and out-of-core single-work-slab streaming (cuda_mgpu.cu, cuda_ic.cu), without build-time MPI or NCCL dependencies.
import py21cmcu as p21
print("Visible GPUs:", p21.cuda_device_count())
p21.set_cuda_devices([0, 1, 2]) # or "all" / "0,1,2"
with p21.use_mode("fast", devices=(0, 1, 2)):
...Or via environment variables:
export P21_CUDA_DEVICES=0,1,2
export CUDA_VISIBLE_DEVICES=0,1,2For large boxes where 2 complex slabs exceed multi-GPU VRAM (2048³ on 3× 24 GB GPUs), single-work-slab mode (P21_CUDA_MGPU_SINGLE_SLAB=1, automatically activated for Zel'dovich when needed) halves complex device slab memory.
For collective multi-GPU / multi-node transport and host-streaming options (v1.0.0):
-
P21_CUDA_MGPU_BACKEND=auto|nccl|p2p|host:autoselects dynamiclibnccl.so.2(>= 2.7) clique communicators when available and falls back seamlessly to CUDA P2P or pinned host-bounce (MgpuHostBounce). See Distributed NCCL & Multi-Node. -
P21_CUDA_MGPU_2LPT_HOST_STREAM=1(Direction P): enables slab-by-slab host streaming for2048³2LPT ICs, bringing peak host RAM below160 GiB(down from235 GiB). -
P21_CUDA_MGPU_VIRTUAL_RANKS=2|4: exercises multi-slab domain decomposition paths on a single GPU for verification.
- Each GPU owns a contiguous range of
Yslabs of(X, Y_slab, Z/2 + 1)complex data. - Batched 2D
(X, Z)R2C/C2R cuFFT plans execute locally per GPU (cuda_mgpu.cu). - Slab exchange (
X↔Ytranspose) runs via dynamic NCCL clique collectives (P21_CUDA_MGPU_BACKEND=auto|nccl), CUDA P2P, or parallelstd::threadsub-tiled transposes (MgpuHostBounce64 MiB pinnedcudaHostAllocPortablebuffers). - Batched 1D
YC2C cuFFT transforms complete the 3D transform. -
Direction K + Direction P 2LPT streaming: eliminates the
32 GiBh_tmp_abhost temporary buffer at2048³via pinned-bounce streaming subtraction and supportsp21_cuda_mgpu_filter_box_host/<160 GiBstreaming (P21_CUDA_MGPU_2LPT_HOST_STREAM=1).
Captured on cluster node b1 (1×–3× RTX 4090, 24 GB VRAM/GPU, 196 GiB Slurm RAM limit):
Grid (Voxels) |
GPUs | Algo |
v0.5.0 IC |
v0.6.0 IC |
Speedup | Total (+PF+PS) |
Path (v0.6.0) |
|---|---|---|---|---|---|---|---|
1024³ (1.074 B) |
1 | ZELDOVICH |
4.122 s |
4.288 s |
0.96× |
4.878 s |
1-GPU native |
1024³ (1.074 B) |
3 | ZELDOVICH |
4.604 s |
4.397 s |
1.05× |
4.990 s |
Multi-GPU slab |
1024³ (1.074 B) |
1 | 2LPT |
8.134 s |
8.200 s |
0.99× |
8.777 s |
1-GPU native |
1536³ (3.624 B) |
2 | ZELDOVICH |
53.903 s |
27.799 s |
1.94× |
29.691 s |
Multi-GPU slab |
1536³ (3.624 B) |
3 | ZELDOVICH |
46.131 s |
29.005 s |
1.59× |
31.024 s |
Multi-GPU slab |
1536³ (3.624 B) |
2 | 2LPT |
210.680 s |
75.231 s |
2.80× |
78.350 s |
Pinned stream |
1536³ (3.624 B) |
3 | 2LPT |
201.302 s |
91.616 s |
2.20× |
95.217 s |
Pinned stream |
1792³ (5.755 B) |
3 | ZELDOVICH |
98.095 s |
38.699 s |
2.53× |
41.754 s |
Multi-GPU slab |
1792³ (5.755 B) |
3 | 2LPT |
365.663 s |
103.892 s |
3.52× |
108.275 s |
Pinned stream |
2048³ (8.590 B) |
3 | ZELDOVICH |
216.665 s (host) |
58.467 s |
3.71× |
64.282 s |
Native in-VRAM (single_slab) |
2048³ (8.590 B) |
3 | 2LPT |
— | skipped | — | — | Needs 235 GiB > 196 GiB host RAM |
| Workload | Min GPUs | VRAM / GPU | Host RAM |
|---|---|---|---|
512³ -> 256³ Coeval (L-INTEGRAL + TS, 3z) |
1 | ~5 GB | 8 GB |
768³ EoR Coeval |
1 | ~19 GB | 16 GB |
1024³ (1.07B) 2LPT IC + PF |
1 | ~7–18 GB | 24 GB |
1536³ (3.62B) Multi-GPU 2LPT IC |
2 | ~15 GB | 90 GB |
1792³ (5.75B) Multi-GPU 2LPT IC |
3 | ~16 GB | 135 GB |
2048³ (8.59B) Single-Slab Zel'dovich / 2LPT |
3 | ~11.6 GB | 72 GB (Zel) / 235 GB (2LPT) |
Check live counters via py21cmcu.cuda_stats() (mgpu_ic_runs, mgpu_fft_runs).
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