GPU Job Basics
Last updated on 2026-08-24 | Edit this page
Overview
Questions
- When should I use a GPU?
- How do I request GPUs in SLURM?
- Which GPU type should I choose?
- How do I write a GPU batch script?
Objectives
- Understand when GPUs accelerate your work and when they do not
- Master
--gres=gpusyntax for GPU requests - Match GPU requirements to available hardware
- Write and submit GPU batch scripts
When Should You Use a GPU?
Workloads That Benefit
- Deep Learning: Training neural networks (PyTorch, TensorFlow)
- Matrix Math: Large matrix multiplications, dense linear algebra
- GPU-Accelerated Libraries: RAPIDS, CuPy, Dask-CUDA
- Molecular Dynamics: GPU-accelerated GROMACS, NAMD
- Custom CUDA Code: Parallel kernels
Workloads That Do NOT Benefit
- Single-threaded serial code
- I/O-bound jobs (waiting for disk/network)
- Light computation (simple statistics, data cleaning)
- Memory-bound sequential code
Don’t Waste GPU Resources
Before submitting a GPU job:
- Test on CPU first
- Run with
nvidia-smiand check utilization - If GPU utilization is below 50%, run on CPU instead
GPU nodes are expensive and limited. Wasting them slows everyone else down.
Requesting GPUs
GPU Batch Script
BASH
#!/bin/bash -l
#SBATCH --job-name=train_model
#SBATCH --partition=gpu
#SBATCH --gres=gpu:a100:1
#SBATCH --cpus-per-task=8
#SBATCH --mem=64G
#SBATCH --time=12:00:00
#SBATCH --output=train_%j.out
module load cuda miniconda3
source ~/ml_env/bin/activate
python train.py --epochs 100 --batch_size 128
Key points:
-
--partition=gpu: Must use the gpu partition -
--gres=gpu:a100:1: Request the GPU -
--cpus-per-task=8: GPUs still need CPU support threads -
module load cuda: Required for CUDA libraries
Interactive GPU Testing
Test GPU code before submitting batch jobs:
BASH
srun --partition=gpu --gres=gpu:l40s:1 \
--cpus-per-task=4 --mem=16G --time=00:30:00 \
--pty bash -l
Inside the session:
Challenge 1: GPU Test Job
Create and submit a GPU test script:
BASH
#!/bin/bash -l
#SBATCH --job-name=gpu_test
#SBATCH --partition=gpu
#SBATCH --gres=gpu:1
#SBATCH --cpus-per-task=2
#SBATCH --mem=8G
#SBATCH --time=00:05:00
#SBATCH --output=gpu_%j.out
module load cuda miniconda3
python << 'EOF'
import torch
print(f"CUDA available: {torch.cuda.is_available()}")
if torch.cuda.is_available():
print(f"GPU: {torch.cuda.get_device_name(0)}")
x = torch.randn(1000, 1000).cuda()
y = torch.mm(x, x)
print(f"GPU computation result shape: {y.shape}")
EOF
Submit with sbatch and check the output.
Output should show CUDA available: True, the GPU model
name, and a torch.Size([1000, 1000]) result. This confirms
your GPU job is configured correctly and the GPU is being used.
- GPUs accelerate parallel computation: deep learning, matrix math, CUDA code
- Do not use GPUs for serial, I/O-bound, or light computational tasks
- Request GPUs with
--gres=gpu:TYPE:N(e.g.,--gres=gpu:a100:1) - Always use
--partition=gpuandmodule load cudafor GPU jobs - A100 for production, L40S for prototyping and inference, RTX PRO 6000 for large-memory work
- Test GPU code interactively before submitting long batch jobs