docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
map_fusion.h
Go to the documentation of this file.
1#pragma once
2
12
13namespace sdfg {
14namespace transformations {
15
17
32class MapFusion : public Transformation {
34
37 bool applied_ = false;
38 bool require_consecutive_ = true; // Only fuse if maps are consecutive in the sequence
39 // When false, Case 2 (init-into-reduction hoisting) is disabled and such fusions are
40 // rejected. This lets the pipeline restrict hoisting to a single, final map-fusion run
41 // so that loop distribution and earlier fusion runs do not fight each other.
42 bool allow_init_hoist_ = true;
43 // whether to consider ProducerIntoConsumer fusions. Those can now be handled by the LoopFusionByAccessWorker
44 bool allow_prod_into_cons_;
45
47 std::vector<passes::loop_fusion::FusionRegCandidate> fusion_candidates_;
48
49 // Resolved locations populated during can_be_applied()
50 std::vector<structured_control_flow::StructuredLoop*> producer_loops_;
51 structured_control_flow::Sequence* producer_body_ = nullptr;
52 structured_control_flow::Block* producer_block_ = nullptr;
53
54 std::vector<structured_control_flow::StructuredLoop*> consumer_loops_;
55 structured_control_flow::Sequence* consumer_body_ = nullptr;
56
57 // Case 2 (init-into-reduction): when true, the producer is hoisted to the
58 // reduction's outer parallel band (before the innermost sequential loop) and
59 // keeps writing the accumulator array, instead of being scalarized and inlined
60 // element-by-element inside the reduction loop (Case 1).
61 bool init_hoist_ = false;
62 // The outer parallel-band body that hosts the hoisted init (Case 2 only).
63 structured_control_flow::Sequence* hoist_body_ = nullptr;
64
73 bool find_write_location(
75 const std::string& container,
76 std::vector<structured_control_flow::StructuredLoop*>& loops,
79 );
80
89 bool find_read_location(
91 const std::string& container,
92 std::vector<structured_control_flow::StructuredLoop*>& loops,
94 );
95
96public:
108 bool require_consecutive = true,
109 bool allow_init_hoist = true,
110 bool allow_prod_into_cons = true
111 );
112
114
119 virtual std::string name() const override;
120
128 virtual bool
130
140 virtual void apply(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) override;
141
146 virtual void to_json(nlohmann::json& j) const override;
147
155};
156
158 friend MapFusion;
159
160 std::unordered_map<std::string, const data_flow::Subset*>& target_containers_;
161 std::unordered_map<std::string, std::vector<data_flow::Subset>> unique_subsets_per_container_;
162
163protected:
164 bool abort() {
165 return true;
166 }
167
168public:
169 FusionConsumerSubsetVisitor(std::unordered_map<std::string, const data_flow::Subset*>& target_containers);
170
172
174
175 bool visit(IfElse& node) override;
176
177 const std::unordered_map<std::string, std::vector<data_flow::Subset>>& unique_subsets_per_container();
178};
179
181 friend MapFusion;
182
184 const std::vector<passes::loop_fusion::FusionRegCandidate>& fusion_candidates_;
185 const std::vector<std::string>& candidate_temps_;
186
187public:
190 const std::vector<passes::loop_fusion::FusionRegCandidate>& fusion_candidates,
191 const std::vector<std::string>& candidate_temps
192 );
193
194 bool dispatch_partial_sequence(Sequence& node, size_t first, size_t end);
195
197
199
200 bool visit(IfElse& node) override;
201};
202
203} // namespace transformations
204} // namespace sdfg
Symbol assumptions for reasoning about bounds, constness, and evolution.
Definition analysis.h:53
Note: Even though the class references unique_ptr, it will never delete an SDFG it has a reference to...
Definition structured_sdfg_builder.h:44
FusionDirection
Definition loop_fusion_by_accesses.h:15
A control flow node representing a basic block with dataflow computations.
Definition block.h:42
Represents a conditional if-else control flow node with multiple cases.
Definition if_else.h:47
Represents a parallel map loop with configurable scheduling.
Definition map.h:47
A sequential container of control flow nodes.
Definition sequence.h:52
Base class for structured loop constructs.
Definition structured_loop.h:244
bool abort()
Definition map_fusion.h:164
FusionConsumerSubsetVisitor(std::unordered_map< std::string, const data_flow::Subset * > &target_containers)
bool visit(sdfg::structured_control_flow::Block &block) override
bool visit(sdfg::structured_control_flow::Sequence &node) override
const std::unordered_map< std::string, std::vector< data_flow::Subset > > & unique_subsets_per_container()
FusionConsumerUpdateVisitor(builder::StructuredSDFGBuilder &builder, const std::vector< passes::loop_fusion::FusionRegCandidate > &fusion_candidates, const std::vector< std::string > &candidate_temps)
bool dispatch_partial_sequence(Sequence &node, size_t first, size_t end)
bool visit(sdfg::structured_control_flow::Block &block) override
bool visit(sdfg::structured_control_flow::Sequence &node) override
friend class FusionConsumerUpdateVisitor
Definition map_fusion.h:33
virtual void to_json(nlohmann::json &j) const override
Serialize this transformation to JSON.
MapFusion(structured_control_flow::Map &first_map, structured_control_flow::StructuredLoop &second_loop, bool require_consecutive=true, bool allow_init_hoist=true, bool allow_prod_into_cons=true)
Construct a map fusion transformation.
virtual bool can_be_applied(builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
Check if this transformation can be applied.
static MapFusion from_json(builder::StructuredSDFGBuilder &builder, const nlohmann::json &j)
Deserialize a map fusion transformation from JSON.
virtual std::string name() const override
Get the name of this transformation.
passes::loop_fusion::LoopFusionByAccessWorker::FusionDirection last_fusion_direction() const
virtual void apply(builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
Apply the map fusion transformation.
Base class for all SDFG transformations.
Definition transformation.h:25
Visitor for Structured SDFG (not a builder).
Definition structured_sdfg_visitor.h:71
Definition function_builder.h:10
Definition loop_parallelization.h:8
Definition analysis.h:7