-
Notifications
You must be signed in to change notification settings - Fork 74
Add HIP Graph API tutorial #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
66efa4c
Add stream-based prototype
j-stephan 76c7808
Add graph-capturing prototype
j-stephan e3549f8
Refactoring and geometry fixes
j-stephan 1586d52
Disable graph capture tutorial on Windows
j-stephan b0be7aa
Graph creation and smaller fixes
j-stephan 0297069
Address review comments
j-stephan 80210d4
CMake fixes
j-stephan 5c38269
Refactor and align all three versions
j-stephan cabd8eb
Use a phantom by default
j-stephan 7e93ca4
Correct graph layout and bugfixes
j-stephan c385be0
Fix missing `<cstring>` include
j-stephan 84db17f
Fix datatype for std::max
j-stephan 851eafd
Fix identifier naming
j-stephan 943f8c8
Small compatibility fixes
j-stephan 6fe56f8
Explicit casts
j-stephan 6a2cc82
Fix UB
j-stephan 5d49004
Allow concurrent backprojection kernels
j-stephan 4f91f93
Bug fix
j-stephan deaab0d
Use different capturing approach
j-stephan 877a024
Second try
j-stephan 5bc6f06
Fix double graph bug
j-stephan b7ceefe
Sphinx annotations
j-stephan fa0ad25
Add timing information
j-stephan e54f588
Remove dataset option
j-stephan 8bd18a7
Remove subvolume feature
j-stephan 5582bc4
Disable synchronization before graph update
j-stephan b0dee3d
Remove synchronization points and improve timing
j-stephan fafc219
Improve status messages
j-stephan 1ad138a
Synchronize before exiting
j-stephan 916ef13
Improve parallelism
j-stephan 92673ae
One graph per branch
j-stephan 06175bd
Evil node-level hackery
j-stephan d5dc854
Serialize everything
j-stephan b229964
Speed up dataset generation
j-stephan a9784b7
Disable node sorting
j-stephan e4f2842
Revert previous commit
j-stephan 8960363
More sphinx markers
j-stephan ee03c08
Update libTIFF version
j-stephan 5c73d5f
Add sphinx markers
j-stephan 099ef9d
Align CMake
j-stephan a6c0675
Update READMEs and gitignore
j-stephan b974bc2
Code hygiene
j-stephan f0d5c2e
Support GPUs without texture instructions
j-stephan 3d5a7e6
Explicitly install git
j-stephan 4024033
Explicitly install hipFFT
j-stephan 827497c
Install libTIFF
j-stephan b75d5fa
Print duration.count() instead of duration
j-stephan d0bcb10
Remove <omp.h>
j-stephan 7005820
Enable separable compilation and remove link to hip::host
j-stephan 44b313e
Mirror hipFFT examples lookup of libraries and flags
j-stephan fea6fdb
Always use CONFIG mode for find_package
j-stephan 976d2d0
Ensure CMake understands we want to compile for NVIDIA
j-stephan 72842c2
Next try
j-stephan ff0fa26
Compile with warnings and add CUDA helpers
j-stephan 3814510
Correct hipStreamWaitEvent signature
j-stephan 99d42a5
Enforce NVIDIA
j-stephan 1cd6520
More CUDA fixes
j-stephan 2a06455
Link to CUDA driver
j-stephan 6fe57d3
Remove obsolete TIFF handling
j-stephan a0d6db0
Fix remaining warnings
j-stephan 0767028
LibTIFF cleanup
j-stephan f1cfe9f
Add Windows note
j-stephan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -22,7 +22,8 @@ | |
|
||
SUBDIRECTORIES := \ | ||
Programming-Guide \ | ||
Reference | ||
Reference \ | ||
Tutorials | ||
|
||
all: $(SUBDIRECTORIES) | ||
|
||
|
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
cmake_minimum_required(VERSION 3.21 FATAL_ERROR) | ||
project(HIP-Doc-Tutorials LANGUAGES CXX) | ||
|
||
include(CTest) | ||
|
||
add_subdirectory(graph_api) |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
cmake_minimum_required(VERSION 3.21) | ||
|
||
project(hip_graph_api_tutorial LANGUAGES CXX) | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/../../../Common/HipPlatform.cmake") | ||
select_gpu_language() | ||
enable_language(${ROCM_EXAMPLES_GPU_LANGUAGE}) | ||
select_hip_platform() | ||
|
||
if(CMAKE_SYSTEM_NAME MATCHES "Windows") | ||
set(ROCM_ROOT | ||
"$ENV{HIP_PATH}" | ||
CACHE PATH | ||
"Root directory of the ROCm installation" | ||
) | ||
else() | ||
set(ROCM_ROOT | ||
"/opt/rocm" | ||
CACHE PATH | ||
"Root directory of the ROCm installation" | ||
) | ||
endif() | ||
|
||
list(APPEND CMAKE_PREFIX_PATH "${ROCM_ROOT}") | ||
|
||
add_subdirectory(src) |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# HIP-Doc HIP Graph API tutorial | ||
|
||
## Description | ||
|
||
This example demonstrates how to port an existing stream-based application to a graph-based application. For more | ||
information on this topic, please refer to the | ||
[HIP Documentation](https://rocm.docs.amd.com/projects/HIP/en/latest/tutorial/graph_api.html). | ||
|
||
### Prerequisites | ||
|
||
On Windows, this example can only be built by CMake and the Ninja generator. Visual Studio generators are not supported. | ||
|
||
### Application flow | ||
|
||
#### Stream variant | ||
|
||
1. The number of asynchronous engines on the device is queried. | ||
2. A phantom volume is created and forward projections are created from it. | ||
3. The required data buffers, hipFFT plans, etc. are set up. | ||
4. The forward projections are processed in batches. The batch size is equal to the number of asynchronous engines. Each | ||
batch item is processed in its own stream. Each projection is processed in the following way: | ||
1. All pixels in the projection are normalized, i.e. transformed from a 12-bit unsigned integer value to a 32-bit | ||
floating-point value in the range [0, 1]. | ||
2. The projection is log transformed. | ||
3. The projection is weighted. | ||
4. The projection is transformed into Fourier space. | ||
5. The projection is filtered in Fourier space. | ||
6. The filtered projection is transformed into real space. | ||
7. The filtered projection is back-projected. | ||
5. The resulting volume is saved to disk. | ||
6. The data is cleaned up. | ||
|
||
#### Capturing variant | ||
|
||
1. The number of asynchronous engines on the device is queried. | ||
2. A phantom volume is created and forward projections are created from it. | ||
3. The required data buffers, hipFFT plans, etc. are set up. | ||
4. The forward projections are processed in batches. The batch size is equal to the number of asynchronous engines. Each | ||
batch item is processed in its own stream. All processing streams are captured into a HIP graph template. | ||
Each projection is processed in the following way: | ||
1. All pixels in the projection are normalized, i.e. transformed from a 12-bit unsigned integer value to a 32-bit | ||
floating-point value in the range [0, 1]. | ||
2. The projection is log transformed. | ||
3. The projection is weighted. | ||
4. The projection is transformed into Fourier space. | ||
5. The projection is filtered in Fourier space. | ||
6. The filtered projection is transformed into real space. | ||
7. The filtered projection is back-projected. | ||
5. The resulting graph template is instantiated and launched on a stream. | ||
6. The resulting volume is saved to disk. | ||
7. The data is cleaned up. | ||
|
||
#### Manual creation variant | ||
|
||
1. The number of asynchronous engines on the device is queried. | ||
2. A phantom volume is created and forward projections are created from it. | ||
3. The required data buffers, hipFFT plans, etc. are set up. | ||
4. The forward projections are processed in batches. The batch size is equal to the number of asynchronous engines. Each | ||
batch item represents a branch in the graph template, and each branch consists of the following steps where each step | ||
represents a node in the graph: | ||
1. All pixels in the projection are normalized, i.e. transformed from a 12-bit unsigned integer value to a 32-bit | ||
floating-point value in the range [0, 1]. | ||
2. The projection is log transformed. | ||
3. The projection is weighted. | ||
4. The projection is transformed into Fourier space. | ||
5. The projection is filtered in Fourier space. | ||
6. The filtered projection is transformed into real space. | ||
7. The filtered projection is back-projected. | ||
5. The resulting graph template is instantiated and launched on a stream. | ||
6. The resulting volume is saved to disk. | ||
7. The data is cleaned up. | ||
|
||
## Demonstrated API calls | ||
|
||
### HIP Runtime | ||
|
||
#### Device symbols | ||
|
||
* `atomicAdd` | ||
* `blockIdx` | ||
* `blockDim` | ||
* `cosf` | ||
* `expf` | ||
* `fabsf` | ||
* `floorf` | ||
* `fmaxf` | ||
* `fminf` | ||
* `logf` | ||
* `max` | ||
* `min` | ||
* `roundf` | ||
* `sinf` | ||
* `sqrtf` | ||
* `tex2D` | ||
* `threadIdx` | ||
|
||
#### Host symbols | ||
|
||
* `hipCreateChannelDesc` | ||
* `hipCreateTextureObject` | ||
* `hipDestroyTextureObject` | ||
* `hipDeviceSynchronize` | ||
* `hipEventCreate` | ||
* `hipEventDestroy` | ||
* `hipEventRecord` | ||
* `hipFree` | ||
* `hipFreeHost` | ||
* `hipGetDeviceProperties` | ||
* `hipGetErrorString` | ||
* `hipGraphAddKernelNode` | ||
* `hipGraphAddMemcpyNode` | ||
* `hipGraphAddMemsetNode` | ||
* `hipGraphCreate` | ||
* `hipGraphDebugDotPrint` | ||
* `hipGraphDestroy` | ||
* `hipGraphExecDestroy` | ||
* `hipGraphExecUpdate` | ||
* `hipGraphGetNodes` | ||
* `hipGraphInstantiate` | ||
* `hipGraphLaunch` | ||
* `hipGraphNodeGetDependentNodes` | ||
* `hipHostMalloc` | ||
* `hipLaunchHostFunc` | ||
* `hipMalloc` | ||
* `hipMalloc3D` | ||
* `hipMallocPitch` | ||
* `hipMemcpy2DAsync` | ||
* `hipMemcpy3DAsync` | ||
* `hipMemGetInfo` | ||
* `hipMemset2DAsync` | ||
* `hipMemset3D` | ||
* `hipStreamBeginCapture` | ||
* `hipStreamBeginCaptureToGraph` | ||
* `hipStreamCreate` | ||
* `hipStreamEndCapture` | ||
* `hipStreamDestroy` | ||
* `hipStreamSynchronize` | ||
* `hipStreamWaitEvent` | ||
* `make_hipExtent` | ||
* `make_hipPitchedPtr` | ||
* `make_hipPos` | ||
|
||
### hipFFT library symbols | ||
|
||
* `hipfftCreate` | ||
* `hipfftExecC2R` | ||
* `hipfftExecR2C` | ||
* `hipfftDestroy` | ||
* `hipfftMakePlanMany` | ||
* `hipfftPlan1d` | ||
* `hipfftSetStream` |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
hip_graph_api_tutorial_streams | ||
hip_graph_api_tutorial_graph_capture | ||
hip_graph_api_tutorial_graph_creation | ||
tiff.dll | ||
libtiff.so* |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.