# 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. ``` console [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 `````{tabs} ````{tab} BETZY * [More details](https://documentation.sigma2.no/hpc_machines/betzy.html) ```{literalinclude} snippets/betzy/15-gpu.txt :language: bash ``` ```` ````{tab} FOX ```{literalinclude} snippets/fox/15-gpu.txt :language: bash ``` ```` `````