2016-07-25 14:53:15 +05:30
## Table of Contents
<!-- toc -->
- [Installing pre-built packages ](#installing-pre-built-packages )
* [Prerequisites ](#prerequisites )
2020-11-02 15:54:42 -05:00
* [AMD Platform ](#amd-platform )
* [NVIDIA Platform ](#nvidia-platform )
2016-05-02 10:19:46 -05:00
- [Building HIP from source ](#building-hip-from-source )
2020-11-02 15:54:42 -05:00
* [Build ROCclr ](#build-rocclr )
* [Build HIP ](#build-hip )
* [Default paths and environment variables ](#default-paths-and-environment-variables )
- [Verify your installation ](#verify-your-installation )
2016-07-25 14:53:15 +05:30
<!-- tocstop -->
2016-05-02 10:19:46 -05:00
# Installing pre-built packages
HIP can be easily installed using pre-built binary packages using the package manager for your platform.
## Prerequisites
2020-11-02 15:54:42 -05:00
HIP code can be developed either on AMD ROCm platform using HIP-Clang compiler, or a CUDA platform with nvcc installed.
2016-05-02 10:19:46 -05:00
2020-11-02 15:54:42 -05:00
## AMD Platform
2016-05-02 10:19:46 -05:00
2019-01-04 11:04:47 +05:30
```
2020-11-02 15:54:42 -05:00
sudo apt install mesa-common-dev
sudo apt install clang
sudo apt install comgr
sudo apt-get -y install rocm-dkms
2019-01-04 11:04:47 +05:30
```
2020-11-02 15:54:42 -05:00
Public link for Rocm installation
https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html
2016-05-02 10:19:46 -05:00
2020-11-02 15:54:42 -05:00
HIP-Clang is the compiler for compiling HIP programs on AMD platform.
2020-01-06 02:02:47 -05:00
2020-11-02 15:54:42 -05:00
HIP-Clang can be built manually:
2020-01-06 02:02:47 -05:00
```
2021-08-26 12:19:54 -04:00
git clone -b amd-stg-open https://github.com/RadeonOpenCompute/llvm-project.git
2020-11-02 15:54:42 -05:00
cd llvm-project
2020-01-06 02:02:47 -05:00
mkdir -p build && cd build
2020-11-02 15:54:42 -05:00
cmake -DCMAKE_INSTALL_PREFIX=/opt/rocm/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=1 -DLLVM_TARGETS_TO_BUILD="AMDGPU;X86" -DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" ../llvm
2020-01-06 02:02:47 -05:00
make -j
sudo make install
```
2020-11-02 15:54:42 -05:00
Rocm device library can be manually built as following,
2020-01-06 02:02:47 -05:00
```
export PATH=/opt/rocm/llvm/bin:$PATH
2021-08-26 12:19:54 -04:00
git clone -b amd-stg-open https://github.com/RadeonOpenCompute/ROCm-Device-Libs.git
2020-01-06 02:02:47 -05:00
cd ROCm-Device-Libs
mkdir -p build && cd build
2020-11-02 15:54:42 -05:00
CC=clang CXX=clang++ cmake -DLLVM_DIR=/opt/rocm/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_WERROR=1 -DLLVM_ENABLE_ASSERTIONS=1 -DCMAKE_INSTALL_PREFIX=/opt/rocm ..
2020-01-06 02:02:47 -05:00
make -j
sudo make install
```
2020-11-02 15:54:42 -05:00
## NVIDIA Platform
2018-05-31 23:55:42 -04:00
2020-11-02 15:54:42 -05:00
HIP-nvcc is the compiler for HIP program compilation on NVIDIA platform.
2016-05-02 10:19:46 -05:00
2019-01-04 11:04:47 +05:30
* Add the ROCm package server to your system as per the OS-specific guide available [here ](https://rocm.github.io/ROCmInstall.html#installing-from-amd-rocm-repositories ).
2021-07-29 00:02:45 -07:00
* Install the "hip-runtime-nvidia" and "hip-devel" package. This will install CUDA SDK and the HIP porting layer.
2016-05-02 10:19:46 -05:00
```
2021-07-29 00:02:45 -07:00
apt-get install hip-runtime-nvidia hip-devel
2016-05-02 10:19:46 -05:00
```
* Default paths and environment variables:
2020-11-02 15:54:42 -05:00
* By default HIP looks for CUDA SDK in /usr/local/cuda (can be overriden by setting CUDA_PATH env variable).
2016-05-02 10:19:46 -05:00
* By default HIP is installed into /opt/rocm/hip (can be overridden by setting HIP_PATH environment variable).
* Optionally, consider adding /opt/rocm/bin to your path to make it easier to use the tools.
2020-11-02 15:54:42 -05:00
# Building HIP from source
2016-05-02 10:19:46 -05:00
2021-07-20 11:00:53 -04:00
## Get HIP source code
2016-05-02 10:19:46 -05:00
2021-07-20 11:00:53 -04:00
```
2021-08-26 12:19:54 -04:00
git clone -b develop https://github.com/ROCm-Developer-Tools/hipamd.git
git clone -b develop https://github.com/ROCm-Developer-Tools/hip.git
git clone -b develop https://github.com/ROCm-Developer-Tools/ROCclr.git
git clone -b develop https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime.git
2021-07-20 11:00:53 -04:00
```
## Set the environment variables
2016-05-02 10:19:46 -05:00
2020-11-02 15:54:42 -05:00
```
2021-07-20 11:00:53 -04:00
export HIPAMD_DIR="$(readlink -f hipamd)"
export HIP_DIR="$(readlink -f hip)"
2020-11-02 15:54:42 -05:00
export ROCclr_DIR="$(readlink -f ROCclr)"
export OPENCL_DIR="$(readlink -f ROCm-OpenCL-Runtime)"
```
2019-03-30 08:24:49 -04:00
2021-07-20 11:00:53 -04:00
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
2021-07-22 19:18:24 +00:00
HIPAMD repository provides implementation specifically for AMD platform.
2021-07-20 11:00:53 -04:00
See https://github.com/ROCm-Developer-Tools/hipamd
2020-11-02 15:54:42 -05:00
## Build HIP
2019-03-30 08:24:49 -04:00
2016-05-02 10:19:46 -05:00
```
2021-07-20 11:00:53 -04:00
cd "$HIPAMD_DIR"
2020-11-02 15:54:42 -05:00
mkdir -p build; cd build
2021-07-20 11:00:53 -04:00
cmake -DHIP_COMMON_DIR=$HIP_DIR -DAMD_OPENCL_PATH=$OPENCL_DIR -DROCCLR_PATH=$ROCCLR_DIR -DCMAKE_PREFIX_PATH="/opt/rocm/" -DCMAKE_INSTALL_PREFIX=$PWD/install ..
make -j$(nproc)
2020-11-02 15:54:42 -05:00
sudo make install
2016-05-02 10:19:46 -05:00
```
2021-07-20 11:00:53 -04:00
Note: If you don't specify CMAKE_INSTALL_PREFIX, hip runtime will be installed to "/opt/rocm/hip".
By default, release version of AMDHIP is built.
2020-11-02 15:54:42 -05:00
## Default paths and environment variables
2016-05-02 10:19:46 -05:00
2020-11-02 15:54:42 -05:00
* By default HIP looks for HSA in /opt/rocm/hsa (can be overridden by setting HSA_PATH environment variable).
* By default HIP is installed into /opt/rocm/hip (can be overridden by setting HIP_PATH environment variable).
* By default HIP looks for clang in /opt/rocm/llvm/bin (can be overridden by setting HIP_CLANG_PATH environment variable)
* By default HIP looks for device library in /opt/rocm/lib (can be overridden by setting DEVICE_LIB_PATH environment variable).
* Optionally, consider adding /opt/rocm/bin to your PATH to make it easier to use the tools.
* Optionally, set HIPCC_VERBOSE=7 to output the command line for compilation.
2016-05-02 10:19:46 -05:00
2020-11-02 15:54:42 -05:00
After installation, make sure HIP_PATH is pointed to /where/to/install/hip
# Verify your installation
Run hipconfig (instructions below assume default installation path) :
2016-05-02 10:19:46 -05:00
```shell
2020-11-02 15:54:42 -05:00
/opt/rocm/bin/hipconfig --full
2016-05-02 10:19:46 -05:00
```
2021-04-01 18:40:43 -04:00
Compile and run the [square sample ](https://github.com/ROCm-Developer-Tools/HIP/tree/main/samples/0_Intro/square ).
2016-05-02 10:19:46 -05:00