docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
sdfg::math::tensor::ElementWiseDataflowTensorNode Class Referenceabstract

Defined by each element of the output tensor (defined by shape) can be defined independently of any other output. More...

#include <sdfg/data_flow/library_nodes/math/tensor/elementwise_node.h>

Inheritance diagram for sdfg::math::tensor::ElementWiseDataflowTensorNode:
[legend]

Classes

struct  ElementOutput
struct  ElementInput

Public Member Functions

 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)
virtual int tensor_input_count () const
 How many inputs, starting with 0 are full tensors?
virtual int mandatory_input_count () const
 How many inputs, starting with 0 are optional?
QuantizationType quantization () const
QuantizationType quantization (const data_flow::DataFlowGraph &dataflow) const
 type of the math calculations.
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.
void set_fixed_quantization (const QuantizationType quant)
void validate_target_tensor (const data_flow::DataFlowGraph &graph) const
void validate_all_input_tensors (const data_flow::DataFlowGraph &graph) const
virtual void validate_non_tensor_inputs (const data_flow::DataFlowGraph &graph) const
 by default, everything after the tensors is mandated to be scalar.
void validate (const Function &function) const override
 Validate the code node's configuration.
const std::vector< symbolic::Expression > & shape () const
 Get the tensor shape.
symbolic::SymbolSet symbols () const override
 Get all symbols used in this node.
void replace (const symbolic::Expression old_expression, const symbolic::Expression new_expression) override
void replace (const symbolic::ExpressionMapping &replacements) override
passes::LibNodeExpander::ExpandOutcome expand (passes::LibNodeExpander::ExpandContext &context, structured_control_flow::Block &block) override
 Expand into map with linearized indexing.
data_flow::PointerAccessType pointer_access_type (int input_idx) const override
 Describes what a pointer is used for.
Public Member Functions inherited from sdfg::math::tensor::TensorNode
 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.
virtual void verify_data_types (const data_flow::DataFlowGraph &graph) const
 Called as part of validate.
void validate (const Function &function) const override
 Validate tensor node constraints.
types::PrimitiveType primitive_type (const data_flow::DataFlowGraph &graph) const
 Get the primitive type of this tensor operation.
virtual bool supports_integer_types () const =0
 Check if this operation supports integer types.
Public Member Functions inherited from sdfg::math::MathNode
 MathNode (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 &implementation_type, bool side_effects=false)
 Construct a mathematical library node.
Public Member Functions inherited from sdfg::data_flow::LibraryNode
 LibraryNode (const LibraryNode &data_node)=delete
LibraryNode & operator= (const LibraryNode &)=delete
virtual ~LibraryNode ()=default
ElementType type_id () const override
 Returns the type of the element.
const LibraryNodeCode & code () const
 Get the operation code.
const ImplementationType & implementation_type () const
 Get the implementation type (const).
ImplementationType & implementation_type ()
 Get the implementation type (mutable).
void set_implementation_type (const ImplementationType &impl_type)
bool side_effect () const override
 Check if this node has side effects.
virtual std::string toStr () const
 Convert node to string representation.
virtual symbolic::Expression flop () const
 Calculate floating point operations for this node.
PointerAccessType pointer_access_type (const Memlet &edge) const
virtual bool relocalize_operand (int input_idx, const math::tensor::TensorLayout &packed)
 Repoint the operand at input_idx to a locally staged buffer.
virtual bool can_relocalize_operand (int input_idx, const math::tensor::TensorLayout &packed) const
 Side-effect-free predicate mirroring relocalize_operand: whether the operand at input_idx can be repointed at the buffer view packed.
virtual std::optional< SubgroupAccess > operand_access (int input_idx, unsigned subgroup_size) const
 The elements one subgroup of subgroup_size lanes reads from the operand at input_idx, if the node declares them.
EdgeRemoveOption can_remove_out_edge (const data_flow::DataFlowGraph &graph, const Memlet *memlet) const override
 Is the edge in question removable, or will this make the node its an output on invalid?
EdgeRemoveOption can_remove_in_edge (const data_flow::DataFlowGraph &graph, const Memlet *memlet) const override
bool pointer_use_creates_side_effects (const DataFlowGraph &dataflow, const Function &func)
Public Member Functions inherited from sdfg::data_flow::CodeNode
 CodeNode (const CodeNode &data_node)=delete
CodeNode & operator= (const CodeNode &)=delete
const std::vector< std::string > & outputs () const
 Get output connector names (const).
const std::vector< std::string > & inputs () const
 Get input connector names (const).
std::vector< std::string > & outputs ()
 Get output connector names (mutable).
std::vector< std::string > & inputs ()
 Get input connector names (mutable).
const std::string & output (size_t index) const
 Get output connector name by index.
const std::string & input (size_t index) const
 Get input connector name by index.
bool has_constant_input (size_t index) const
 Check if an input is connected to a constant node.
Public Member Functions inherited from sdfg::data_flow::DataFlowNode
 DataFlowNode (const DataFlowNode &data_node)=delete
DataFlowNode & operator= (const DataFlowNode &)=delete
graph::Vertex vertex () const
 Get the graph vertex for this node.
const DataFlowGraph & get_parent () const
 Get the parent dataflow graph (const).
DataFlowGraph & get_parent ()
 Get the parent dataflow graph (mutable).
virtual std::unique_ptr< DataFlowNode > clone (size_t element_id, const graph::Vertex vertex, DataFlowGraph &parent) const =0
 Clone this node for graph transformations.
virtual bool update_edge_removed (const std::string &out_conn)
Public Member Functions inherited from sdfg::Element
 Element (size_t element_id, const DebugInfo &debug_info)
virtual ~Element ()=default
size_t element_id () const
const DebugInfo & debug_info () const
void set_debug_info (const DebugInfo &debug_info)
void add_metadata (const std::string &key, const std::string &value)
void remove_metadata (const std::string &key)
const std::string & metadata (const std::string &key) const
const std::string * metadata_if_exists (const std::string &key) const
const std::unordered_map< std::string, std::string > & metadata () const
std::string_view element_type () const
 Returns the type of the element as a human-readable string.

Static Public Member Functions

static std::vector< std::string > build_input_conns (const std::string &modified_tensor_conn, const std::vector< std::string > &inputs)
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)
static std::unique_ptr< types::IType > access_type (const std::pair< types::PrimitiveType, const TensorLayout * > &pair)
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)
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)
Static Public Member Functions inherited from sdfg::data_flow::LibraryNode
static bool classof (const Element &element)
Static Public Member Functions inherited from sdfg::data_flow::CodeNode
static bool classof (const Element &element)
 LLVM-style RTTI predicate: true if element is a CodeNode.
Static Public Member Functions inherited from sdfg::data_flow::DataFlowNode
static bool classof (const Element &element)
 LLVM-style RTTI predicate: true if element is a DataFlowNode.

Protected Member Functions

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 the inputs.
data_flow::AccessNode & create_tmp_access_node (builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &block, const std::string &prefix, const types::IType &type) const
Protected Member Functions inherited from sdfg::math::tensor::TensorNode
void validate_shape_matches (const std::vector< symbolic::Expression > &required_shape, const TensorLayout &layout, const std::string &name) const
Protected Member Functions inherited from sdfg::data_flow::LibraryNode
 LibraryNode (size_t element_id, const DebugInfo &debug_info, const graph::Vertex vertex, DataFlowGraph &parent, const LibraryNodeCode &code, const std::vector< std::string > &outputs, const std::vector< std::string > &inputs, const bool side_effect, const ImplementationType &implementation_type)
 Protected constructor for library nodes.
Protected Member Functions inherited from sdfg::data_flow::CodeNode
 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.
Protected Member Functions inherited from sdfg::data_flow::DataFlowNode
 DataFlowNode (size_t element_id, const DebugInfo &debug_info, const graph::Vertex vertex, DataFlowGraph &parent)
 Protected constructor for dataflow nodes.

Protected Attributes

QuantizationType fixed_quantization_
std::vector< symbolic::Expression > shape_
 Logical tensor shape.
Protected Attributes inherited from sdfg::data_flow::LibraryNode
LibraryNodeCode code_
 Operation identifier (e.g., "GEMM", "Add").
bool side_effect_
 Whether this node has side effects.
ImplementationType implementation_type_
 How to implement this node.
Protected Attributes inherited from sdfg::data_flow::CodeNode
std::vector< std::string > outputs_
 Names of output connectors.
std::vector< std::string > inputs_
 Names of input connectors.
Protected Attributes inherited from sdfg::Element
size_t element_id_
DebugInfo debug_info_
std::unordered_map< std::string, std::string > metadata_

Additional Inherited Members

Static Public Attributes inherited from sdfg::data_flow::CodeNode
static constexpr ElementType TypeGroup = ElementType::Tasklet | ElementType::LibraryNode
 Bitmask of all concrete ElementTypes that are CodeNodes.
Static Public Attributes inherited from sdfg::data_flow::DataFlowNode
static constexpr ElementType TypeGroup
 Bitmask of all concrete ElementTypes that are DataFlowNodes.
Static Protected Member Functions inherited from sdfg::math::tensor::TensorNode
static data_flow::TaskletCode get_integer_minmax_tasklet (types::PrimitiveType prim_type, bool is_max)
 Get the appropriate tasklet code for min/max operations on integers.

Detailed Description

Defined by each element of the output tensor (defined by shape) can be defined independently of any other output.

Inputs may have lower dimensionality then the output, but must never overlap with the output if its not a 1:1 mapping. For now only scalar or output shape is supported.

The inputs are required to be listed as (dest_ptr, [other_inputs...]). input_.at(0) always is the tensor that is written to

Constructor & Destructor Documentation

◆ ElementWiseDataflowTensorNode()

sdfg::math::tensor::ElementWiseDataflowTensorNode::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 )

Member Function Documentation

◆ access_type()

std::unique_ptr< types::IType > sdfg::math::tensor::ElementWiseDataflowTensorNode::access_type ( const std::pair< types::PrimitiveType, const TensorLayout * > & pair)
static

◆ add_eltwise_scope()

std::pair< structured_control_flow::Sequence *, std::vector< symbolic::Expression > > sdfg::math::tensor::ElementWiseDataflowTensorNode::add_eltwise_scope ( builder::StructuredSDFGBuilder & builder,
const DebugInfo & scope_deb_info,
Sequence & parent,
const std::vector< symbolic::Expression > & shape )
static

◆ build_input_conns()

std::vector< std::string > sdfg::math::tensor::ElementWiseDataflowTensorNode::build_input_conns ( const std::string & modified_tensor_conn,
const std::vector< std::string > & inputs )
static

◆ create_input()

bool sdfg::math::tensor::ElementWiseDataflowTensorNode::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 )
static

◆ create_output()

void sdfg::math::tensor::ElementWiseDataflowTensorNode::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 )
static

◆ create_tmp_access_node()

data_flow::AccessNode & sdfg::math::tensor::ElementWiseDataflowTensorNode::create_tmp_access_node ( builder::StructuredSDFGBuilder & builder,
structured_control_flow::Block & block,
const std::string & prefix,
const types::IType & type ) const
protected

◆ expand()

passes::LibNodeExpander::ExpandOutcome sdfg::math::tensor::ElementWiseDataflowTensorNode::expand ( passes::LibNodeExpander::ExpandContext & context,
structured_control_flow::Block & block )
overridevirtual

Expand into map with linearized indexing.

Creates nested maps over each dimension with linearized index computation for accessing the flat input/output arrays.

Parameters
contextway to request isolation of node or add new blocks, loops etc.
blockthe block in which the node is contained
Returns
outcome of expand, created by context

Implements sdfg::math::MathNode.

◆ expand_operation_dataflow()

virtual ElementOutput sdfg::math::tensor::ElementWiseDataflowTensorNode::expand_operation_dataflow ( builder::StructuredSDFGBuilder & builder,
structured_control_flow::Block & block,
std::vector< ElementInput > & needed_inputs,
types::PrimitiveType expected_type )
protectedpure virtual

Models the pure dataflow of the operation as applied to each element of the output as a function of the inputs.

Must fit into a single Dataflow block. All inputs will be single elements. The caller must handle potential broadcasts etc.

Parameters
builder
block
input_typesaccess nodes for the current element of each of the input tensors in their respective order
needed_inputslist of inputs and their targets to connect with which scalar type
expected_type
Returns
(output producer, output-conn index), nullptr for producer to signal abort

Implemented in sdfg::math::tensor::AddNode, sdfg::math::tensor::CastNode, sdfg::math::tensor::CMathTensorNode, sdfg::math::tensor::DivNode, sdfg::math::tensor::ErfNode, sdfg::math::tensor::ExpNode, sdfg::math::tensor::GELUNode, sdfg::math::tensor::LogicalNotNode, sdfg::math::tensor::MaximumNode, sdfg::math::tensor::MinimumNode, sdfg::math::tensor::MulNode, sdfg::math::tensor::PowNode, sdfg::math::tensor::ReLUNode, sdfg::math::tensor::RsqrtNode, sdfg::math::tensor::SigmoidNode, sdfg::math::tensor::SqrtNode, sdfg::math::tensor::SubNode, sdfg::math::tensor::TanhNode, and sdfg::math::tensor::TaskletTensorNode.

◆ fixed_quantization()

QuantizationType sdfg::math::tensor::ElementWiseDataflowTensorNode::fixed_quantization ( ) const

configuration of the type for the math calculations, independent of current input types etc.

'Void' indicates auto-inferring from inputs

◆ mandatory_input_count()

virtual int sdfg::math::tensor::ElementWiseDataflowTensorNode::mandatory_input_count ( ) const
inlinevirtual

How many inputs, starting with 0 are optional?

input0 always has to be present. Further inputs will be stripped out of the available inputs if not connected Override validate_non_tensor_inputs() to match this [expand_operation_dataflow] is given the inputs that exist and expected to handle whatever is valid without errors

◆ pointer_access_type()

data_flow::PointerAccessType sdfg::math::tensor::ElementWiseDataflowTensorNode::pointer_access_type ( int input_idx) const
overridevirtual

Describes what a pointer is used for.

Parameters
input_idxindex of input that is a pointer.
Returns
Invalid if not asked about a pointer input

Reimplemented from sdfg::data_flow::LibraryNode.

◆ quantization() [1/2]

QuantizationType sdfg::math::tensor::ElementWiseDataflowTensorNode::quantization ( ) const
inline

◆ quantization() [2/2]

QuantizationType sdfg::math::tensor::ElementWiseDataflowTensorNode::quantization ( const data_flow::DataFlowGraph & dataflow) const

type of the math calculations.

May be inferred or fixed.

◆ replace() [1/2]

void sdfg::math::tensor::ElementWiseDataflowTensorNode::replace ( const symbolic::Expression old_expression,
const symbolic::Expression new_expression )
overridevirtual

Implements sdfg::Element.

◆ replace() [2/2]

void sdfg::math::tensor::ElementWiseDataflowTensorNode::replace ( const symbolic::ExpressionMapping & replacements)
overridevirtual

Reimplemented from sdfg::Element.

◆ set_fixed_quantization()

void sdfg::math::tensor::ElementWiseDataflowTensorNode::set_fixed_quantization ( const QuantizationType quant)

◆ shape()

const std::vector< symbolic::Expression > & sdfg::math::tensor::ElementWiseDataflowTensorNode::shape ( ) const
inline

Get the tensor shape.

Returns
Logical tensor shape

◆ symbols()

symbolic::SymbolSet sdfg::math::tensor::ElementWiseDataflowTensorNode::symbols ( ) const
overridevirtual

Get all symbols used in this node.

Returns
Set of symbolic expressions used by this node

Implements sdfg::data_flow::LibraryNode.

◆ tensor_input_count()

virtual int sdfg::math::tensor::ElementWiseDataflowTensorNode::tensor_input_count ( ) const
inlinevirtual

How many inputs, starting with 0 are full tensors?

input0 always has to be. Further inputs that are not tensors are by default required to be scalar-only Override validate_non_tensor_inputs() to change this. [expand_operation_dataflow] is given the inputs that exist and expected to handle whatever is valid without errors

Reimplemented in sdfg::math::tensor::FillNode.

◆ uniform_quantization()

std::optional< QuantizationType > sdfg::math::tensor::ElementWiseDataflowTensorNode::uniform_quantization ( const data_flow::DataFlowGraph & dataflow) const

Same result as quantization if it matches all the inputs.

None if its impossible to use the same types for input & output and math

◆ validate()

void sdfg::math::tensor::ElementWiseDataflowTensorNode::validate ( const Function & function) const
overridevirtual

Validate the code node's configuration.

Parameters
functionFunction context for validation

Ensures that:

  • No two access nodes connect to the same data for inputs/outputs

Reimplemented from sdfg::data_flow::CodeNode.

Reimplemented in sdfg::math::tensor::LogicalNotNode, and sdfg::math::tensor::TaskletTensorNode.

◆ validate_all_input_tensors()

void sdfg::math::tensor::ElementWiseDataflowTensorNode::validate_all_input_tensors ( const data_flow::DataFlowGraph & graph) const

◆ validate_non_tensor_inputs()

virtual void sdfg::math::tensor::ElementWiseDataflowTensorNode::validate_non_tensor_inputs ( const data_flow::DataFlowGraph & graph) const
virtual

by default, everything after the tensors is mandated to be scalar.

Override to change this.

Reimplemented in sdfg::math::tensor::FillNode.

◆ validate_target_tensor()

void sdfg::math::tensor::ElementWiseDataflowTensorNode::validate_target_tensor ( const data_flow::DataFlowGraph & graph) const

Member Data Documentation

◆ fixed_quantization_

QuantizationType sdfg::math::tensor::ElementWiseDataflowTensorNode::fixed_quantization_
protected

◆ shape_

std::vector<symbolic::Expression> sdfg::math::tensor::ElementWiseDataflowTensorNode::shape_
protected

Logical tensor shape.


The documentation for this class was generated from the following file: