As others have already stated, CUDA can only be directly run on NVIDIA GPUs. As also stated, existing CUDA code could be hipify
-ed, which essentially runs a sed
script that changes known CUDA API calls to HIP API calls. Then the HIP code can be compiled and run on either NVIDIA (CUDA backend) or AMD (ROCm backend) GPUs.
The new piece of information I'd like to contribute is that if someone doesn't want to hipify
their existing CUDA code (i.e., change all CUDA API calls to HIP API calls), there is another option that can be used; simply add (and include) a header file that redefines the CUDA calls as HIP calls. For example, a simple vector addition code might use the following header file:
#include "hip/hip_runtime.h"
#define cudaMalloc hipMalloc
#define cudaMemcpy hipMemcpy
#define cudaMemcpyHostToDevice hipMemcpyHostToDevice
#define cudaMemcpyDeviceToHost hipMemcpyDeviceToHost
#define cudaFree hipFree
...where the main program would include the header file:
#include "/path/to/header/file"
int main(){
...
}
Compilation would, of course, require using nvcc
(as normal) on an NVIDIA GPU and hipcc
on an AMD GPU.
Regarding where to get started with GPU computing (in general), I would recommend starting with CUDA since it has the most documentation, example codes, and user-experiences available via a Google search. The good news is, once you know how to program in CUDA, you essentially already know how to program in HIP : )