-
Notifications
You must be signed in to change notification settings - Fork 237
[rocroller] Build Basic-Block Dependence DAGs #4785
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
Open
pjots
wants to merge
39
commits into
develop
Choose a base branch
from
users/psandhu/BasicBlockDependenceDAGs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+654
−97
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
d5c6b3f
construct dependenceDAG and update RemoveImplicitScheduling pass logic
pjots 7782f17
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots 5c3924f
Merge branch 'develop' into users/psandhu/BasicBlockDependenceDAGs
pjots 38fe5be
apply Nathan's suggested patch -- more modular and reusable code
pjots 4d30184
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots e21943f
order might be undefined in kernelgraph for two Multiply nodes with W…
pjots 0dd47e2
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots b6df996
WIP
pjots 36aeca0
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots f2b4cf1
Revert "WIP"
pjots 9b0c590
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots 13800bd
update test
pjots 36a999e
fix formatting
pjots 6b9dbd0
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots d741c3a
Merge branch 'develop' into users/psandhu/BasicBlockDependenceDAGs
pjots d40e06f
update code structure
pjots 4f55c99
added licenses
pjots 910bb44
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots 22a735e
Merge branch 'users/psandhu/BasicBlockDependenceDAGs' of github.com:R…
pjots 91d79fa
Merge branch 'develop' into users/psandhu/BasicBlockDependenceDAGs
pjots 383333d
add a unit test
pjots 78c9a9e
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots 966c558
Merge branch 'users/psandhu/BasicBlockDependenceDAGs' of github.com:R…
pjots f872cdc
add a fun Nth fibonacci unit test
pjots d3f184d
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots f38c6f0
updated hoist unit test
pjots 6e6902d
address Kerry's comments
pjots e789bb6
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots 76bebb8
adds documentation
pjots 76cea6b
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots ca52c33
Merge branch 'develop' into users/psandhu/BasicBlockDependenceDAGs
pjots 35cdd49
WIP add unit tests
pjots 7e9a01b
Merge branch 'users/psandhu/BasicBlockDependenceDAGs' of github.com:R…
pjots c1eaf26
added check for same basic block, unit testing WIP
pjots c80ba10
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots 76f2905
return boolean for addDependenceEdge routine
pjots 2542551
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots cbdb67a
remove belongToSameBasicBlock routine and add TODOs
pjots 955a4dd
Merge branch 'develop' of github.com:ROCm/rocm-libraries into users/p…
pjots 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
33 changes: 33 additions & 0 deletions
33
shared/rocroller/lib/include/rocRoller/KernelGraph/ControlGraph/DataDependenceDAG.hpp
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,33 @@ | ||
| // Copyright Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <rocRoller/KernelGraph/ControlGraph/ControlGraph.hpp> | ||
|
|
||
| namespace rocRoller::KernelGraph::DataDependenceDAG | ||
| { | ||
| /** | ||
| * Builds the data dependence graph for the given kernel graph, | ||
| * specifically based on its control graph portion. It explicitly | ||
| * represents only the data dependences(flow, anti, and output) between | ||
| * the control graph nodes at the basic-block level. | ||
| * | ||
| * The data dependence graph has no cycles in it, therefore it | ||
| * is termed as data dependence DAG (directed acyclic graph). | ||
| * Since it involves multiple basic-blocks, the data dependence graph | ||
| * may not be a connected graph at the moment. In the future, | ||
| * we can make it as a connected graph by transforming it into a | ||
| * program dependence graph (which includes both data and control | ||
| * dependence information). | ||
| * | ||
| * It describes the dependency relationship between the control graph nodes, | ||
| * so it makes sense to use the existing `rocRoller::KernelGraph::ControlGraph` | ||
| * structure for its represenatation. | ||
| * | ||
| * The dependences are indicated using `Sequence` edges at each basic-block | ||
| * level i.e. between the nodes sharing the same immediate body-parent | ||
| * in `graph.control`. | ||
| */ | ||
| ControlGraph::ControlGraph ConstructDataDependenceDAG(KernelGraph const& graph); | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
shared/rocroller/lib/include/rocRoller/KernelGraph/ControlGraph/DataDependenceDAG_detail.hpp
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,55 @@ | ||
| // Copyright Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <rocRoller/KernelGraph/ControlGraph/ControlFlowRWTracer.hpp> | ||
|
|
||
| namespace rocRoller::KernelGraph::DataDependenceDAG::Detail | ||
| { | ||
| class DataDependenceDAGDetail | ||
| { | ||
| public: | ||
| /** | ||
| * Initializes the data dependence DAG structure (`m_dependenceDAG`) | ||
| * with only the control nodes from the given kernel graph. | ||
| */ | ||
| DataDependenceDAGDetail(KernelGraph const& graph); | ||
|
|
||
| /** | ||
| * Returns the body-parent for the given node in the control graph. | ||
| */ | ||
| int getBodyParent(int control); | ||
| /** | ||
| * Adds a dependence edge(represented via `Sequence`) between the given | ||
| * source and destination nodes in the dependence DAG (`m_dependenceDAG), | ||
| * if both the nodes have the same body-parent. | ||
| * | ||
| * Returns true if a dependence edge is added or exists between the | ||
| * given source and destination nodes, otherwise returns false. | ||
| */ | ||
| bool addDependenceEdge(int source, int dest); | ||
| /** | ||
| * Makes necessary updates to `m_latestWriteToCoord`, `m_latestReadsToCoord` | ||
| * and `m_dependenceDAG` structures for the given `ReadWriteRecord`. | ||
| */ | ||
| void processReadWriteRecord(ControlFlowRWTracer::ReadWriteRecord const& record); | ||
| /** | ||
| * Builds the data dependence DAG by populating the `m_dependenceDAG` structure | ||
| * with required dependence edges based on the trace generated using `ControlFlowRWTracer` | ||
| * for `m_graph`. | ||
| */ | ||
| void constructDataDependenceDAG(); | ||
| /** | ||
| * Returns the data dependence DAG (`m_dependenceDAG`). | ||
| */ | ||
| ControlGraph::ControlGraph getDataDependenceDAG(); | ||
|
|
||
| private: | ||
| KernelGraph const& m_graph; | ||
| ControlGraph::ControlGraph m_dependenceDAG; | ||
| std::unordered_map<int, int> m_bodyParentCache; | ||
| std::map<int, int> m_latestWriteToCoord; | ||
| std::map<int, std::unordered_set<int>> m_latestReadsToCoord; | ||
| }; | ||
| } |
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
173 changes: 173 additions & 0 deletions
173
shared/rocroller/lib/source/KernelGraph/ControlGraph/DataDependenceDAG.cpp
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,173 @@ | ||
| // Copyright Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include <rocRoller/KernelGraph/ControlGraph/DataDependenceDAG.hpp> | ||
| #include <rocRoller/KernelGraph/ControlGraph/DataDependenceDAG_detail.hpp> | ||
| #include <rocRoller/KernelGraph/Utils.hpp> | ||
|
|
||
| namespace rocRoller::KernelGraph | ||
| { | ||
| namespace DataDependenceDAG | ||
| { | ||
| using ReadWrite = ControlFlowRWTracer::ReadWrite; | ||
|
|
||
| ControlGraph::ControlGraph ConstructDataDependenceDAG(KernelGraph const& graph) | ||
| { | ||
| using namespace Detail; | ||
|
|
||
| DataDependenceDAGDetail obj(graph); | ||
| obj.constructDataDependenceDAG(); | ||
| return obj.getDataDependenceDAG(); | ||
| } | ||
|
|
||
| namespace Detail | ||
| { | ||
| DataDependenceDAGDetail::DataDependenceDAGDetail(KernelGraph const& graph) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it makes sense, the constructor could call |
||
| : m_graph(graph) | ||
| { | ||
| // Insert all control graph nodes into the data dependence DAG | ||
| for(auto node : m_graph.control.getNodes()) | ||
| { | ||
| m_dependenceDAG.setElement(node, m_graph.control.getElement(node)); | ||
| } | ||
| } | ||
|
|
||
| ControlGraph::ControlGraph DataDependenceDAGDetail::getDataDependenceDAG() | ||
| { | ||
| return m_dependenceDAG; | ||
| } | ||
|
|
||
| void DataDependenceDAGDetail::constructDataDependenceDAG() | ||
| { | ||
| auto tracer = ControlFlowRWTracer(m_graph); | ||
| auto records = tracer.coordinatesReadWrite(); | ||
|
|
||
| // This assumes that the trace is ordered and records for the | ||
| // same control operation are consecutive. | ||
| std::unordered_set<int> seen; | ||
| for(auto iter = records.begin(); iter != records.end();) | ||
| { | ||
| auto currentControl = iter->control; | ||
|
|
||
| AssertFatal(seen.find(currentControl) == seen.end(), | ||
| "The records for the same control operation are not consecutive.", | ||
| ShowValue(currentControl)); | ||
|
|
||
| for(; iter != records.end() && iter->control == currentControl; ++iter) | ||
| { | ||
| processReadWriteRecord(*iter); | ||
| } | ||
|
|
||
| seen.insert(currentControl); | ||
| } | ||
| } | ||
|
|
||
| int DataDependenceDAGDetail::getBodyParent(int control) | ||
| { | ||
| if(auto iter = m_bodyParentCache.find(control); iter != m_bodyParentCache.end()) | ||
| return iter->second; | ||
|
|
||
| auto topSetCoordinate = getTopSetCoordinate(m_graph, control); | ||
| auto bodyParent = bodyParents(topSetCoordinate, m_graph).take(1).only(); | ||
| AssertFatal(bodyParent.has_value(), | ||
| "Control node has no body parent", | ||
| ShowValue(control), | ||
| ShowValue(topSetCoordinate)); | ||
|
|
||
| m_bodyParentCache.emplace(control, bodyParent.value()); | ||
| return bodyParent.value(); | ||
| } | ||
|
|
||
| bool DataDependenceDAGDetail::addDependenceEdge(int source, int dest) | ||
| { | ||
| AssertFatal(source != dest, ShowValue(source), ShowValue(dest)); | ||
|
|
||
| if(getBodyParent(source) != getBodyParent(dest)) | ||
| return false; | ||
|
|
||
| if(!m_dependenceDAG.findEdge(source, dest).has_value()) | ||
| { | ||
| m_dependenceDAG.addElement(ControlGraph::Sequence(), {source}, {dest}); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void DataDependenceDAGDetail::processReadWriteRecord( | ||
| ControlFlowRWTracer::ReadWriteRecord const& record) | ||
| { | ||
| AssertFatal(record.rw != ReadWrite::Count, | ||
| ShowValue(record.control), | ||
| ShowValue(record.coordinate), | ||
| ShowValue(record.rw)); | ||
|
|
||
| if(auto writeIter = m_latestWriteToCoord.find(record.coordinate); | ||
| writeIter != m_latestWriteToCoord.end()) | ||
| { | ||
| AssertFatal(writeIter->second != record.control, | ||
| ShowValue(writeIter->second), | ||
| ShowValue(record.control), | ||
| ShowValue(record.coordinate), | ||
| ShowValue(record.rw)); | ||
|
|
||
| // adds WW(output dep) or WR(flow dep) edge | ||
| auto depAdded = addDependenceEdge(writeIter->second, record.control); | ||
|
|
||
| //TODO: Check the order and ensure that writeIter->second | ||
| // happens before record.control. | ||
| //if(depAdded) | ||
| //{ | ||
| // auto order = m_graph.control.compareNodes( | ||
| // UseCacheIfAvailable, writeIter->second, record.control); | ||
| // AssertFatal(order == ControlGraph::NodeOrdering::LeftFirst | ||
| // || order == ControlGraph::NodeOrdering::RightInBodyOfLeft, | ||
| // ShowValue(order), | ||
| // ShowValue(writeIter->second), | ||
| // ShowValue(record.control), | ||
| // ShowValue(record.coordinate), | ||
| // ShowValue(record.rw)); | ||
| //} | ||
| } | ||
|
|
||
| if(record.rw == ReadWrite::WRITE || record.rw == ReadWrite::READWRITE) | ||
| { | ||
| for(auto const readControl : m_latestReadsToCoord[record.coordinate]) | ||
| { | ||
| if(readControl == record.control) | ||
| continue; | ||
|
|
||
| // adds RW(anti dep) edges | ||
| auto depAdded = addDependenceEdge(readControl, record.control); | ||
|
|
||
| //TODO: Check the order and ensure that writeIter->second | ||
| // happens before record.control. | ||
| //if(depAdded) | ||
| //{ | ||
| // auto order = m_graph.control.compareNodes( | ||
| // UseCacheIfAvailable, readControl, record.control); | ||
| // AssertFatal(order == ControlGraph::NodeOrdering::LeftFirst | ||
| // || order | ||
| // == ControlGraph::NodeOrdering::RightInBodyOfLeft, | ||
| // ShowValue(order), | ||
| // ShowValue(readControl), | ||
| // ShowValue(record.control), | ||
| // ShowValue(record.coordinate), | ||
| // ShowValue(record.rw)); | ||
| //} | ||
| } | ||
|
|
||
| // Since the current control node writes into this coord, | ||
| // the latest reads info needs to be reset. | ||
| m_latestReadsToCoord[record.coordinate].clear(); | ||
| // update the latest write to coord | ||
| m_latestWriteToCoord[record.coordinate] = record.control; | ||
| } | ||
|
|
||
| if(record.rw == ReadWrite::READ || record.rw == ReadWrite::READWRITE) | ||
| { | ||
| m_latestReadsToCoord[record.coordinate].insert(record.control); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.