docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
lib_node_expander.h
Go to the documentation of this file.
1#pragma once
3#include "sdfg/options.h"
5
6namespace sdfg::passes {
7
9public:
11
13 bool applied;
15 }
16 };
17 virtual ~LibNodeExpander() = default;
18
28 virtual const LibNodeExpander* for_lib_node(const data_flow::LibraryNode& node) const {
29 return this;
30 }
31
42 return nullptr;
43 }
44
46 public:
47 virtual ~AccessNodeExpand() = default;
48
50
62
63 enum class LoopType { For, Map };
64
66 LoopType type,
67 const symbolic::Symbol indvar,
68 const symbolic::Condition condition,
69 const symbolic::Expression init,
70 const symbolic::Expression update,
71 const ScheduleType& schedule_type
72 ) = 0;
73
104 virtual data_flow::AccessNode&
114
120 };
121
123 public:
124 virtual ~ExpandContext() = default;
125
140 virtual std::unique_ptr<AccessNodeExpand>
141 replacement_requires_access_nodes(const std::vector<InputUse>& access_dirs) = 0;
142
143 // TODO virtual std::unique_ptr<DataflowExpand> replace_dataflow() = 0;
144 // this would be a quicker way, when the expansion only consists of pure dataflow, where base expansion
145 // infrastructure needs to migrate edges from the old node to the new nodes. Describing the new targets of edges
146 // can be taken from `ElementWiseDataflowTensorNode.expand_operation_dataflow()`
147
152
153 virtual ExpandOutcome unable() = 0;
154
156
159 virtual const Options& options() const = 0;
160 };
161
164 ) const = 0;
165};
166
167template<typename T>
169public:
171
172 const LibNodeExpander* for_lib_node(const data_flow::LibraryNode& node) const override {
173 if (auto* cast = dynamic_cast<const T*>(&node)) {
174 return this;
175 }
176 return nullptr;
177 }
178
181
184 ) const override {
185 auto& typed_node = static_cast<T&>(node);
186 return handle_expand(context, block, typed_node);
187 }
188};
189
190template<typename T>
192 const data_flow::LibraryNodeCode code_;
193
194public:
197
200 return code_;
201 }
202
203 const data_flow::LibraryNodeCode* matched_code() const override {
204 return &code_;
205 }
206
207 const LibNodeExpander* for_lib_node(const data_flow::LibraryNode& node) const override {
208 if (node.code() == code_) {
209 return this;
210 }
211 return nullptr;
212 }
213};
214
215} // namespace sdfg::passes
Definition options.h:56
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
Node representing access to a data container in the dataflow graph.
Definition access_node.h:84
Base class for all library nodes in the dataflow graph.
Definition library_node.h:106
const LibraryNodeCode & code() const
Get the operation code.
const data_flow::LibraryNodeCode & code() const
The fixed library node code this expander dispatches on.
Definition lib_node_expander.h:199
const LibNodeExpander * for_lib_node(const data_flow::LibraryNode &node) const override
Prefiltering of libnodes.
Definition lib_node_expander.h:207
CodeLibNodeExpander(const data_flow::LibraryNodeCode &code)
Definition lib_node_expander.h:195
const data_flow::LibraryNodeCode * matched_code() const override
If this expander dispatches on a single, fixed library node code, expose it here.
Definition lib_node_expander.h:203
Definition lib_node_expander.h:45
virtual data_flow::AccessNode & add_indirect_read_access(structured_control_flow::Block &block, size_t input_idx)=0
Creates an access node that represents the input of the original lib-node as accurately as possible,...
virtual structured_control_flow::Sequence & replace_with_sequence()=0
Creates a new sequence where the libNode was.
virtual builder::StructuredSDFGBuilder & builder()=0
virtual data_flow::AccessNode & add_output_access(structured_control_flow::Block &block, size_t output_idx)=0
Creates an access node that represents the output of the original lib-node as accurately as possible,...
virtual data_flow::AccessNode & add_scalar_input_access(structured_control_flow::Block &block, size_t input_idx)=0
Creates an access node that represents the input of the original lib-node as accurately as possible,...
LoopType
Definition lib_node_expander.h:63
virtual data_flow::AccessNode & add_indirect_write_access(structured_control_flow::Block &block, size_t input_idx)=0
Creates an access node that represents the input of the original lib-node as accurately as possible,...
virtual ExpandOutcome successfully_expanded()=0
The expansion is now complete.
virtual structured_control_flow::StructuredLoop & replace_with_structured_loop(LoopType type, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const ScheduleType &schedule_type)=0
Definition lib_node_expander.h:122
virtual ExpandOutcome successfully_modified_node_only()=0
Only properties of the node under expansion had to be changed, no change to the dataflow were necessa...
virtual std::unique_ptr< AccessNodeExpand > replacement_requires_access_nodes(const std::vector< InputUse > &access_dirs)=0
start expansion with access nodes.
virtual const Options & options() const =0
Compile options for this run, so expanders can select variants (e.g.
Definition lib_node_expander.h:8
virtual ~LibNodeExpander()=default
InputUse
Definition lib_node_expander.h:10
@ IndirectWrite
Definition lib_node_expander.h:10
@ IndirectRead
Definition lib_node_expander.h:10
@ Skip
Definition lib_node_expander.h:10
@ IndirectReadWrite
Definition lib_node_expander.h:10
@ Scalar
Definition lib_node_expander.h:10
virtual const LibNodeExpander * for_lib_node(const data_flow::LibraryNode &node) const
Prefiltering of libnodes.
Definition lib_node_expander.h:28
virtual ExpandOutcome handle_expand(ExpandContext &context, structured_control_flow::Block &block, data_flow::LibraryNode &node) const =0
virtual const data_flow::LibraryNodeCode * matched_code() const
If this expander dispatches on a single, fixed library node code, expose it here.
Definition lib_node_expander.h:41
Definition lib_node_expander.h:168
virtual LibNodeExpander::ExpandOutcome handle_expand(LibNodeExpander::ExpandContext &context, structured_control_flow::Block &block, T &node) const =0
LibNodeExpander::ExpandOutcome handle_expand(LibNodeExpander::ExpandContext &context, structured_control_flow::Block &block, data_flow::LibraryNode &node) const override
Definition lib_node_expander.h:182
const LibNodeExpander * for_lib_node(const data_flow::LibraryNode &node) const override
Prefiltering of libnodes.
Definition lib_node_expander.h:172
A control flow node representing a basic block with dataflow computations.
Definition block.h:42
Represents a traditional for-loop with sequential execution.
Definition for.h:43
Represents a parallel map loop with configurable scheduling.
Definition map.h:47
Represents a schedule type for Map nodes.
Definition structured_loop.h:31
A sequential container of control flow nodes.
Definition sequence.h:52
Base class for structured loop constructs.
Definition structured_loop.h:244
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
SymEngine::RCP< const SymEngine::Symbol > Symbol
Reference-counted pointer to a SymEngine Symbol.
Definition symbolic.h:71
SymEngine::RCP< const SymEngine::Boolean > Condition
Reference-counted pointer to a boolean condition expression.
Definition symbolic.h:86
StringEnum LibraryNodeCode
Definition library_node.h:65
Definition approximate_math.h:12
Definition lib_node_expander.h:12
ExpandOutcome(bool applied)
Definition lib_node_expander.h:14
bool applied
Definition lib_node_expander.h:13