Learn about the AMD ROCm/ HIP Programming.

HIP Programming
HIP is a C++ Runtime API and Kernel Language that allows developers to create portable applications for AMD and NVIDIA GPUs from single source code.
New projects can be developed directly in the portable HIP C++ language and can run on either NVIDIA or AMD platforms. Additionally, HIP provides porting tools which make it easy to port existing CUDA codes to the HIP layer, with no loss of performance as compared to the original CUDA application. Enough chit-chat let's digg into a code, you have already visited our CUDA programming essentials course, now let's check a HIP code and you will realise how close these two dialects are.
Let's run a simple HIP code to add two vectors.
-
Input
This code adds the following two arrays a[]
and c[]
onto the GPU:
// array init
int a[]{1, 2, 3, 4, 5};
int b[]{6, 7, 8, 9, 10};
Then returns the result into the host array c[]
shows the output.
7 9 11 13 15
Note the use of the HIP kernel function hipLaunchKernelGGL()
which performs the addition operation on the GPU:
// HIP Kernel
__global__
void kernel(const int* pA, const int* pB, int* pC) {
const auto gidx = blockIdx.x * blockDim.x + threadIdx.x;
pC[gidx] = pA[gidx] + pB[gidx];
}
Do you want to know more how the HIP works? Join a free HIP course today!