docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
elementwise_node.h
Go to the documentation of this file.
1
56
57#pragma once
58
60
64
65namespace sdfg {
66
67namespace math {
68namespace tensor {
69
80protected:
82 std::vector<symbolic::Expression> shape_;
83
84public:
95
97 size_t element_id,
98 const DebugInfo& debug_info,
102 const std::vector<symbolic::Expression>& shape,
103 const std::string& modified_tensor_conn,
104 const std::vector<std::string>& tensor_inputs,
107 );
108
109 static std::vector<std::string>
110 build_input_conns(const std::string& modified_tensor_conn, const std::vector<std::string>& inputs);
111
120 virtual int tensor_input_count() const {
121 return inputs_.size();
122 }
123
132 virtual int mandatory_input_count() const {
133 return inputs_.size();
134 }
135
137 return quantization(get_parent());
138 }
139
144
149 std::optional<QuantizationType> uniform_quantization(const data_flow::DataFlowGraph& dataflow) const;
150
156
158
160
162
167
168 void validate(const Function& function) const override;
169
174 const std::vector<symbolic::Expression>& shape() const {
175 return shape_;
176 }
177
178 symbolic::SymbolSet symbols() const override;
179
180 void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override;
181
182 void replace(const symbolic::ExpressionMapping& replacements) override;
183
184 static std::pair<structured_control_flow::Sequence*, std::vector<symbolic::Expression>> add_eltwise_scope(
186 const DebugInfo& scope_deb_info,
187 Sequence& parent,
188 const std::vector<symbolic::Expression>& shape
189 );
190
191 static std::unique_ptr<types::IType> access_type(const std::pair<types::PrimitiveType, const TensorLayout*>& pair);
192
193 static bool create_input(
196 const data_flow::AccessNode& org_src,
197 const std::pair<types::PrimitiveType, const TensorLayout*>& src_type,
198 const ElementInput& needed_input,
199 const std::vector<symbolic::Expression>& eltwise_subset,
200 std::unordered_map<const data_flow::AccessNode*, data_flow::AccessNode*>& new_node_mapping
201 );
202
203 static void create_output(
206 const data_flow::AccessNode& org_dst,
207 const types::Tensor& dst_type,
208 const ElementOutput& provided_output,
209 const std::vector<symbolic::Expression>& eltwise_subset
210 );
211
224
226
227protected:
243 std::vector<ElementInput>& needed_inputs,
244 types::PrimitiveType expected_type
245 ) = 0;
246
250 const std::string& prefix,
251 const types::IType& type
252 ) const;
253};
254
256public:
257 nlohmann::json serialize(const data_flow::LibraryNode& library_node) override;
258
259 struct BaseDeser {
260 std::vector<symbolic::Expression> shape;
263 };
264
265 BaseDeser deserialize_base_values(const nlohmann::json& j);
266};
267
268template<typename T>
270public:
273 ) override {
274 // Assertions for required fields
275 auto base = deserialize_base_values(j);
276
277 return static_cast<ElementWiseDataflowTensorNode&>(builder.add_library_node<
278 T>(parent, base.debug_info, base.shape, base.quantization));
279 }
280};
281
282} // namespace tensor
283} // namespace math
284} // namespace sdfg
Dispatchers for dataflow blocks and library nodes.
Definition element.h:30
size_t element_id() const
const DebugInfo & debug_info() const
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
Node representing access to a data container in the dataflow graph.
Definition access_node.h:84
CodeNode(size_t element_id, const DebugInfo &debug_info, const graph::Vertex vertex, DataFlowGraph &parent, const std::vector< std::string > &outputs, const std::vector< std::string > &inputs)
Protected constructor for code nodes.
const std::vector< std::string > & inputs() const
Get input connector names (const).
std::vector< std::string > inputs_
Names of input connectors.
Definition code_node.h:94
Definition data_flow_graph.h:29
graph::Vertex vertex() const
Get the graph vertex for this node.
const DataFlowGraph & get_parent() const
Get the parent dataflow graph (const).
Base class for all library nodes in the dataflow graph.
Definition library_node.h:106
const LibraryNodeCode & code() const
Get the operation code.
nlohmann::json serialize(const data_flow::LibraryNode &library_node) override
Serialize a library node to JSON.
Defined by each element of the output tensor (defined by shape) can be defined independently of any o...
Definition elementwise_node.h:79
void validate_all_input_tensors(const data_flow::DataFlowGraph &graph) const
ElementWiseDataflowTensorNode(size_t element_id, const DebugInfo &debug_info, const graph::Vertex vertex, data_flow::DataFlowGraph &parent, const data_flow::LibraryNodeCode &code, const std::vector< symbolic::Expression > &shape, const std::string &modified_tensor_conn, const std::vector< std::string > &tensor_inputs, QuantizationType quantization=QUANTIZATION_MATCH_INPUTS, const data_flow::ImplementationType &impl_type=data_flow::ImplementationType_NONE)
QuantizationType fixed_quantization_
Definition elementwise_node.h:81
void set_fixed_quantization(const QuantizationType quant)
static bool create_input(builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &block, const data_flow::AccessNode &org_src, const std::pair< types::PrimitiveType, const TensorLayout * > &src_type, const ElementInput &needed_input, const std::vector< symbolic::Expression > &eltwise_subset, std::unordered_map< const data_flow::AccessNode *, data_flow::AccessNode * > &new_node_mapping)
virtual int mandatory_input_count() const
How many inputs, starting with 0 are optional?
Definition elementwise_node.h:132
void validate(const Function &function) const override
Validate the code node's configuration.
static std::pair< structured_control_flow::Sequence *, std::vector< symbolic::Expression > > add_eltwise_scope(builder::StructuredSDFGBuilder &builder, const DebugInfo &scope_deb_info, Sequence &parent, const std::vector< symbolic::Expression > &shape)
virtual int tensor_input_count() const
How many inputs, starting with 0 are full tensors?
Definition elementwise_node.h:120
data_flow::PointerAccessType pointer_access_type(int input_idx) const override
Describes what a pointer is used for.
symbolic::SymbolSet symbols() const override
Get all symbols used in this node.
QuantizationType quantization(const data_flow::DataFlowGraph &dataflow) const
type of the math calculations.
data_flow::AccessNode & create_tmp_access_node(builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &block, const std::string &prefix, const types::IType &type) const
void replace(const symbolic::ExpressionMapping &replacements) override
static void create_output(builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &block, const data_flow::AccessNode &org_dst, const types::Tensor &dst_type, const ElementOutput &provided_output, const std::vector< symbolic::Expression > &eltwise_subset)
void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override
std::optional< QuantizationType > uniform_quantization(const data_flow::DataFlowGraph &dataflow) const
Same result as quantization if it matches all the inputs.
QuantizationType fixed_quantization() const
configuration of the type for the math calculations, independent of current input types etc.
virtual void validate_non_tensor_inputs(const data_flow::DataFlowGraph &graph) const
by default, everything after the tensors is mandated to be scalar.
QuantizationType quantization() const
Definition elementwise_node.h:136
const std::vector< symbolic::Expression > & shape() const
Get the tensor shape.
Definition elementwise_node.h:174
void validate_target_tensor(const data_flow::DataFlowGraph &graph) const
static std::unique_ptr< types::IType > access_type(const std::pair< types::PrimitiveType, const TensorLayout * > &pair)
static std::vector< std::string > build_input_conns(const std::string &modified_tensor_conn, const std::vector< std::string > &inputs)
std::vector< symbolic::Expression > shape_
Logical tensor shape.
Definition elementwise_node.h:82
passes::LibNodeExpander::ExpandOutcome expand(passes::LibNodeExpander::ExpandContext &context, structured_control_flow::Block &block) override
Expand into map with linearized indexing.
virtual ElementOutput expand_operation_dataflow(builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &block, std::vector< ElementInput > &needed_inputs, types::PrimitiveType expected_type)=0
Models the pure dataflow of the operation as applied to each element of the output as a function of t...
data_flow::LibraryNode & deserialize(const nlohmann::json &j, builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &parent) override
Deserialize a library node from JSON.
Definition elementwise_node.h:271
TensorNode(size_t element_id, const DebugInfo &debug_info, const graph::Vertex vertex, data_flow::DataFlowGraph &parent, const data_flow::LibraryNodeCode &code, const std::vector< std::string > &outputs, const std::vector< std::string > &inputs, const data_flow::ImplementationType &impl_type)
Construct a tensor node.
Definition lib_node_expander.h:122
Base class for library node serialization.
Definition json_serializer.h:195
A control flow node representing a basic block with dataflow computations.
Definition block.h:42
A sequential container of control flow nodes.
Definition sequence.h:52
Abstract base interface for all types in the sdfglib type system.
Definition type.h:625
Definition tensor.h:13
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
std::set< Symbol, SymEngine::RCPBasicKeyLess > SymbolSet
Ordered set of symbols.
Definition symbolic.h:95
SymEngine::map_basic_basic ExpressionMapping
Definition symbolic.h:109
Definition function_builder.h:10
StringEnum ImplementationType
Implementation type identifier for library nodes.
Definition library_node.h:75
StringEnum LibraryNodeCode
Definition library_node.h:65
ImplementationType ImplementationType_NONE
Default implementation type indicating no specific implementation.
Definition library_node.h:84
std::unique_ptr< PointerAccessMeta, PtrAccessDeleter > PointerAccessType
Definition pointer_metadata.h:32
Definition graph.h:22
boost::graph_traits< Graph >::vertex_descriptor Vertex
Definition graph.h:25
Definition arange_node.h:8
constexpr QuantizationType QUANTIZATION_MATCH_INPUTS
Definition tensor_node.h:27
types::PrimitiveType QuantizationType
Definition tensor_node.h:26
Definition batched_gemm_node.h:12
PrimitiveType
Enumeration of all primitive data types supported by sdfglib.
Definition type.h:35
@ Void
Void type (0 bits).
Definition type.h:36
Definition analysis.h:7
QuantizationType quantization
Definition elementwise_node.h:261
std::vector< symbolic::Expression > shape
Definition elementwise_node.h:260
types::PrimitiveType required_type
Definition elementwise_node.h:93
CodeNode * consumer
Definition elementwise_node.h:91
types::PrimitiveType type
Definition elementwise_node.h:88
CodeNode * producer
Definition elementwise_node.h:86
Definition lib_node_expander.h:12
Abstract base class for tensor library nodes.