Run on a GPU¶
FORGE has a Metal backend for Apple Silicon and a CUDA backend for NVIDIA GPUs. Each backend has its own copy of every program, so you choose the GPU by choosing which programs you run. GPU backends explains what runs where.
Use the GPU programs¶
Build with the backend enabled (Build and install FORGE), then put its directory first on your PATH:
export PATH="$HOME/forge/bin/metal:$HOME/forge/bin:$PATH" # Apple Silicon
export PATH="$HOME/forge/bin/cuda:$HOME/forge/bin:$PATH" # NVIDIA
Check which backend you are running: the log reports it near the start, for example Using Metal GPU backend (device 0), Using CUDA GPU device 0, or CPU-only build; --device 0 ignored.
GPU work is single precision. All the command-line programs use single precision.
Pick a CUDA device¶
On a machine with several NVIDIA GPUs, pass the index:
forgeSense [options] --device 1
Metal always uses the default GPU, and warns if --device is anything other than 0. For MPI runs, see Run a reconstruction with MPI.
Limit GPU memory¶
forgePcSenseTimeSeg and oscillateRecon process coils in batches sized to fit the GPU's memory budget. If the GPU is shared with other jobs, or you see out-of-memory errors, set a smaller budget in megabytes:
FORGE_METAL_WORKING_SET_MB=8000 forgePcSenseTimeSeg [options] # Metal
FORGE_CUDA_WORKING_SET_MB=8000 forgePcSenseTimeSeg [options] # CUDA
Without them, Metal uses the device's recommended working set and CUDA uses the free device memory at the time.
Profile a run¶
On macOS, builds define USE_SIGNPOST, so you can record a run in Instruments with the os_signpost instrument. A Metal build also has metal_profile, a standalone 3D reconstruction meant for Instruments. CUDA builds have cuda_profile for Nsight Systems, and mark ranges with NVTX.
The environment variable reference lists the other switches, which are mainly for testing.