Skip to content

GPU Jobs

Exercises

  1. Request 1 GPU and verify the allocation

Submit a job to the GPU partition requesting 1 GPU. Inside the job, run nvidia-smi to confirm a GPU was allocated, and print $CUDA_VISIBLE_DEVICES to see which GPU device was assigned.

Hint / Solution
sbatch --partition=gpu --gres=gpu:1 --cpus-per-task=4 --mem=16G \
    --time=00:10:00 --output=gpu_test_%j.out --job-name=gpu_test \
    --wrap='echo "CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES"; nvidia-smi'
Expected output: Validated 2026-04-15 on slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ sbatch --partition=gpu --gres=gpu:1 --cpus-per-task=4 --mem=8G --time=00:10:00 --job-name=val_gpu1 --output=gpu_%j.out --wrap='echo CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES; nvidia-smi'
Submitted batch job 42

$ cat gpu_42.out
CUDA_VISIBLE_DEVICES=0
Wed Apr 15 02:10:34 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.105.08             Driver Version: 580.105.08     CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  Tesla T4                       On  |   00000000:00:1E.0 Off |                    0 |
| N/A   35C    P8             13W /   70W |       0MiB /  15360MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+
  1. Request a specific GPU type

First, check what GPU types are available on your cluster using sinfo. Then submit a job requesting a specific GPU type (e.g., A100 or V100).

Hint / Solution
# Check available GPU types
sinfo -p gpu -o "%N %G"

# Request a specific type (adjust the type to match your cluster)
sbatch --partition=gpu --gres=gpu:a100:1 --cpus-per-task=4 --mem=16G \
    --time=00:10:00 --output=gpu_type_%j.out --job-name=gpu_type \
    --wrap='nvidia-smi --query-gpu=name --format=csv,noheader'
Expected output: Validated 2026-04-15 on slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ sinfo -p gpu -o '%N %G'
NODELIST GRES
gpu-dy-t4-1 gpu:t4:1
  1. Check CUDA_VISIBLE_DEVICES with multiple GPUs

Submit a job requesting 2 GPUs. Inside the job, print $CUDA_VISIBLE_DEVICES and use nvidia-smi to list the allocated GPU details (name, memory, index).

Hint / Solution
sbatch --partition=gpu --gres=gpu:2 --cpus-per-task=8 --mem=32G \
    --time=00:10:00 --output=multi_gpu_%j.out --job-name=multi_gpu \
    --wrap='echo "CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES"; nvidia-smi --query-gpu=index,name,memory.total --format=csv'
Expected output: Validated 2026-04-15 on slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ sbatch --partition=gpu --gres=gpu:1 --cpus-per-task=4 --mem=8G --time=00:10:00 --job-name=val_gpu3 --output=gpu3_%j.out --wrap='echo CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES; nvidia-smi --query-gpu=index,name,memory.total --format=csv'
Submitted batch job 42

$ cat gpu3_42.out
CUDA_VISIBLE_DEVICES=0
index, name, memory.total [MiB]
0, Tesla T4, 15360 MiB
  1. Use sacct to see GPU allocation details

After a GPU job completes, use sacct with the AllocTRES format field to see exactly what trackable resources (including GPUs) were allocated. Compare this with the CPU and memory allocation.

Hint / Solution
# After your GPU job completes:
sacct -j <jobid> --format=JobID,JobName,AllocTRES%60,Elapsed,State

# The AllocTRES column will show something like:
# billing=12,cpu=4,gres/gpu=1,mem=16G,node=1
Expected output: Validated 2026-04-15 on slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ sacct -j 42 --format=JobID,JobName,AllocTRES%60,Elapsed,State
JobID           JobName                                                    AllocTRES    Elapsed      State 
------------ ---------- ------------------------------------------------------------ ---------- ---------- 
42            val_gpu4                                billing=4,cpu=4,mem=8G,node=1   00:00:11  COMPLETED 
42.batch         batch                                          cpu=4,mem=8G,node=1   00:00:11  COMPLETED 

References