Original author was Trey White, at the time with HPE and now with ORNL.
The HIPifly method for converting CUDA code to HIP, is straight-forward and works with minimal modifications to the source code. This example applies the HIPifly method to a simple vector addition problem offloaded to the GPU using CUDA.
All CUDA functions are defined in the src/gpu_functions.cu
file. By including the hipifly.h
file when using HIP, all the CUDA functions will be automatically replaced with the analogous HIP function during compile time.
By default, the program is compiled for NVIDIA GPUs using nvcc
. To compile for CUDA just run make
.
To compile for AMD GPUs using hipcc
run make DFLAGS=-DENABLE_HIP
. Note that the Makefile applies different GPU compilation flags when compiling for CUDA or for HIP.
The paths to the CUDA or the ROCm software stack as CUDA_PATH
or ROCM_PATH
are needed to compile.
After compiling run the program: ./vector_add