docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
loop_fusion_by_accesses.h
Go to the documentation of this file.
1#pragma once
2
10
12
14public:
20
21protected:
22 bool allow_init_hoist_ = true;
23
24 LoopFusionByAccessWorker(bool allow_init_hoist = true) : allow_init_hoist_(allow_init_hoist) {
25 }
26
27 struct Plan {
30
32 std::vector<structured_control_flow::StructuredLoop*> producer_loops_;
36 std::vector<structured_control_flow::StructuredLoop*> consumer_loops_;
39 std::vector<FusionRegCandidate> fusion_candidates_;
40
44
45 // Case 2 (init-into-reduction): when true, the producer is hoisted to the
46 // reduction's outer parallel band (before the innermost sequential loop) and
47 // keeps writing the accumulator array, instead of being scalarized and inlined
48 // element-by-element inside the reduction loop (Case 1).
49 bool init_hoist_ = false;
51
53
54 // The outer parallel-band body that hosts the hoisted init (Case 2 only).
56 // The loops being fused match domains exactly, so we can remove the original loop, if we do
57 bool domains_match = false;
58
59 // Number of redundant writes copied into the target loop (that could technically by avoided)
61 };
62
63 virtual ~LoopFusionByAccessWorker() = default;
64
66
68
70
78 const Plan& plan, FusionLoopCandidate* first_current, FusionLoopCandidate* second_current
79 ) = 0;
80
81public:
82 static std::vector<std::pair<symbolic::Symbol, symbolic::Expression>> solve_subsets(
83 const data_flow::Subset& producer_subset,
84 const data_flow::Subset& consumer_subset,
85 const std::vector<structured_control_flow::StructuredLoop*>& producer_loops,
86 const std::vector<structured_control_flow::StructuredLoop*>& consumer_loops,
87 const symbolic::Assumptions& producer_assumptions,
88 const symbolic::Assumptions& consumer_assumptions,
89 bool invert_range_check = false
90 );
91
92protected:
93 struct FusionRegs {
94 std::unordered_set<RegId> fusion_regs;
95 std::unordered_set<RegId> second_outputs;
98 };
99
101
102
107 std::vector<structured_control_flow::StructuredLoop*>
109
110 std::vector<structured_control_flow::StructuredLoop*>
112
113public:
114 std::unique_ptr<Plan> try_create_fusion_by_access_plan(
115 FusionLoopCandidate& first, FusionLoopCandidate& second, bool domains_match = false
116 );
117
119
120protected:
123
124public:
126};
127
128
129} // namespace sdfg::passes::loop_fusion
Symbol assumptions for reasoning about bounds, constness, and evolution.
Definition loop_analysis.h:97
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
static std::vector< std::pair< symbolic::Symbol, symbolic::Expression > > solve_subsets(const data_flow::Subset &producer_subset, const data_flow::Subset &consumer_subset, const std::vector< structured_control_flow::StructuredLoop * > &producer_loops, const std::vector< structured_control_flow::StructuredLoop * > &consumer_loops, const symbolic::Assumptions &producer_assumptions, const symbolic::Assumptions &consumer_assumptions, bool invert_range_check=false)
FusionRegs find_fusion_regs(const FusionLoopCandidate &first, const FusionLoopCandidate &second)
virtual FusionLoopCandidate * get_fuse_candidate(structured_control_flow::StructuredLoop &loop)=0
LoopFusionByAccessWorker(bool allow_init_hoist=true)
Definition loop_fusion_by_accesses.h:24
virtual ComplexFusionResult apply_consumer_into_producer(Plan &plan)
FusionDirection
Definition loop_fusion_by_accesses.h:15
@ ProducerIntoConsumer
Definition loop_fusion_by_accesses.h:17
@ ConsumerIntoProducer
Definition loop_fusion_by_accesses.h:18
virtual analysis::LoopAnalysis & get_loop_analysis()=0
virtual void update_copied_leaf_contents_from_first_to_second(const Plan &plan, FusionLoopCandidate *first_current, FusionLoopCandidate *second_current)=0
Moved non-loop contents from first_current to second_current.
std::unique_ptr< Plan > try_create_fusion_by_access_plan(FusionLoopCandidate &first, FusionLoopCandidate &second, bool domains_match=false)
ComplexFusionResult apply_fusion_by_access_plan(std::unique_ptr< Plan > plan)
ComplexFusionResult try_fuse_by_access(FusionLoopCandidate &first, FusionLoopCandidate &second, bool domains_match)
virtual builder::StructuredSDFGBuilder & builder()=0
std::vector< structured_control_flow::StructuredLoop * > collect_structured_sub_tree(structured_control_flow::StructuredLoop &top)
Returns a vector of loops from top to its innermost StructuredLoop, assuming they are all perfectly n...
bool allow_init_hoist_
Definition loop_fusion_by_accesses.h:22
virtual ComplexFusionResult apply_producer_into_consumer(Plan &plan)
std::vector< structured_control_flow::StructuredLoop * > collect_loop_parents(structured_control_flow::Sequence *sequence, structured_control_flow::StructuredLoop *loop)
A control flow node representing a basic block with dataflow computations.
Definition block.h:42
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
Map from symbols to their assumptions.
Definition assumptions.h:313
symbolic::MultiExpression Subset
Type alias for a subset specification (array of symbolic expressions).
Definition memlet.h:103
Definition fusion_types.h:7
Represents pre-cached data for 1 Loop that fullfills the prerequisits for fusing with another candida...
Definition fusion_types.h:90
std::unordered_set< RegId > fusion_regs
Definition loop_fusion_by_accesses.h:94
bool conflicts
Definition loop_fusion_by_accesses.h:96
std::unordered_set< RegId > second_outputs
Definition loop_fusion_by_accesses.h:95
int64_t copied_redundant_writes
Definition loop_fusion_by_accesses.h:97
Definition loop_fusion_by_accesses.h:27
int64_t copied_redundant_writes
Definition loop_fusion_by_accesses.h:60
bool init_hoist_
Definition loop_fusion_by_accesses.h:49
structured_control_flow::Sequence * hoist_body_
Definition loop_fusion_by_accesses.h:55
std::vector< structured_control_flow::StructuredLoop * > consumer_loops_
Definition loop_fusion_by_accesses.h:36
structured_control_flow::Sequence & consumer_target_sequence() const
std::vector< FusionRegCandidate > fusion_candidates_
Definition loop_fusion_by_accesses.h:39
std::vector< structured_control_flow::StructuredLoop * > producer_loops_
Definition loop_fusion_by_accesses.h:32
structured_control_flow::Block * producer_block_
Definition loop_fusion_by_accesses.h:34
FusionDirection direction_
Definition loop_fusion_by_accesses.h:31
structured_control_flow::StructuredLoop * consumer_target_loop() const
structured_control_flow::StructuredLoop & second
Definition loop_fusion_by_accesses.h:29
structured_control_flow::Sequence * producer_body_
Definition loop_fusion_by_accesses.h:33
Plan(structured_control_flow::Map &first, structured_control_flow::StructuredLoop &second)
Definition loop_fusion_by_accesses.h:41
bool domains_match
Definition loop_fusion_by_accesses.h:57
structured_control_flow::Sequence * consumer_body_
Definition loop_fusion_by_accesses.h:37
FusionLoopCandidate * consumer_fusion_candidate_
Definition loop_fusion_by_accesses.h:38
FusionLoopCandidate * producer_fusion_candidate_
Definition loop_fusion_by_accesses.h:35
structured_control_flow::Map & first
Definition loop_fusion_by_accesses.h:28