# 2. Installation

## 2.1. Introduction

This chapter describes how to obtain hipRAND. There are two main methods: the easiest way is to install the prebuilt packages from the ROCm repositories. Alternatively, this chapter also describes how to build hipRAND from source.

## 2.2. Prebuilt Packages

Installing the prebuilt hipRAND packages requires a ROCm-enabled platform. See the ROCm documentation for more information. After installing ROCm or enabling the ROCm repositories, hipRAND can be obtained using the system package manager.

For Ubuntu and Debian:

    sudo apt-get install hiprand

For CentOS:

    sudo yum install hiprand

For SLES:

    sudo dnf install hiprand

This will install hipRAND into the `/opt/rocm` directory.

## 2.3. Building hipRAND From Source

### 2.3.1. Requirements

To build hipRAND, CMake version 3.10 or later is required.

Additionally, to build hipRAND for the ROCm platform, the following software are required:

- AMD ROCm platform (version 5.0.0 or later).

- rocRAND

To build hipRAND for the CUDA platform instead, the following software is required:

- The CUDA Toolkit

- cuRAND (included in the CUDA Toolkit)

### 2.3.2. Obtaining Sources

The hipRAND sources are available from the hipRAND GitHub Repository. Use the branch that matches the system-installed version of ROCm. For example on a system that has ROCm 5.4 installed, use the following command to obtain hipRAND sources:

    git checkout -b release/rocm-rel-5.4 https://github.com/ROCmSoftwarePlatform/hipRAND.git

### 2.3.3. Building the Library

After obtaining the sources and dependencies, hipRAND can be built for the ROCm platform using the installation script:

    cd hipRAND
    ./install --install

This automatically builds all required dependencies, excluding HIP and Git, and installs the project to `/opt/rocm` if everything went well. See `./install --help` for further information.

### 2.3.4. Building with CMake

For a more elaborate installation process, hipRAND can be built manually using CMake. This enables certain configuration options that are not exposed to the `./install` script. In general, hipRAND can be built using CMake by configuring as follows:

    cd hipRAND; mkdir build; cd build
    # Configure the project
    CXX=<compiler> cmake [options] ..
    # Build
    make -j$(nproc)
    # Optionally, run the tests
    ctest --output-on-failure
    # Install
    [sudo] make install

Where `<compiler>>` should be set to `hipcc` on a ROCm platform, or to a regular C++ compiler such as `g++` on a CUDA platform.

- `BUILD_WITH_LIB` controls whether to build hipRAND with the rocRAND or cuRAND backend. If set to `CUDA`, hipRAND will be built using the cuRAND backend. Otherwise, the rocRAND backend will be used.

- `BUILD_FORTRAN_WRAPPER` controls whether to build the Fortran wrapper. Defaults to `OFF`.

- `BUILD_TEST` controls whether to build the hipRAND tests. Defaults to `OFF`.

- `BUILD_BENCHMARK` controls whether to build the hipRAND benchmarks. Defaults to `OFF`.

- `BUILD_ADDRESS_SANITIZER` controls whether to build with address sanitization enabled. Defaults to `OFF`.

## 2.4. Building the Python API Wrapper

### 2.4.1. Requirements

The hipRAND Python API Wrapper requires the following dependencies:

- hipRAND

- Python 3.5

- NumPy (will be installed automatically as a dependency if necessary)

Note: If hipRAND is built from sources but not installed or installed in non-standard directory, set the `ROCRAND_PATH` or `HIPRAND_PATH` environment variable to the path containing `libhiprand.so`. For example:

    export HIPRAND_PATH=~/hipRAND/build/library/

### 2.4.2. Installing

The Python hipRAND module can be installed using pip:

    cd hipRAND/python/hiprand
    pip install .

The tests can be executed as follows:

    cd hipRAND/python/hiprand
    python tests/hiprand_test.py