1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
# rocPRIM
The rocPRIM is a header-only library providing HIP parallel primitives for developing
performant GPU-accelerated code on AMD ROCm platform.
## Requirements
* Git
* CMake (3.16 or later)
* AMD [ROCm](https://rocm.github.io/install.html) platform (1.8.2 or later)
* Including [HIP-clang](https://github.com/ROCm-Developer-Tools/HIP/blob/master/INSTALL.md#hip-clang) compiler
* C++14
* Python 3.6 or higher (HIP on Windows only, required only for install script)
* Visual Studio 2019 with clang support (HIP on Windows only)
* Strawberry Perl (HIP on Windows only)
Optional:
* [GTest](https://github.com/google/googletest)
* Required only for tests. Building tests is enabled by default.
* It will be automatically downloaded and built by cmake script.
* [Google Benchmark](https://github.com/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
### Linux
```shell
git clone https://github.com/ROCmSoftwarePlatform/rocPRIM.git
# Go to rocPRIM directory, create and go to the build directory.
cd rocPRIM; mkdir build; cd build
# Configure rocPRIM, setup options for your system.
# Build options:
# ONLY_INSTALL - OFF by default, If this flag is on, the build ignore the BUILD_* flags
# BUILD_TEST - OFF by default,
# BUILD_EXAMPLE - OFF by default,
# BUILD_BENCHMARK - OFF by default.
# BENCHMARK_CONFIG_TUNING - OFF by default. The purpose of this flag to find the best kernel config parameters.
# At ON the compilation time can be increased significantly.
# AMDGPU_TARGETS - list of AMD architectures, default: gfx803;gfx900;gfx906;gfx908.
# You can make compilation faster if you want to test/benchmark only on one architecture,
# for example, add -DAMDGPU_TARGETS=gfx906 to 'cmake' parameters.
# AMDGPU_TEST_TARGETS - list of AMD architectures, default: "" (default system device)
# If you want to detect failures on a per GFX IP basis, setting it to some set of ips will create
# separate tests with the ip name embedded into the test name. Building for all, but selecting
# tests only of a specific architecture is possible for eg: ctest -R gfx803|gfx900
#
# ! IMPORTANT !
# Set C++ compiler to 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.
# Using HIP-clang:
[CXX=hipcc] cmake -DBUILD_BENCHMARK=ON ../.
#
# ! EXPERIMENTAL !
# Alternatively one may build using the experimental (and highly incomplete) HIP-CPU back-end for host-side
# execution using any C++17 conforming compiler (supported by HIP-CPU). AMDGPU_* options are unavailable in this case.
# USE_HIP_CPU - OFF by default
# Build
make -j4
# Optionally, run tests if they're enabled.
ctest --output-on-failure
# Install
[sudo] make install
```
### Windows
Initial support for HIP on Windows has been added. To install, use the provided rmake.py python script:
```shell
git clone https://github.com/ROCmSoftwarePlatform/rocPRIM.git
cd rocPRIM
# 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 rocPRIM
Include `<rocprim/rocprim.hpp>` header:
```cpp
#include <rocprim/rocprim.hpp>
```
Recommended way of including rocPRIM into a CMake project is by using its package
configuration files. rocPRIM package name is `rocprim`.
```cmake
# "/opt/rocm" - default install prefix
find_package(rocprim REQUIRED CONFIG PATHS "/opt/rocm/rocprim")
...
# Includes only rocPRIM headers, HIP libraries have
# to be linked manually by user
target_link_libraries(<your_target> roc::rocprim)
# Includes rocPRIM headers and required HIP dependencies
target_link_libraries(<your_target> roc::rocprim_hip)
```
## Running Unit Tests
Unit tests are implemented in terms of Google Test and collections of tests are wrapped to be invoked from CTest for convenience.
```shell
# Go to rocPRIM build directory
cd rocPRIM; cd build
# List available tests
ctest --show-only
# To run all tests
ctest
# Run specific test(s)
ctest -R <regex>
# To run the Google Test manually
./test/rocprim/test_<unit-test-name>
```
### Using multiple GPUs concurrently for testing
This feature requires CMake 3.16+ to be used for building / testing. _(Prior versions of CMake cannot assign ids to tests when running in parallel. Assigning tests to distinct devices could only be done at the cost of extreme complexity._)
The unit tests can make use of [CTest Resource Allocation](https://cmake.org/cmake/help/latest/manual/ctest.1.html#resource-allocation) feature enabling distributing tests across multiple GPUs in an intelligent manner. The feature can accelerate testing when multiple GPUs of the same family are in a system as well as test multiple family of products from one invocation without having to resort to `HIP_VISIBLE_DEVICES` environment variable. The feature relies on the presence of a resource spec file.
> IMPORTANT: trying to use `RESOURCE_GROUPS` and `--resource-spec-file` with CMake/CTest respectively of versions prior to 3.16 omits the feature silently. No warnings issued about unknown properties or command-line arguments. Make sure that `cmake`/`ctest` invoked are sufficiently recent.
#### Auto resource spec generation
There is a utility script in the repo that may be called independently:
```shell
# Go to rocPRIM build directory
cd rocPRIM; cd build
# Invoke directly or use CMake script mode via cmake -P
../cmake/GenerateResourceSpec.cmake
# Assuming you have 2 compatible GPUs in the system
ctest --resource-spec-file ./resources.json --parallel 2
```
#### Manual
Assuming the user has 2 GPUs from the gfx900 family and they are the first devices enumerated by the system one may specify during configuration `-D AMDGPU_TEST_TARGETS=gfx900` stating only one family will be tested. Leaving this var empty (default) results in targeting the default device in the system. To let CMake know there are 2 GPUs that should be targeted, one has to feed CTest a JSON file via the `--resource-spec-file <path_to_file>` flag. For example:
```json
{
"version": {
"major": 1,
"minor": 0
},
"local": [
{
"gfx900": [
{
"id": "0"
},
{
"id": "1"
}
]
}
]
}
```
Invoking CTest as `ctest --resource-spec-file <path_to_file> --parallel 2` will allow two tests to run concurrently which will be distributed among the two GPUs.
### Using custom seeds for the tests
Go to the `rocPRIM/test/rocprim/test_seed.hpp` file.
```cpp
//(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.
```cpp
static constexpr unsigned int seeds [] = {};
```
(3) this line should never be modified.
## Running Benchmarks
```shell
# Go to rocPRIM build directory
cd rocPRIM; 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>]
```
### Performance configuration
Most of device-wide primitives provided by rocPRIM can be tuned for different AMD device,
different types or different operations using compile-time configuration structures passed
to them as a template parameter. Main "knobs" are usually size of the block and number of
items processed by a single thread.
rocPRIM has built-in default configurations for each of its primitives. In order to use
included configurations user should define macro `ROCPRIM_TARGET_ARCH` to `803` if algorithms
should be optimized for gfx803 GCN version, or to `900` for gfx900.
## Documentation
The latest rocPRIM documentation and API description can be found [here](https://codedocs.xyz/ROCmSoftwarePlatform/rocPRIM/).
It can also be build using the following commands
```shell
# go to rocPRIM doc directory
cd rocPRIM; cd doc
# run doxygen
doxygen Doxyfile
# open html/index.html
```
## hipCUB
[hipCUB](https://github.com/ROCmSoftwarePlatform/hipCUB/) is a thin wrapper library on top of
[rocPRIM](https://github.com/ROCmSoftwarePlatform/rocPRIM) or [CUB](https://github.com/NVlabs/cub).
It enables developers to port project that uses CUB library to the
[HIP](https://github.com/ROCm-Developer-Tools/HIP) layer and to run them on AMD hardware. In [ROCm](https://rocm.github.io/)
environment hipCUB uses rocPRIM library as the backend, however, on CUDA platforms it uses CUB instead.
## Support
Bugs and feature requests can be reported through [the issue tracker](https://github.com/ROCmSoftwarePlatform/rocPRIM/issues).
## Contributions and License
Contributions of any kind are most welcome! More details are found at [CONTRIBUTING](./CONTRIBUTING.md)
and [LICENSE](./LICENSE.txt).
|