-
Notifications
You must be signed in to change notification settings - Fork 4
Zero-fill to Memset Pass #861
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
Draft
Atrisan
wants to merge
11
commits into
main
Choose a base branch
from
zero_fill_replacements
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d9158e2
add shape info to nested array tiles in memory layout analysis
Atrisan 83658ab
add initial zero fill implementation + tests
Atrisan 667b780
loop info based traversal
Atrisan 192c163
update verifier
Atrisan 4e21630
memset replacement after normalize
Atrisan a876bc7
apply new dispatcher for rocm memset
Atrisan ae0a1be
verifier
Atrisan b0cbdae
reset verifier
Atrisan 31234c9
cvaty flow verifier
Atrisan 4e275b4
update verifier
Atrisan 75ff2eb
llvm verifier
Atrisan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "sdfg/analysis/loop_analysis.h" | ||
| #include "sdfg/analysis/memory_layout_analysis.h" | ||
| #include "sdfg/passes/pass.h" | ||
| #include "sdfg/structured_control_flow/map.h" | ||
| #include "sdfg/symbolic/symbolic.h" | ||
| #include "sdfg/types/type.h" | ||
| #include "sdfg/visitor/structured_sdfg_visitor.h" | ||
|
|
||
| namespace sdfg::passes { | ||
|
|
||
| /** | ||
| * @brief Replaces perfectly-nested Map loops that zero out an entire array with a single memset. | ||
| * | ||
| * The pass detects a perfect nest of Map loops whose only effect is to overwrite the | ||
| * complete contents of a (multi-dimensional) array container with the literal value 0 | ||
| * (and nothing else). Such a nest is semantically equivalent to a `memset(A, 0, sizeof(A))` | ||
| * and is rewritten to a single stdlib::MemsetNode. | ||
| * | ||
| * A nest qualifies when: | ||
| * - Each loop level is a Map with `init == 0`, unit stride and an extractable exclusive | ||
| * upper bound; the nest is perfect (each Map body contains exactly the next level). | ||
| * - The innermost body is a single Block whose only computation assigns the constant 0 | ||
| * to one element of the array, indexed exactly by the induction variables of the nest. | ||
| * - The MemoryLayoutAnalysis tile for the target container at the outermost Map covers the | ||
| * whole array contiguously from offset 0 (bounded dimensions match the declared extent, | ||
| * and the covered elements form a dense block), guaranteeing the whole array is covered. | ||
| * Relying on the layout analysis also transparently handles linearized accesses such as | ||
| * `A[i*M + j]`, which are delinearized to the underlying multi-dimensional shape. | ||
| */ | ||
| class ZeroFillToMemsetPass : public sdfg::passes::Pass { | ||
|
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. sdfg::passes:: unnecessary |
||
| public: | ||
| struct State { | ||
| size_t applied = 0; | ||
| }; | ||
|
|
||
| std::string name() override { return "ZeroFillToMemset"; } | ||
|
|
||
| bool run_pass(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) override; | ||
| }; | ||
|
|
||
| class ZeroFillToMemsetVisitor : public sdfg::visitor::ActualStructuredSDFGVisitor { | ||
| public: | ||
| struct Candidate { | ||
| structured_control_flow::Map* map; | ||
| std::string array; | ||
| symbolic::Expression num; | ||
| std::unique_ptr<types::IType> ptr_type; | ||
| }; | ||
|
|
||
| private: | ||
| builder::StructuredSDFGBuilder& builder_; | ||
| ZeroFillToMemsetPass::State& state_; | ||
| analysis::MemoryLayoutAnalysis& memory_layout_analysis_; | ||
| analysis::LoopAnalysis& loop_analysis_; | ||
| std::vector<Candidate> candidates_; | ||
|
|
||
| bool match(structured_control_flow::Map& node, Candidate& candidate); | ||
|
|
||
| public: | ||
| ZeroFillToMemsetVisitor( | ||
| builder::StructuredSDFGBuilder& builder, | ||
| ZeroFillToMemsetPass::State& state, | ||
| analysis::MemoryLayoutAnalysis& memory_layout_analysis, | ||
| analysis::LoopAnalysis& loop_analysis | ||
| ); | ||
|
|
||
| bool visit(structured_control_flow::Map& node) override; | ||
|
|
||
| void apply(); | ||
| }; | ||
|
|
||
| } // namespace sdfg::passes | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not nested namespace syntax as 99.9% of all other files?