-
Notifications
You must be signed in to change notification settings - Fork 67
core(graph): initial doc #648
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| 16. Graphs | ||
| ========== | ||
|
|
||
| Usage | ||
| ----- | ||
|
|
||
| :cppkokkos:`Kokkos::Graph` is an abstraction that describes | ||
| asynchronous workloads organised as a direct acyclic graph (DAG). | ||
|
|
||
| Once defined, the graph can be executed many times. | ||
|
|
||
| :cppkokkos:`Kokkos::Graph` is specialized for some backends: | ||
|
|
||
| * :cppkokkos:`Cuda` | ||
| * :cppkokkos:`HIP` | ||
| * :cppkokkos:`SYCL` | ||
|
|
||
| On these backends, the :cppkokkos:`Kokkos::Graph` specialisations map to the native graph API, namely, the CUDA Graph API, the HIP Graph API, and the SYCL (command) Graph API, respectively. | ||
|
|
||
| For other backends, :cppkokkos:`Kokkos::Graph` provides a defaulted implementation. | ||
|
|
||
| Execution space instance versus graph | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Workloads submitted on :cppkokkos:`Kokkos` execution space instances execute *eagerly*, *i.e.*, | ||
| once the :cppkokkos:`Kokkos::parallel_` function is called, the workload is immediately launched on the device. | ||
|
|
||
| By contrast, the :cppkokkos:`Kokkos::Graph` abstraction follows *lazy* execution, | ||
| *i.e*, workloads added to a :cppkokkos:`Kokkos::Graph` are **not** executed *until* | ||
| the whole graph is ready and submitted. | ||
|
|
||
| Always in 3 phases | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Typically, 3 phases are needed: | ||
|
|
||
| 1. definition | ||
| 2. instantiation | ||
| 3. submission | ||
|
|
||
| The *definition* phase consists in describing the workloads: what they do, as well as their dependencies. | ||
| In other words, this phase creates a *topological* graph of workloads. | ||
|
|
||
| The *instantiation* phase **locks** the topology, *i.e.*, it cannot be changed anymore. | ||
| During this phase, the graph will be checked for flaws. | ||
| The backend creates an *executable* graph. | ||
|
|
||
| The last phase is *submission*. It will execute the workloads, observing their dependencies. | ||
| This phase can be run multiple times. | ||
|
|
||
| Advantages | ||
| ~~~~~~~~~~ | ||
|
|
||
| There are many advantages. Here are a few: | ||
|
|
||
| * Since the workloads are described ahead of execution, | ||
| the backend driver and/or compiler can leverage optimization opportunities. | ||
| * Launch overhead is reduced, benefitting DAGs consisting of small workloads. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
||
| Diamond DAG | ||
| ~~~~~~~~~~~ | ||
|
|
||
| Consider a diamond-like DAG. | ||
|
|
||
| .. graphviz:: | ||
|
|
||
| digraph diamond { | ||
| A -> B; | ||
| A -> C; | ||
| B -> D; | ||
| C -> D; | ||
| } | ||
|
|
||
| The following snippet defines, instantiates and submits a :cppkokkos:`Kokkos::Graph` | ||
| for this DAG. | ||
|
|
||
| .. code-block:: c++ | ||
|
|
||
| auto graph = Kokkos::create_graph([&](auto root) { | ||
| auto node_A = root.then_parallel_for("workload A", ...policy..., ...functor...); | ||
|
|
||
| auto node_B = node_A.then_parallel_for("workload B", ...policy..., ...functor...); | ||
| auto node_C = node_A.then_parallel_for("workload C", ...policy..., ...functor...); | ||
|
|
||
| auto node_D = Kokkos::when_all(node_B, node_C).then_parallel_for("workload D", ...policy..., ...functor...); | ||
| }); | ||
|
|
||
| graph.instantiate(); | ||
|
|
||
| graph.submit(); |
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
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.