-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f615ce2
commit 5cababb
Showing
8 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,56 @@ | ||
# rocThrust Examples | ||
|
||
## Summary | ||
|
||
The examples in this subdirectory showcase the functionality of the [rocThrust](https://github.com/rocmSoftwarePlatform/rocThrust) library. The examples build on Linux using the ROCm platform and on Windows using the HIP on Windows platform. | ||
|
||
## Prerequisites | ||
|
||
### Linux | ||
|
||
- [CMake](https://cmake.org/download/) (at least version 3.21) | ||
- OR GNU Make - available via the distribution's package manager | ||
- OR GNU Make - available via the distribution's package manager | ||
- [ROCm](https://docs.amd.com/bundle/ROCm-Installation-Guide-v5.2/page/Overview_of_ROCm_Installation_Methods.html) (at least version 5.x.x) | ||
- [rocThrust](https://github.com/rocmSoftwarePlatform/rocThrust): `rocthrust-dev` package available from [repo.radeon.com](https://repo.radeon.com/rocm/). The repository is added during the standard ROCm [install procedure](https://docs.amd.com/bundle/ROCm-Installation-Guide-v5.2/page/How_to_Install_ROCm.html). | ||
|
||
### Windows | ||
|
||
- [Visual Studio](https://visualstudio.microsoft.com/) 2019 or 2022 with the "Desktop Development with C++" workload | ||
- ROCm toolchain for Windows (No public release yet) | ||
- The Visual Studio ROCm extension needs to be installed to build with the solution files. | ||
- The Visual Studio ROCm extension needs to be installed to build with the solution files. | ||
- [rocThrust](https://github.com/rocmSoftwarePlatform/rocThrust): installed as part of the ROCm SDK on Windows | ||
- [CMake](https://cmake.org/download/) (optional, to build with CMake. Requires at least version 3.21) | ||
- [Ninja](https://ninja-build.org/) (optional, to build with CMake) | ||
|
||
## Building | ||
|
||
### Linux | ||
|
||
Make sure that the dependencies are installed, or use the [provided Dockerfile](../../Dockerfiles/hip-libraries-rocm-ubuntu.Dockerfile) to build and run the examples in a containerized environment that has all prerequisites installed. | ||
|
||
#### Using CMake | ||
|
||
All examples in the `rocThrust` subdirectory can either be built by a single CMake project or be built independently. | ||
|
||
- `$ cd Libraries/rocThrust` | ||
- `$ cmake -S . -B build` | ||
- `$ cmake --build build` | ||
|
||
#### Using Make | ||
|
||
All examples can be built by a single invocation to Make or be built independently. | ||
|
||
- `$ cd Libraries/rocThrust` | ||
- `$ make` | ||
|
||
### Windows | ||
|
||
#### Visual Studio | ||
|
||
Visual Studio solution files are available for the individual examples. To build all examples for rocThrust open the top level solution file [ROCm-Examples-VS2019.sln](../../ROCm-Examples-VS2019.sln) and filter for rocThrust. | ||
|
||
For more detailed build instructions refer to the top level [README.md](../../README.md#visual-studio). | ||
|
||
#### CMake | ||
|
||
All examples in the `rocThrust` subdirectory can either be built by a single CMake project or be built independently. For build instructions refer to the top-level [README.md](../../README.md#cmake-2). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
# rocThrust Norm Example | ||
|
||
## Description | ||
|
||
An example is presented to compute the Euclidean norm of a `thrust::device_vector`. The result is written to the standard output. | ||
|
||
### Application flow | ||
|
||
1. Instantiate a host vector. | ||
2. Copy the vector to the device by constructing `thrust::device_vector` from the host vector. | ||
3. Set the initial value for the transformed reduction to 0. | ||
4. Add the sum of the square of each element and get the square root of the sum (by using `std::sqrt()`). That is the definition of the Euclidean norm. Use the `square` operator to calculate the square of each element. Use the `thrust::plus` binary operator to sum elements. | ||
5. Print the norm to the standard output. | ||
|
||
## Key APIs and Concepts | ||
|
||
- `thrust::transform_reduce()` computes a generalized sum (AKA reduction or fold) after transforming each element with a unary function. Both the transformation and the reduction function can be specified. (e.g. with `thrust::plus` as the binary summation and `f` as the transform function `transform_reduce` would compute the value of `f(a[0]) + f(a[1]) + f(a[2]) + ...`). | ||
- In the example, the operator is the `thrust::plus` function object with doubles. It is a binary operator that returns the arithmetic sum. | ||
- An initial value is required for the summation. | ||
- A `thrust::device_vector` is used to simplify memory management and transfer. See the [vectors example](../vectors) for the usage of `thrust::vector`. | ||
|
||
## Demonstrated API Calls | ||
|
||
### rocThrust | ||
|
||
- `thrust::device_vector::device_vector` | ||
- `thrust::plus` | ||
- `thrust::reduce()` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters