2023-04-19 05:49:28 +02:00
# Building HIP from Source
## Prerequisites
2022-03-11 16:59:44 +05:30
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.
2023-04-19 05:49:28 +02:00
### AMD platform
2023-09-22 14:37:33 -04:00
Install ROCm packages or pre-built binary packages using the package manager. Refer to the ROCm Installation Guide at https://rocm.docs.amd.com for more information on installing ROCm.
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2022-03-11 16:59:44 +05:30
sudo apt install mesa-common-dev
sudo apt install clang
sudo apt install comgr
sudo apt-get -y install rocm-dkms
2023-07-29 00:00:21 +05:30
sudo apt-get install -y libelf-dev
2022-03-11 16:59:44 +05:30
```
2023-04-19 05:49:28 +02:00
### NVIDIA platform
2022-03-11 16:59:44 +05:30
Install Nvidia driver and pre-build packages (see HIP Installation Guide at https://docs.amd.com/ for the release)
2023-04-19 05:49:28 +02:00
### Branch of repository
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
Before get HIP source code, set the expected branch of repository at the variable `ROCM_BRANCH` .
2023-09-22 14:37:33 -04:00
For example, for ROCm6.0 release branch, set
2023-04-19 05:49:28 +02:00
``` shell
2023-09-22 14:37:33 -04:00
export ROCM_BRANCH = rocm-6.0.x
2022-03-11 16:59:44 +05:30
```
2023-09-22 14:37:33 -04:00
ROCm5.7 release branch, set
2023-04-19 05:49:28 +02:00
``` shell
2023-09-22 14:37:33 -04:00
export ROCM_BRANCH = rocm-5.7.x
2022-03-11 16:59:44 +05:30
```
Similiar format for future branches.
2023-04-19 05:49:28 +02:00
`ROCM_PATH` is path where ROCM is installed. BY default `ROCM_PATH` is at `/opt/rocm` .
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
## Build HIP on AMD platform
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
### Get HIP source code
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2023-07-29 00:00:21 +05:30
git clone -b " $ROCM_BRANCH " https://github.com/ROCm-Developer-Tools/clr.git
2023-01-26 21:50:58 +05:30
git clone -b " $ROCM_BRANCH " https://github.com/ROCm-Developer-Tools/hip.git
2023-07-29 00:00:21 +05:30
git clone -b " $ROCM_BRANCH " https://github.com/ROCm-Developer-Tools/HIPCC.git
2022-03-11 16:59:44 +05:30
```
2023-04-19 05:49:28 +02:00
### Set the environment variables
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2023-07-29 00:00:21 +05:30
export CLR_DIR = " $( readlink -f clr) "
2022-03-11 16:59:44 +05:30
export HIP_DIR = " $( readlink -f hip) "
2023-07-29 00:00:21 +05:30
export HIPCC_DIR = " $( readlink -f hipcc) "
2022-03-11 16:59:44 +05:30
```
2023-07-29 00:00:21 +05:30
Note, starting from ROCM 5.6 release, clr is a new repository including the previous ROCclr, HIPAMD and OpenCl repositories.
ROCclr is defined on AMD platform that HIP uses Radeon Open Compute Common Language Runtime (ROCclr), which is a virtual device interface that HIP runtimes interact with different backends.
HIPAMD provides implementation specifically for AMD platform.
OpenCL provides headers that ROCclr runtime currently depends on.
2022-03-11 16:59:44 +05:30
2023-07-29 00:00:21 +05:30
### Build the HIPCC runtime
``` shell
cd " $HIPCC_DIR "
mkdir -p build; cd build
cmake ..
make -j4
```
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
### Build HIP
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2023-07-29 00:00:21 +05:30
cd " $CLR_DIR "
2022-03-11 16:59:44 +05:30
mkdir -p build; cd build
2023-07-29 00:00:21 +05:30
cmake -DHIP_COMMON_DIR= $HIP_DIR -DHIP_PLATFORM= amd -DCMAKE_PREFIX_PATH= "/opt/rocm/" -DCMAKE_INSTALL_PREFIX= $PWD /install -DHIPCC_BIN_DIR= $HIPCC_DIR /build -DHIP_CATCH_TEST= 0 -DCLR_BUILD_HIP= ON -DCLR_BUILD_OCL= OFF ..
2022-03-11 16:59:44 +05:30
make -j$( nproc)
sudo make install
```
2023-07-29 00:00:21 +05:30
Note, if `CMAKE_INSTALL_PREFIX` is not specified, hip runtime will be installed to `<ROCM_PATH>/hip` .
By default, release version of HIP is built.
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
### Default paths and environment variables
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
* By default HIP looks for HSA in `<ROCM_PATH>/hsa` (can be overridden by setting `HSA_PATH` environment variable).
2023-10-05 16:26:31 -04:00
* By default HIP is installed into `<ROCM_PATH>/hip` .
2023-04-19 05:49:28 +02:00
* By default HIP looks for clang in `<ROCM_PATH>/llvm/bin` (can be overridden by setting `HIP_CLANG_PATH` environment variable)
* By default HIP looks for device library in `<ROCM_PATH>/lib` (can be overridden by setting `DEVICE_LIB_PATH` environment variable).
* Optionally, consider adding `<ROCM_PATH>/bin` to your `PATH` to make it easier to use the tools.
* Optionally, set `HIPCC_VERBOSE=7` to output the command line for compilation.
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
### Generating profiling header after adding/changing a HIP API
2023-02-24 15:10:09 +05:30
2023-10-05 16:26:31 -04:00
When you add or change a HIP API, you must generate a new `hip_prof_str.h` header. ROCm tools like ROCProfiler and ROCTracer use this header to track HIP APIs.
2023-02-24 15:10:09 +05:30
To generate the header after your change, use the tool `hip_prof_gen.py` present in `hipamd/src` .
Usage:
`hip_prof_gen.py [-v] <input HIP API .h file> <patched srcs path> <previous output> [<output>]`
Flags:
* -v - verbose messages
* -r - process source directory recursively
* -t - API types matching check
* --priv - private API check
* -e - on error exit mode
* -p - HIP_INIT_API macro patching mode
2023-04-19 05:49:28 +02:00
Example Usage:
``` shell
hip_prof_gen.py -v -p -t --priv <hip>/include/hip/hip_runtime_api.h \
<hipamd>/src <hipamd>/include/hip/amd_detail/hip_prof_str.h \
<hipamd>/include/hip/amd_detail/hip_prof_str.h.new
```
2023-02-24 15:10:09 +05:30
2023-04-19 05:49:28 +02:00
### Build HIP tests
2022-06-15 06:19:09 +05:30
2023-01-26 21:50:58 +05:30
HIP catch tests, with new architectured Catch2, are official seperated from HIP project, exist in HIP tests repository, can be built via the following instructions.
2023-09-13 18:02:31 +01:00
#### Get HIP tests source code
2023-01-26 21:50:58 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2023-01-26 21:50:58 +05:30
git clone -b " $ROCM_BRANCH " https://github.com/ROCm-Developer-Tools/hip-tests.git
```
2023-09-13 18:02:31 +01:00
#### Build HIP tests from source
2022-06-15 06:19:09 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2023-07-29 00:00:21 +05:30
export HIPTESTS_DIR = " $( readlink -f hip-tests) "
cd " $HIPTESTS_DIR "
2022-06-15 06:19:09 +05:30
mkdir -p build; cd build
2023-10-05 16:26:31 -04:00
cmake ../catch -DHIP_PLATFORM= amd -DHIP_PATH= $CLR_DIR /build/install # or any path where HIP is installed, for example, /opt/rocm.
make -j$( nproc) build_tests # build tests
cd build/catch_tests && ctest # to run all tests.
2022-06-15 06:19:09 +05:30
```
2023-07-29 00:00:21 +05:30
HIP catch tests are built under the folder $HIPTESTS_DIR/build.
2023-10-05 16:26:31 -04:00
Note that when using ctest, you can use different ctest options, for example, to run all tests with the keyword hipMemset,
```
ctest -R hipMemset
```
Use the below option will print test failures for failed tests,
```
ctest --output-on-failure
```
For more information, refer to https://cmake.org/cmake/help/v3.5/manual/ctest.1.html.
2022-06-15 06:19:09 +05:30
2023-01-26 21:50:58 +05:30
To run any single catch test, the following is an example,
2022-06-15 06:19:09 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2023-07-29 00:00:21 +05:30
cd $HIPTESTS_DIR /build/catch_tests/unit/texture
2022-06-15 06:19:09 +05:30
./TextureTest
```
2023-09-13 18:02:31 +01:00
#### Build HIP Catch2 standalone test
2022-06-15 06:19:09 +05:30
HIP Catch2 supports build a standalone test, for example,
2023-04-19 05:49:28 +02:00
``` shell
2023-07-29 00:00:21 +05:30
cd " $HIPTESTS_DIR "
hipcc $HIPTESTS_DIR /catch/unit/memory/hipPointerGetAttributes.cc -I ./catch/include ./catch/hipTestMain/standalone_main.cc -I ./catch/external/Catch2 -o hipPointerGetAttributes
2022-06-15 06:19:09 +05:30
./hipPointerGetAttributes
...
All tests passed
```
2023-04-19 05:49:28 +02:00
## Build HIP on NVIDIA platform
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
### Get HIP source code
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2023-01-26 21:50:58 +05:30
git clone -b " $ROCM_BRANCH " https://github.com/ROCm-Developer-Tools/hip.git
2023-07-29 00:00:21 +05:30
git clone -b " $ROCM_BRANCH " https://github.com/ROCm-Developer-Tools/clr.git
git clone -b " $ROCM_BRANCH " https://github.com/ROCm-Developer-Tools/HIPCC.git
2022-03-11 16:59:44 +05:30
```
2023-04-19 05:49:28 +02:00
### Set the environment variables
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2022-03-11 16:59:44 +05:30
export HIP_DIR = " $( readlink -f hip) "
2023-07-29 00:00:21 +05:30
export CLR_DIR = " $( readlink -f hipamd) "
export HIPCC_DIR = " $( readlink -f hipcc) "
```
### Build the HIPCC runtime
``` shell
cd " $HIPCC_DIR "
mkdir -p build; cd build
cmake ..
make -j4
2022-03-11 16:59:44 +05:30
```
2023-04-19 05:49:28 +02:00
### Build HIP
2022-03-11 16:59:44 +05:30
2023-04-19 05:49:28 +02:00
``` shell
2023-07-29 00:00:21 +05:30
cd " $CLR_DIR "
2022-03-11 16:59:44 +05:30
mkdir -p build; cd build
2023-07-29 00:00:21 +05:30
cmake -DHIP_COMMON_DIR= $HIP_DIR -DHIP_PLATFORM= nvidia -DCMAKE_INSTALL_PREFIX= $PWD /install -DHIPCC_BIN_DIR= $HIPCC_DIR /build -DHIP_CATCH_TEST= 0 -DCLR_BUILD_HIP= ON -DCLR_BUILD_OCL= OFF ..
2022-03-11 16:59:44 +05:30
make -j$( nproc)
sudo make install
```
2023-04-19 05:49:28 +02:00
### Build HIP tests
Build HIP tests commands on NVIDIA platform are basically the same as AMD, except set `-DHIP_PLATFORM=nvidia` .
2022-06-15 06:19:09 +05:30
2023-04-19 05:49:28 +02:00
## Run HIP
2022-03-11 16:59:44 +05:30
2023-07-29 00:00:21 +05:30
Compile and run the [square sample ](https://github.com/ROCm-Developer-Tools/hip-tests/tree/rocm-5.5.x/samples/0_Intro/square ).
2022-03-11 16:59:44 +05:30