|
| 1 | +# Cuda example |
| 2 | + |
| 3 | +This example shows how you can compile and run a cuda program in one of the clusters GPU nodes. We expected that you already have access and know how to login. |
| 4 | + |
| 5 | +## 0. Git clone the guides repo with the examples |
| 6 | + |
| 7 | +To facilitate the demonstration we already prepared the code and scripts necessary, your job is to first run and then understand by looking into more detail. |
| 8 | + |
| 9 | +```bash |
| 10 | +$ git clone https://github.com/ieeta-pt/HPC-guides.git |
| 11 | +$ cd HPC-guides/examples/cuda |
| 12 | +``` |
| 13 | + |
| 14 | +## 1. Preprare the environment |
| 15 | + |
| 16 | +First step is the preparation of the development enviroment which in this case would be to load the gcc compiler and CUDA libraries. |
| 17 | + |
| 18 | +```bash |
| 19 | +$ module load gcc/11 |
| 20 | +$ module load cuda |
| 21 | +``` |
| 22 | + |
| 23 | +Here we load gcc 11 and not 12, since the currently installed CUDA version (11.8) advises to run with gcc 11. |
| 24 | + |
| 25 | +## 2. Compile the cuda program |
| 26 | + |
| 27 | +For compiling the cuda program just call the nvcc |
| 28 | + |
| 29 | +```bash |
| 30 | +$ nvcc vector_addition.cu -o vector_addition |
| 31 | +``` |
| 32 | + |
| 33 | +## 3. Submit the job |
| 34 | + |
| 35 | +`lunch_cuda.sh` already contains the code to lunch the slurm job while requesting a gpu. |
| 36 | + |
| 37 | +```bash |
| 38 | +$ sbatch lunch_cuda.sh |
| 39 | +``` |
| 40 | + |
| 41 | +Check your directly for the output file and cat: |
| 42 | + |
| 43 | +```bash |
| 44 | +$ ll |
| 45 | +total 808 |
| 46 | +drwxr-xr-x 2 tiagoalmeida students 4096 Jul 5 15:49 ./ |
| 47 | +drwxr-xr-x 3 tiagoalmeida students 4096 Jul 5 15:48 ../ |
| 48 | +-rw-r--r-- 1 tiagoalmeida students 248 Jul 5 15:49 Cuda-93.out |
| 49 | +-rw-r--r-- 1 tiagoalmeida students 504 Jul 5 15:48 lunch_cuda.sh |
| 50 | +-rwxr-xr-x 1 tiagoalmeida students 803936 Jul 5 15:48 vector_addition* |
| 51 | +-rw-r--r-- 1 tiagoalmeida students 2051 Jul 5 15:48 vector_addition.cu |
| 52 | +``` |
| 53 | + |
| 54 | +```bash |
| 55 | +$ cat Cuda-93.out |
| 56 | +Job Information for Job ID: 93 from tiagoalmeida |
| 57 | +------------ ------------ |
| 58 | +Account: students |
| 59 | +CPUs per Node: 2 |
| 60 | +GPU: NVIDIA RTX A2000 |
| 61 | +Partition: gpu |
| 62 | +QOS: normal |
| 63 | +Start Time: 2024-07-05 14:49:32 UTC |
| 64 | +Running On Node: dl-srv-02 |
| 65 | +------------ ------------ |
| 66 | + |
| 67 | +--------------------------- |
| 68 | +__SUCCESS__ |
| 69 | +--------------------------- |
| 70 | +N = 1048576 |
| 71 | +Threads Per Block = 256 |
| 72 | +Blocks In Grid = 4096 |
| 73 | +--------------------------- |
| 74 | +``` |
1 | 75 |
|
0 commit comments