Skip to content
forked from ROCm/hipCUB

Reusable software components for rocm developers

License

Notifications You must be signed in to change notification settings

raramakr/hipCUB

 
 

Repository files navigation

hipCUB

hipCUB is a thin wrapper library on top of rocPRIM or CUB. It enables developers to port a project using the CUB library to the HIP layer to run on AMD hardware. In the ROCm environment, hipCUB uses the rocPRIM library as the backend. However, on CUDA platforms it uses CUB instead.

Requirements

  • Git
  • CMake (3.16 or later)
  • For AMD GPUs:
    • AMD ROCm platform (1.8.0 or later)
      • Including HIP-clang compiler, which must be set as C++ compiler on ROCm platform.
    • rocPRIM library
      • Automatically downloaded and built by CMake script.
      • Requires CMake 3.16.9 or later.
  • For NVIDIA GPUs:
    • CUDA Toolkit
    • CUB library
      • Automatically downloaded and built by CMake script.
      • Requires CMake 3.15.0 or later.
  • Python 3.6 or higher (HIP on Windows only, only required for install scripts)
  • Visual Studio 2019 with clang support (HIP on Windows only)
  • Strawberry Perl (HIP on Windows only)

Optional:

  • GTest
    • Required only for tests. Building tests is enabled by default.
    • It will be automatically downloaded and built by CMake script.
  • Google Benchmark
    • Required only for benchmarks. Building benchmarks is off by default.
    • It will be automatically downloaded and built by cmake script.

Build And Install

git clone https://github.com/ROCmSoftwarePlatform/hipCUB.git

# Go to hipCUB directory, create and go to the build directory.
cd hipCUB; mkdir build; cd build

# Configure hipCUB, setup options for your system.
# Build options:
#   BUILD_TEST - OFF by default,
#   BUILD_BENCHMARK - OFF by default.
#   DOWNLOAD_ROCPRIM - OFF by default and at ON the rocPRIM will be downloaded to build folder,
#
# ! IMPORTANT !
# Set C++ compiler to HCC or HIP-clang. You can do it by adding 'CXX=<path-to-compiler>'
# before 'cmake' or setting cmake option 'CMAKE_CXX_COMPILER' to path to the compiler.
#
[CXX=hipcc] cmake ../. # or cmake-gui ../.

# To configure hipCUB for Nvidia platforms, 'CXX=<path-to-nvcc>', `CXX=nvcc` or omitting the flag
# entirely before 'cmake' is sufficient
[CXX=nvcc] cmake -DBUILD_TEST=ON ../. # or cmake-gui ../.
# or
cmake -DBUILD_TEST=ON ../. # or cmake-gui ../.
# or to build benchmarks
cmake -DBUILD_BENCHMARK=ON ../.

# Build
make -j4

# Optionally, run tests if they're enabled.
ctest --output-on-failure

# Package
make package

# Install
[sudo] make install

HIP on Windows

Initial support for HIP on Windows has been added. To install, use the provided rmake.py python script:

git clone https://github.com/ROCmSoftwarePlatform/hipCUB.git
cd hipCUB

# the -i option will install rocPRIM to C:\hipSDK by default
python rmake.py -i

# the -c option will build all clients including unit tests
python rmake.py -c

Using hipCUB In A Project

Recommended way of including hipCUB into a CMake project is by using its package configuration files.

# On ROCm hipCUB requires rocPRIM
find_package(rocprim REQUIRED CONFIG PATHS "/opt/rocm/rocprim")

# "/opt/rocm" - default install prefix
find_package(hipcub REQUIRED CONFIG PATHS "/opt/rocm/hipcub")

...
# On ROCm: includes hipCUB headers and roc::rocprim_hip target
# On CUDA: includes only hipCUB headers, user has to include CUB directory
target_link_libraries(<your_target> hip::hipcub)

Include only the main header file:

#include <hipcub/hipcub.hpp>

CUB or rocPRIM headers are included by hipCUB depending on the current HIP platform.

Running Unit Tests

# Go to hipCUB build directory
cd hipCUB; cd build

# To run all tests
ctest

# To run unit tests for hipCUB
./test/hipcub/<unit-test-name>

Using custom seeds for the tests

Go to the hipCUB/test/hipcub/test_seed.hpp file.

//(1)
static constexpr int random_seeds_count = 10;

//(2)
static constexpr unsigned int seeds [] = {0, 2, 10, 1000};

//(3)
static constexpr size_t seed_size = sizeof(seeds) / sizeof(seeds[0]);

(1) defines a constant that sets how many passes over the tests will be done with runtime-generated seeds. Modify at will.

(2) defines the user generated seeds. Each of the elements of the array will be used as seed for all tests. Modify at will. If no static seeds are desired, the array should be left empty.

static constexpr unsigned int seeds [] = {};

(3) this line should never be modified.

Running Benchmarks

# Go to hipCUB build directory
cd hipCUB; cd build

# To run benchmark for warp functions:
# Further option can be found using --help
# [] Fields are optional
./benchmark/benchmark_warp_<function_name> [--size <size>] [--trials <trials>]

# To run benchmark for block functions:
# Further option can be found using --help
# [] Fields are optional
./benchmark/benchmark_block_<function_name> [--size <size>] [--trials <trials>]

# To run benchmark for device functions:
# Further option can be found using --help
# [] Fields are optional
./benchmark/benchmark_device_<function_name> [--size <size>] [--trials <trials>]

Documentation

# go to hipCUB docs directory
cd hipCUB; cd docs

# run doxygen and sphinx
./run_doc.sh

# open docBin/html/index.html

Support

Bugs and feature requests can be reported through the issue tracker.

Contributions and License

Contributions of any kind are most welcome! More details are found at CONTRIBUTING and LICENSE.

About

Reusable software components for rocm developers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 94.7%
  • CMake 3.3%
  • Python 1.3%
  • Other 0.7%