docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
reduce.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <vector>
6
11
12namespace sdfg {
13
14namespace builder {
16}
18
29enum class ReductionOperation { Add, Mul, Min, Max };
30
35
41
45enum class RescaleBase { E, Two };
46
48
52RescaleBase rescale_base_from_string(const std::string& value);
53
75 std::string container;
77 // Anchor (`Max`) container this `Add` is relative to; empty for a plain reduction.
78 std::string rescale = "";
80};
81
106class Reduce : public StructuredLoop {
108
109private:
110 std::vector<ReductionInfo> reductions_;
111
112 Reduce(
113 size_t element_id,
114 const DebugInfo& debug_info,
115 ControlFlowNode* parent,
120 std::vector<ReductionInfo> reductions,
122 );
123
124 static constexpr size_t REQUIRED_ELEMENT_IDS = StructuredLoop::REQUIRED_ELEMENT_IDS;
125
126public:
127 Reduce(const Reduce& node) = delete;
128 Reduce& operator=(const Reduce&) = delete;
129
130 ElementType type_id() const override {
131 return ElementType::Reduce;
132 }
133
134 static bool classof(const Element& element) {
135 return element.type_id() == ElementType::Reduce;
136 }
137
139
140 void validate(const Function& function) const override;
141
142 void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override;
143
144 void replace(const symbolic::ExpressionMapping& replacements) override;
145
152 const std::vector<ReductionInfo>& reductions() const;
153
161 void replace_reduction_container(const std::string& old_name, const std::string& new_name);
162
163 void original_index(const std::string& container, symbolic::Expression index);
164};
165
166} // namespace structured_control_flow
167} // namespace sdfg
Definition element.h:30
Element(size_t element_id, const DebugInfo &debug_info)
size_t element_id() const
const DebugInfo & debug_info() const
virtual ElementType type_id() const =0
Returns the type of the element.
Definition function.h:43
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
Base class for all structured control flow nodes in a StructuredSDFG.
Definition control_flow_node.h:44
void original_index(const std::string &container, symbolic::Expression index)
void replace_reduction_container(const std::string &old_name, const std::string &new_name)
Retarget any reduction whose accumulator is old_name to new_name.
void validate(const Function &function) const override
Validates the element.
Reduce(const Reduce &node)=delete
void replace(const symbolic::ExpressionMapping &replacements) override
Reduce & operator=(const Reduce &)=delete
static bool classof(const Element &element)
Definition reduce.h:134
bool accept(visitor::ActualStructuredSDFGVisitor &visitor) override
const std::vector< ReductionInfo > & reductions() const
Get the reductions carried by this loop.
void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override
ElementType type_id() const override
Returns the type of the element.
Definition reduce.h:130
Represents a schedule type for Map nodes.
Definition structured_loop.h:31
const symbolic::Expression update() const
Get the update expression for the induction variable.
const symbolic::Symbol indvar() const
Get the induction variable (loop counter) symbol.
const ScheduleType & schedule_type() const
Get the scheduling strategy for this Map.
const symbolic::Expression init() const
Get the initialization expression for the induction variable.
static constexpr size_t REQUIRED_ELEMENT_IDS
Definition structured_loop.h:281
StructuredLoop(size_t element_id, const DebugInfo &debug_info, ControlFlowNode *parent, symbolic::Symbol indvar, symbolic::Expression init, symbolic::Expression update, symbolic::Condition condition, const ScheduleType &schedule_type=ScheduleType_Sequential::create())
const symbolic::Condition condition() const
Get the loop continuation condition.
Visitor for Structured SDFG (not a builder).
Definition structured_sdfg_visitor.h:71
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
SymEngine::map_basic_basic ExpressionMapping
Definition symbolic.h:109
Definition function_builder.h:10
Definition language_extension.h:18
RescaleBase
Exponential base of a rescaled reduction (see ReductionInfo::rescale).
Definition reduce.h:45
ReductionOperation
Associative and commutative reduction operators.
Definition reduce.h:29
std::string reduction_operation_to_string(ReductionOperation op)
Serialize a reduction operator to its canonical string identifier.
ReductionOperation reduction_operation_from_string(const std::string &value)
Parse a reduction operator from its canonical string identifier.
RescaleBase rescale_base_from_string(const std::string &value)
std::string rescale_base_to_string(RescaleBase base)
Definition control_flow_node.h:16
Definition analysis.h:7
ElementType
Definition element.h:72
@ Reduce
Definition element.h:90
A single reduction carried by a Reduce loop.
Definition reduce.h:73
RescaleBase rescale_base
Definition reduce.h:79
std::string rescale
Definition reduce.h:78
std::string container
Definition reduce.h:75
symbolic::Expression original_index
Definition reduce.h:76
ReductionOperation operation
Definition reduce.h:74
Symbolic system for integer-based symbol analysis.