Build rocThrust from source#

To build rocThrust as part of the ROCm Core SDK, see TheRock build instructions. TheRock is the recommended way to build ROCm components from source.

Alternatively, you can build rocThrust standalone using the following instructions.

Prerequisites#

On Linux, ROCm must be installed before rocThrust is installed.

rocThrust has the following prerequisites on Linux and Microsoft Windows:

rocPRIM can be automatically downloaded and installed when rocThrust is built.

rocThrust has these additional prerequisites on Windows:

Get the rocThrust source code#

The rocThrust source code is available from the ROCm libraries GitHub repository. Use sparse checkout when cloning the rocThrust project:

git clone --no-checkout --filter=blob:none https://github.com/ROCm/rocm-libraries.git
cd rocm-libraries
git sparse-checkout init --cone
git sparse-checkout set projects/rocthrust

Then use git checkout to check out the branch you need.

The develop branch is intended for users who want to preview new features or contribute to the rocThrust code base.

If you don’t intend to contribute to the rocThrust code base and won’t be previewing features, use a branch that matches the version of ROCm installed on your system.

For build instructions, see ./build.

Build on Linux#

You can use the install script to build and install rocThrust on Linux. You can also use CMake if you want more build and installation options.

The install script is located in the rocthrust root directory.

To build and install rocThrust, run:

./install --install

This command also downloads and installs rocPRIM.

To build rocThrust and generate tar, zip, and debian packages, run:

./install --package

To see a complete list of options, run:

./install --help

Build on Windows#

You can use rmake.py to build and install rocThrust on Windows. You can also use CMake if you want more build and installation options.

rmake.py is located in the rocthrust root directory.

To build and install rocThrust, run:

python rmake.py -i

This command also downloads rocPRIM and installs it in C:\hipSDK.

The -c option builds all clients, including the unit tests:

python rmake.py -c

CMake build options can be passed to the rmake.py script using the --cmake-darg option:

python rmake.py -ci --cmake-darg THRUST_HOST_SYSTEM=OMP --cmake-darg THRUST_DEVICE_SYSTEM=OMP

To see a complete list of rmake.py options, run:

python rmake.py --help

Build with CMake#

You can build and install rocThrust with CMake on either Windows or Linux.

Set CXX to hipcc and set CMAKE_CXX_COMPILER to hipcc’s absolute path. For example:

CXX=hipcc
CMAKE_CXX_COMPILER=/usr/bin/hipcc

Create the build directory under the rocthrust root directory, then change directory to the build directory:

mkdir build
cd build

Generate the rocThrust makefile using the cmake command:

cmake ../. [-D<OPTION1=VALUE1> [-D<OPTION2=VALUE2>] ...]

The build options are:

  • DISABLE_WERROR: Set this to OFF to pass -Werror to the compiler. Default is ON.

  • BUILD_TEST: Set this to ON to enable rocThrust tests. Default is OFF.

  • BUILD_HIPSTDPAR_TEST: Set this to ON to enable HIPSTDPAR tests. Default is OFF.

  • BUILD_BENCHMARK: Set this to ON to build rocThrust benchmarks. Default is OFF.

  • BUILD_EXAMPLE: Set this to ON to build the rocThrust examples. Default is OFF.

  • BUILD_OFFLOAD_COMPRESS: Set this to OFF to prevent the --offload-compress switch from being passed to the compiler and compressing the binary. On by default.

  • USE_SYSTEM_LIB: Set this to ON to use the installed ROCm libraries when building the tests. For this option to take effect, BUILD_TEST must be set to ON. Default is OFF.

  • RNG_SEED_COUNT: Set this to the non-repeatable random dataset count. Default is 0.

  • PRNG_SEEDS: Set this to the RNG seeds. The seeds must be passed as a semicolon-delimited array of 32-bit unsigned integers. To avoid command line parsing errors, enclose the entire option in quotation marks. For example, cmake "-DPRNG_SEEDS=1;2;3;4". -DPRNG_SEEDS=1 is used by default.

  • BUILD_ADDRESS_SANITIZER: Set this to ON to build with the Clang address sanitizer enabled. Default is OFF.

  • EXTERNAL_DEPS_FORCE_DOWNLOAD: Set this to ON to download the non-ROCm dependencies such as Google Test even if they’re already installed. Default is OFF.

  • USE_HIPCXX: Set this to ON to build with CMake HIP language support. Setting this to ON eliminates the need to use CXX=hipcc. Default is OFF.

  • ROCPRIM_FETCH_METHOD and ROCRAND_FETCH_METHOD: Set these to the method to use to download the rocPRIM and rocRAND components, respectively. Can be set to PACKAGE, DOWNLOAD, or MONOREPO. Set to MONOREPO if the component isn’t already installed and you’re building rocThrust from within a clone of the rocm-libraries repository that includes the component. Set to DOWNLOAD if the component isn’t installed and you aren’t in a clone of the rocm-libraries repository that includes the component. DOWNLOAD will clone the repository using sparse checkout so that only the necessary files are downloaded. Set to PACKAGE if the component is already installed. If the component isn’t installed, it’ll be downloaded from the repository in the same way as using the DOWNLOAD option. The default method is PACKAGE.

  • LINK_HIP_DEVICE_LIBS: Set to OFF to prevent linking against device dependencies, including rocPRIM, and the build can only be used for host-side computation. Default is ON.

  • THRUST_DEVICE_SYSTEM: Sets the device backend that will be used. If unspecified, this option will be inferred from the name of the device compiler. Valid values include HIP (for AMD GPU acceleration), CPP (C++, for sequential host-side compute), TBB (Thread Building Blocks, for parallel host-side compute), and OMP (OpenMP, for parallel host-side compute). Note that when this is set to a value other than HIP, you must set LINK_HIP_DEVICE_LIBS=OFF.

  • THRUST_HOST_SYSTEM: Sets the host backend that will be used. If unspecified, this option defaults to CPP. Valid values include CPP (C++), OMP (OpenMP), and TBB (Thread Building Blocks).

Note

If you’re using a version of git earlier than 2.25, -DROCPRIM_FETCH_METHOD=DOWNLOAD and -DROCRAND_FETCH_METHOD=DOWNLOAD will download the entire rocm-libraries repository.

Build rocThrust using the generated make file:

make -j4

After you’ve built rocThrust, you can optionally generate tar, zip, and deb packages:

make package

Finally, install rocThrust:

make install