CUDA Setup and Configuration¶
Loading CUDA Modules¶
# List available CUDA versions
module avail cuda
# Load a specific version
module load cuda
# Verify CUDA installation
nvcc --version
Environment Variables¶
CUDA sets these automatically when you load the module:
echo $CUDA_HOME # CUDA installation path
echo $PATH # Includes CUDA bin
echo $LD_LIBRARY_PATH # Includes CUDA libs
Installing Additional Packages¶
# Install PyTorch with CUDA support
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
# Install TensorFlow with GPU support
pip install tensorflow
# Install cuDNN
module load cudnn
Verifying GPU Access¶
# Check GPU status
nvidia-smi
# Check CUDA device
python -c "import torch; print(torch.cuda.is_available())"
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
Common CUDA Issues¶
CUDA out of memory¶
# In PyTorch, clear cache
torch.cuda.empty_cache()
# Monitor memory
nvidia-smi --query-gpu=memory.used,memory.free --format=csv
Wrong CUDA version¶
# Check your code's CUDA requirement
# Match with available modules
module avail cuda