...
$ hipify-perl hello.cu > hello.hip.cucpp
When using a CUDA backend for compiling, note how the .cu extension has to be kept, to allow for the subsequent compilation with a CUDA backend. On the other hand, when using a ROCm backend for compiling, HIP source files typically have the .cpp extension.
...
HIP code can be compiled by using the hipcc
compiler provided by AMD ROCm:
$ hipcc --offload-arch=<architecture> hello.hip.cu cpp -o helloHIP
The code can be executed in an interactive SLURM session or within a batch job. An explicit request to use one or more GPUs is required. Terminal 1 shows an interactive session on GarrawarlaSetonix:
Column |
---|
|
Code Block |
---|
language | bash |
---|
theme | DJango |
---|
title | Terminal 1. Run HIP code |
---|
| $ salloc -N 1 -n 1 --gres=gpu:1 -p gpuq gpu-dev -A <project>-gpu -t 0:01:00
$ module load hip/<version>rocm craype-accel-amd-gfx90a
$ hipify-perl hello.cu > hello.hip.cpp
$ hipcc --offload-arch=gfx90a hello.hip.cpp -o helloHIP
$ export OMP_NUM_THREADS=1
$ srun -N 1 -n 1 -c 8 --gres=gpu:1 --gpus-per-task=1 --gpu-exportbind=allclosest ./helloHIP
Hello from GPU thread 0 in block 0
Hello from GPU thread 1 in block 0
Hello from GPU thread 2 in block 0
Hello from GPU thread 3 in block 0
Hello from GPU thread 4 in block 0
Hello from GPU thread 0 in block 1
Hello from GPU thread 1 in block 1
Hello from GPU thread 2 in block 1
Hello from GPU thread 3 in block 1
Hello from GPU thread 4 in block 1
Hello from GPU thread 0 in block 3
Hello from GPU thread 1 in block 3
Hello from GPU thread 2 in block 3
Hello from GPU thread 3 in block 3
Hello from GPU thread 4 in block 3
Hello from GPU thread 0 in block 2
Hello from GPU thread 1 in block 2
Hello from GPU thread 2 in block 2
Hello from GPU thread 3 in block 2
Hello from GPU thread 4 in block 2
|
|
...