7#include <unordered_map>
8#include <unordered_set>
65 const std::vector<EinsumIndexContribution>& ordered_contributions,
66 const std::vector<symbolic::Expression>& shape
93 std::vector<OperandContribution>
inputs;
113 return edge->subset();
116 return edge->base_type();
135 return edge->base_type();
157 std::vector<EinsumDimension>
dims;
170 std::unordered_map<std::string, data_flow::DataFlowNode*>
input_nodes;
179 std::pair<data_flow::AccessNode*, const data_flow::Subset&>
get_input_for(
size_t input_idx);
273 const std::vector<std::unique_ptr<EinsumCluster>>&
einsums()
const {
Access nodes for reading/writing data in the dataflow graph.
Node representing access to a data container in the dataflow graph.
Definition access_node.h:84
Edge in the dataflow graph representing data movement.
Definition memlet.h:131
Simple computational operation in the dataflow graph.
Definition tasklet.h:348
Non-destructive counterpart of an EinsumNode.
Definition einsum_detection.h:150
std::pair< data_flow::AccessNode *, const data_flow::Subset & > get_input_for(size_t input_idx)
std::vector< EinsumDimension > dims
Definition einsum_detection.h:157
std::vector< std::unique_ptr< EinsumEdge > > in_edges
Definition einsum_detection.h:158
std::list< structured_control_flow::StructuredLoop * > consumed_loops
Surrounding loops folded into this cluster as reduction/free dimensions. From outermost to innermost.
Definition einsum_detection.h:177
bool subtraction
True if the core reduction was a subtraction (carries an implicit -1 factor).
Definition einsum_detection.h:172
const std::vector< EinsumIndexing > & get_input_indexings() const
std::string toStr() const
std::unordered_map< std::string, data_flow::DataFlowNode * > input_nodes
Source node for each input connector (may be null for synthetic constants).
Definition einsum_detection.h:170
symbolic::Expression get_linearized_outer_offset(int input_idx) const
data_flow::AccessNode * output_node
Definition einsum_detection.h:168
const data_flow::Subset & out_indices() const
std::vector< std::string > inputs
Definition einsum_detection.h:159
std::list< data_flow::DataFlowNode * > consumed_nodes
Dataflow nodes folded into this cluster (reduction tasklet, mul tasklets, ...).
Definition einsum_detection.h:175
const EinsumIndexing & get_output_indexing() const
structured_control_flow::Block * block
Block that holds the reduction core of this cluster.
Definition einsum_detection.h:153
EinsumIndexing einsum_out_indices
Inner-index mapping of the output operand.
Definition einsum_detection.h:164
const data_flow::Subset & get_input_subset(size_t input_idx) const
std::unique_ptr< EinsumEdge > output_edge
Reduction/output access node of the cluster.
Definition einsum_detection.h:167
std::vector< EinsumIndexing > einsum_in_indices
Inner-index mapping per input operand (parallel to in_indices/inputs).
Definition einsum_detection.h:162
void apply_promote(EinsumCluster &cluster, structured_control_flow::StructuredLoop &loop, const PromotionCheck &check)
bool try_to_consume_loop(EinsumCluster &einsum, structured_control_flow::StructuredLoop &loop)
If there is a cluster representing the full contents of the loop, try to have it consume this loop.
bool visit(structured_control_flow::AssignmentBlock &node) override
EinsumCluster * from_einsum_node(structured_control_flow::Block &block, EinsumNode &einsum_node)
Mirror an already existing EinsumNode into a cluster.
void filter_for_coverage()
void consume_input_operations(BlockState &state)
for all the clusters of the block last scanned into BlockState, try to consume all the input operatio...
static bool subsets_eq(const data_flow::Subset &subset1, const data_flow::Subset &subset2)
size_t run(structured_control_flow::ControlFlowNode &start)
Run detection starting from the given control flow node.
void register_cluster_in_scope(EinsumCluster *cluster)
bool visit(structured_control_flow::Block &node) override
static bool try_extend(BlockState &state, EinsumCluster &cluster)
Try to fold a multiplication feeding an input into the cluster. Returns true if applied.
bool visit(structured_control_flow::While &node) override
bool block_fully_consumed(BlockState &state, structured_control_flow::Block &block)
std::vector< std::unique_ptr< EinsumCluster > > all_einsums_
all that have been found
Definition einsum_detection.h:219
static bool subset_contains_symbol(const data_flow::Subset &subset, const symbolic::Symbol &symbol)
std::vector< LoopScopeState > loop_stack_
those that are relevant to the current scope.
Definition einsum_detection.h:221
EinsumCluster * try_lift(structured_control_flow::Block &block, data_flow::Tasklet &tasklet)
Try to lift a reduction tasklet into a fresh einsum cluster core.
const std::vector< std::unique_ptr< EinsumCluster > > & einsums() const
All einsum clusters found during the last run.
Definition einsum_detection.h:273
static symbolic::Expression cnf_to_upper_bound(const symbolic::CNF &cnf, const symbolic::Symbol indvar)
PromotionCheck can_promote(EinsumCluster &cluster, structured_control_flow::StructuredLoop &loop)
Verify the loop can be folded and return the new dimension's per-operand contributions.
EinsumCluster & new_cluster(structured_control_flow::Block &block)
bool visit(structured_control_flow::IfElse &node) override
void recompute_einsum_indices(EinsumCluster &cluster)
Recompute the per-operand inner-index mappings from the current dims and subsets.
EinsumDetection()=default
void find_einsum_core_ops(BlockState &state, structured_control_flow::Block &block)
Loop for operations (reductions) that can form the core of einsum clusters.
bool visit(structured_control_flow::Return &node) override
bool handleStructuredLoop(structured_control_flow::StructuredLoop &loop) override
const data_flow::Subset & subset() const override
Definition einsum_detection.h:112
data_flow::Memlet * original_edge() const override
Definition einsum_detection.h:118
EinsumEdgeOriginal(data_flow::Memlet *edge)
Definition einsum_detection.h:109
const types::IType & base_type() const override
Definition einsum_detection.h:115
EinsumEdgeVirtual(const data_flow::Memlet *edge, const data_flow::Subset &subset)
Definition einsum_detection.h:128
const data_flow::Subset & subset() const override
Definition einsum_detection.h:131
const types::IType & base_type() const override
Definition einsum_detection.h:134
data_flow::Memlet * original_edge() const override
Definition einsum_detection.h:137
Definition einsum_detection.h:96
virtual const types::IType & base_type() const =0
virtual data_flow::Memlet * original_edge() const =0
virtual ~EinsumEdge()=default
virtual const data_flow::Subset & subset() const =0
Definition einsum_node.h:34
A control flow node representing a basic block with dataflow computations.
Definition block.h:42
Base class for all structured control flow nodes in a StructuredSDFG.
Definition control_flow_node.h:44
Represents a conditional if-else control flow node with multiple cases.
Definition if_else.h:47
Represents a return statement that exits the function with a value.
Definition return.h:32
Base class for structured loop constructs.
Definition structured_loop.h:244
Represents a while-loop with condition-controlled iteration.
Definition while.h:37
Abstract base interface for all types in the sdfglib type system.
Definition type.h:625
Visitor for Structured SDFG (not a builder).
Definition structured_sdfg_visitor.h:71
bool visit(sdfg::structured_control_flow::ControlFlowNode &node)
Base class for all nodes in the dataflow graph.
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
Edges in the dataflow graph representing data movement.
symbolic::MultiExpression Subset
Type alias for a subset specification (array of symbolic expressions).
Definition memlet.h:103
std::vector< std::vector< Condition > > CNF
Conjunctive Normal Form representation.
Definition conjunctive_normal_form.h:73
Definition einsum_detection.h:206
std::list< EinsumCluster * > clusters
Definition einsum_detection.h:208
std::unordered_set< data_flow::DataFlowNode * > consumed_nodes
Definition einsum_detection.h:207
Definition einsum_detection.h:210
EinsumCluster * representing_last_block_
Definition einsum_detection.h:214
bool non_reducible
found more than a single block in this scope, or sth.
Definition einsum_detection.h:213
A single einsum dimension's contribution to one operand's access subset.
Definition einsum_detection.h:31
int64_t factor
Integer coefficient of the indvar within that index expression.
Definition einsum_detection.h:37
symbolic::Symbol indvar
Induction variable of the contributing dimension.
Definition einsum_detection.h:33
symbolic::Expression factor_expr() const
size_t index
Index position within the original subset that this dimension contributes to.
Definition einsum_detection.h:35
How the consumed einsum dimensions map onto one operand's access subset.
Definition einsum_detection.h:50
std::vector< EinsumIndexContribution > contributions
Contributions of individual dimensions to this operand's index positions.
Definition einsum_detection.h:52
std::vector< symbolic::Expression > get_strides(const std::vector< EinsumIndexContribution > &ordered_contributions, const std::vector< symbolic::Expression > &shape) const
Compute all strides for shape, given this indexing's contributions reordered so that ordered_contribu...
size_t covered
Number of innermost original index positions fully covered by the dimensions.
Definition einsum_detection.h:54
A single consumed dimension's contribution to one operand, found during promotion.
Definition einsum_detection.h:75
int64_t factor
Integer coefficient of the indvar in that index expression.
Definition einsum_detection.h:80
size_t index
Index position within the operand's subset it contributes to.
Definition einsum_detection.h:78
bool contributes
Definition einsum_detection.h:76
Symbolic system for integer-based symbol analysis.
Simple computational operations in the dataflow graph.