GPU-jobs
Instructor note
Total: 75min (Teaching:45Min | Discussion:0min | Breaks:0min | Exercises:30Min)
Objectives
Objectives
Recruit GPUs in a jobs.
PyTorch example to demonstrate how to use GPUs
Not all software uses GPUs, just because there are available GPUs. Inorder to demonstrate the use of GPUs we need to run a small software that can utilise them. PyTorch is an example of a package that we can use to write code that would utilise GPUs, if they are available.
[MY_USER_NAME@CLUSTER_NAME ~]$ cat gpu-example.py
import torch
# Check if CUDA is available
if torch.cuda.is_available():
num_gpu = torch.cuda.device_count()
for i in range(num_gpu):
print(f'GPU {i+1}:', torch.cuda.get_device_name(i))
else:
print('No GPU available, using the CPU.')
Call the program from the job script
[MY_USER_NAME@CLUSTER_NAME ~]$ cat example-job.sh
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --time=00:10:00
#SBATCH --account=<PROJECT_NAME>
#SBATCH --mem=8G
#SBATCH --partition=accel
#SBATCH --mem=8G
#SBATCH --gpus=1
module purge
module load PyTorch/1.10.0-foss-2021a-CUDA-11.3.1
python gpu-example.py > ${SLURM_JOB_UID}.out
NA