This module encapsulates the primary use cases for Apptainer in High Performance Computing.
Apptainer makes it trivial to use GPUs. You do NOT need to install the NVIDIA driver inside the container. You only need the CUDA toolkit (and cuDNN) inside. The host driver is mounted at runtime.
To enable GPU support, simply add --nv:
apptainer exec --nv pytorch.sif python train.pyApptainer supports the "Hybrid MPI" model. You have an MPI installed on the host (e.g., OpenMPI) and a compatible MPI installed inside the container.
You call mpirun from the host, which then launches apptainer containers.
mpirun -n 4 apptainer exec my_mpi_app.sif /app/mpi_binaryBy default, Apptainer binds $HOME, /tmp, and $PWD. On HPC, you often need access to scratch storage or shared datasets.
apptainer exec --bind /scratch/user:/data my_container.sif python script.pyThis maps /scratch/user on the host to /data inside the container.
See exercises/04_ml_gpu.def for a PyTorch setup.
To test it (if you have a GPU):
apptainer exec --nv ml_gpu.sif python -c "import torch; print(torch.cuda.is_available())"