HIP: Heterogenous-computing Interface for Portability
Table of Contents

Prerequisites

HIP code can be developed either on AMD ROCm platform using HIP-Clang compiler, or a CUDA platform with nvcc installed. Before build and run HIP, make sure drivers and pre-build packages are installed properly on the platform.

AMD platform

Install ROCm packages (see ROCm Installation Guide on AMD public documentation site (https://docs.amd.com/)) or install pre-built binary packages using the package manager,

1 sudo apt install mesa-common-dev
2 sudo apt install clang
3 sudo apt install comgr
4 sudo apt-get -y install rocm-dkms

NVIDIA platform

Install Nvidia driver and pre-build packages (see HIP Installation Guide at https://docs.amd.com/ for the release)

Branch of repository

Before get HIP source code, set the expected branch of repository at the variable HIP_BRANCH. For example, for ROCm5.0 release branch, set

1 export HIP_BRANCH=rocm-5.0.x

ROCm5.1 release branch, set

1 export HIP_BRANCH=rocm-5.1.x

Similiar format for future branches.

ROCM_PATH is path where ROCM is installed. BY default ROCM_PATH is at /opt/rocm.

Build HIP on AMD platform

Get HIP source code

1 git clone -b $HIP_BRANCH https://github.com/ROCm-Developer-Tools/hipamd.git
2 git clone -b $HIP_BRANCH https://github.com/ROCm-Developer-Tools/hip.git
3 git clone -b $HIP_BRANCH https://github.com/ROCm-Developer-Tools/ROCclr.git

Set the environment variables

1 export HIPAMD_DIR="$(readlink -f hipamd)"
2 export HIP_DIR="$(readlink -f hip)"

ROCclr is defined on AMD platform that HIP use Radeon Open Compute Common Language Runtime (ROCclr), which is a virtual device interface that HIP runtimes interact with different backends. See https://github.com/ROCm-Developer-Tools/ROCclr

HIPAMD repository provides implementation specifically for AMD platform. See https://github.com/ROCm-Developer-Tools/hipamd

Build HIP

1 cd "$HIPAMD_DIR"
2 mkdir -p build; cd build
3 cmake -DHIP_COMMON_DIR=$HIP_DIR -DCMAKE_PREFIX_PATH="<ROCM_PATH>/" -DCMAKE_INSTALL_PREFIX=$PWD/install ..
4 make -j$(nproc)
5 sudo make install

Note: If you don't specify CMAKE_INSTALL_PREFIX, hip runtime will be installed to "<ROCM_PATH>/hip". By default, release version of AMDHIP is built.

Default paths and environment variables

After make install command, make sure HIP_PATH is pointed to $PWD/install/hip.

Build HIP tests

Build HIP directed tests

Developers can build HIP directed tests right after build HIP commands,

1 sudo make install
2 make -j$(nproc) build_tests

By default, all HIP directed tests will be built and generated under the folder $HIPAMD_DIR/build/directed_tests. Take HIP directed device APIs tests, as an example, all available test applications will have executable files generated under, $HIPAMD_DIR/build/directed_tests/runtimeApi/device.

Run all HIP directed_tests, use the command,

1 ctest

Or

1 make test

Build and run a single directed test, use the follow command as an example,

1 make directed_tests.texture.hipTexObjPitch
2 cd $HIPAMD_DIR/build/directed_tests/texcture
3 ./hipTexObjPitch

Please note, the integrated HIP directed tests, will be deprecated in future release.

Build HIP catch tests

After build and install HIP commands, catch tests can be built via the following instructions,

1 cd "$HIP_DIR"
2 mkdir -p build; cd build
3 export HIP_PATH=$HIPAMD_DIR/build/install
4 cmake ../tests/catch/ -DHIP_PLATFORM=amd
5 make -j$(nproc) build_tests
6 ctest # run tests

HIP catch tests are built under the folder $HIP_DIR/build.

To run a single catch test, the following is an example,

1 cd $HIP_DIR/build/unit/texture
2 ./TextureTest

Build HIP Catch2 standalone test

HIP Catch2 supports build a standalone test, for example,

1 export PATH=$HIP_DIR/bin:$PATH
2 export HIP_PATH=$HIPAMD_DIR/build/install
3 
4 hipcc $HIP_DIR/tests/catch/unit/memory/hipPointerGetAttributes.cc -I ./tests/catch/include ./tests/catch/hipTestMain/standalone_main.cc -I ./tests/catch/external/Catch2 -g -o hipPointerGetAttributes
5 ./hipPointerGetAttributes
6 ...
7 
8 All tests passed

HIP catch tests, especially new architectured Catch2, will be official HIP tests in the repository and can be built alone as with the instructions shown above.

Build HIP on NVIDIA platform

Get HIP source code

1 git clone -b $HIP_BRANCH https://github.com/ROCm-Developer-Tools/hip.git
2 git clone -b $HIP_BRANCH https://github.com/ROCm-Developer-Tools/hipamd.git

Set the environment variables

1 export HIP_DIR="$(readlink -f hip)"
2 export HIPAMD_DIR="$(readlink -f hipamd)"

Build HIP

1 cd "$HIPAMD_DIR"
2 mkdir -p build; cd build
3 cmake -DHIP_COMMON_DIR=$HIP_DIR -DHIP_PLATFORM=nvidia -DCMAKE_INSTALL_PREFIX=$PWD/install ..
4 make -j$(nproc)
5 sudo make install

Build HIP tests

Build HIP tests commands on NVIDIA platform are basically the same as AMD, except set -DHIP_PLATFORM=nvidia.

Run HIP

Compile and run the square sample.