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

Convolution operation following ONNX Conv operator specification. More...

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

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

Classes

struct  ConvExpandPrerequisits

Public Member Functions

 ConvNode (size_t element_id, const DebugInfo &debug_info, const graph::Vertex vertex, data_flow::DataFlowGraph &parent, const std::vector< symbolic::Expression > &shape, const std::vector< symbolic::Expression > &kernel_shape, const std::vector< symbolic::Expression > &strides, const std::vector< symbolic::Expression > &pads, const std::vector< symbolic::Expression > &dilations, symbolic::Expression output_channels, symbolic::Expression group, bool with_bias=false, QuantizationType quantization=QUANTIZATION_MATCH_INPUTS, const data_flow::ImplementationType &impl_type=data_flow::ImplementationType_NONE)
 Construct a convolution node.
symbolic::Expression output_channels () const
 Get the output channels.
symbolic::Expression group () const
 Get the group count.
void validate (const Function &function) const override
 Validate the code node's configuration.
symbolic::MultiExpression get_out_shape ()
bool has_bias () const
passes::LibNodeExpander::ExpandOutcome expand (passes::LibNodeExpander::ExpandContext &context, structured_control_flow::Block &block) override
 Expand convolution into nested maps for n-dimensional convolution.
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
bool supports_integer_types () const override
 Check if this operation supports integer types.
std::unique_ptr< data_flow::DataFlowNode > clone (size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph &parent) const override
 Clone this node for graph transformations.
std::string toStr () const override
 Convert node to string representation.
symbolic::Expression num_output_elements () const
 Total number of output elements: N * C_out * prod(output_spatial_dim(i)).
symbolic::Expression kernel_iteration_count () const
 Number of multiply-accumulate iterations per output element: (C_in / group) * prod(kernel_shape[i]).
symbolic::Expression flop () const override
 Calculate floating point operations for this node.
data_flow::PointerAccessType pointer_access_type (int input_idx) const override
 Describes what a pointer is used for.
bool check_expandable (data_flow::DataFlowGraph &dfg, ConvExpandPrerequisits &boundary) const
Public Member Functions inherited from sdfg::math::tensor::SpatialTensorNode
 SpatialTensorNode (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, QuantizationType quantization, const std::vector< symbolic::Expression > &shape, const std::vector< symbolic::Expression > &kernel_shape, const std::vector< symbolic::Expression > &strides, const std::vector< symbolic::Expression > &pads, const std::vector< symbolic::Expression > &dilations)
const std::vector< symbolic::Expression > & shape () const
const std::vector< symbolic::Expression > & kernel_shape () const
const std::vector< symbolic::Expression > & strides () const
const std::vector< symbolic::Expression > & pads () const
const std::vector< symbolic::Expression > & dilations () const
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)
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
size_t num_spatial_dims () const
 Number of spatial dimensions.
symbolic::Expression output_spatial_dim (size_t i) const
 Compute the output size for spatial dimension i.
symbolic::Expression output_spatial_volume () const
 Total number of output spatial elements: prod(output_spatial_dim(i)).
symbolic::Expression kernel_volume () const
 Total number of kernel / window elements: prod(kernel_shape[i]).
std::basic_ostream< char > & operator<< (std::basic_ostream< char > &os) const
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.
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.
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 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 blas::BLAS_Precision get_blas_precision (types::Scalar base_type)
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.

Static Public Attributes

static int constexpr Y_INPUT_IDX = 0
static int constexpr X_INPUT_IDX = 1
static int constexpr W_INPUT_IDX = 2
static int constexpr B_INPUT_IDX = 3
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.

Protected Attributes

symbolic::Expression output_channels_
 Number of output channels (C_out).
symbolic::Expression group_
 Number of groups for grouped convolution.
bool with_bias_
Protected Attributes inherited from sdfg::math::tensor::SpatialTensorNode
QuantizationType fixed_quantization_
std::vector< symbolic::Expression > shape_
 Input shape [N, C, D1, ..., Dn].
std::vector< symbolic::Expression > kernel_shape_
 Pooling window shape [k1, ..., kn].
std::vector< symbolic::Expression > strides_
 Stride along each spatial axis.
std::vector< symbolic::Expression > pads_
 Padding (start and end for each axis).
std::vector< symbolic::Expression > dilations_
 Dilation along each spatial axis.
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

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.
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

Convolution operation following ONNX Conv operator specification.

ConvNode represents a convolution operation that is compatible with the ONNX Conv operator. The operation is expanded using nested maps for n-dimensional convolutions (1D, 2D, 3D, etc.).

Input/Output Requirements

  • Input connector "X": Input tensor [N, C_in, D1, ..., Dn]
  • Input connector "W": Weight tensor [C_out, C_in/group, k1, ..., kn]
  • Input connector "B" (optional): Bias tensor [C_out]
  • Output connector "Y": Output tensor [N, C_out, D1_out, ..., Dn_out]

Expansion Support

  • naïve: Full support
  • im2col: Does not support non-contiguous output tensor and non-BLAS primitive types
  • im2row: Does not support grouping (groups != 1) and non-BLAS primitive types

Example

Creating a 2D convolution:

std::vector<symbolic::Expression> kernel_shape = {symbolic::integer(3), symbolic::integer(3)};
std::vector<symbolic::Expression> strides = {symbolic::integer(1), symbolic::integer(1)};
std::vector<symbolic::Expression> pads = {symbolic::integer(1), symbolic::integer(1),
std::vector<symbolic::Expression> dilations = {symbolic::integer(1), symbolic::integer(1)};
auto& conv_node = builder.add_library_node<math::tensor::ConvNode>(
);
const DebugInfo & debug_info() const
symbolic::Expression group() const
Get the group count.
Definition conv_node.h:127
const std::vector< symbolic::Expression > & strides() const
Definition spatial_tensor_node.h:69
const std::vector< symbolic::Expression > & dilations() const
Definition spatial_tensor_node.h:75
const std::vector< symbolic::Expression > & pads() const
Definition spatial_tensor_node.h:72
const std::vector< symbolic::Expression > & kernel_shape() const
Definition spatial_tensor_node.h:66
Integer integer(int64_t value)
Creates an integer constant.

Constructor & Destructor Documentation

◆ ConvNode()

sdfg::math::tensor::ConvNode::ConvNode ( size_t element_id,
const DebugInfo & debug_info,
const graph::Vertex vertex,
data_flow::DataFlowGraph & parent,
const std::vector< symbolic::Expression > & shape,
const std::vector< symbolic::Expression > & kernel_shape,
const std::vector< symbolic::Expression > & strides,
const std::vector< symbolic::Expression > & pads,
const std::vector< symbolic::Expression > & dilations,
symbolic::Expression output_channels,
symbolic::Expression group,
bool with_bias = false,
QuantizationType quantization = QUANTIZATION_MATCH_INPUTS,
const data_flow::ImplementationType & impl_type = data_flow::ImplementationType_NONE )

Construct a convolution node.

Parameters
element_idUnique element identifier
debug_infoDebug information
vertexGraph vertex
parentParent dataflow graph
shapeInput tensor shape [N, C_in, D1, ..., Dn]
kernel_shapeShape of the convolution kernel
stridesStride along each spatial axis (defaults to 1 for each axis)
padsPadding for start and end of each axis (defaults to 0)
dilationsDilation along each spatial axis (defaults to 1)
output_channelsNumber of output channels
groupNumber of groups for grouped convolution (defaults to 1)

Member Function Documentation

◆ check_expandable()

bool sdfg::math::tensor::ConvNode::check_expandable ( data_flow::DataFlowGraph & dfg,
ConvExpandPrerequisits & boundary ) const

◆ clone()

std::unique_ptr< data_flow::DataFlowNode > sdfg::math::tensor::ConvNode::clone ( size_t element_id,
const graph::Vertex vertex,
data_flow::DataFlowGraph & parent ) const
overridevirtual

Clone this node for graph transformations.

Parameters
element_idNew element identifier for the clone
vertexNew graph vertex for the clone
parentParent graph for the clone
Returns
Unique pointer to the cloned node

Pure virtual function that must be implemented by derived classes to support graph transformations and optimizations.

Implements sdfg::data_flow::DataFlowNode.

◆ expand()

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

Expand convolution into nested maps for n-dimensional convolution.

Expands the convolution operation by:

  1. Creating outer maps for parallel iteration over batch and output dimensions
  2. Creating inner for loops for sequential accumulation over input channels and kernel
  3. Computing convolution using FMA (fused multiply-add) tasklets
  4. Adding bias if present
  5. Writing results to output tensor

Supports n-dimensional convolutions (1D, 2D, 3D, and higher) with configurable strides and padding for each spatial dimension.

Implements sdfg::math::MathNode.

◆ flop()

symbolic::Expression sdfg::math::tensor::ConvNode::flop ( ) const
overridevirtual

Calculate floating point operations for this node.

Returns
Symbolic expression for FLOP count (or null)

Reimplemented from sdfg::data_flow::LibraryNode.

◆ get_blas_precision()

blas::BLAS_Precision sdfg::math::tensor::ConvNode::get_blas_precision ( types::Scalar base_type)
static

◆ get_out_shape()

symbolic::MultiExpression sdfg::math::tensor::ConvNode::get_out_shape ( )

◆ group()

symbolic::Expression sdfg::math::tensor::ConvNode::group ( ) const
inline

Get the group count.

Returns
Number of groups for grouped convolution

◆ has_bias()

bool sdfg::math::tensor::ConvNode::has_bias ( ) const

◆ kernel_iteration_count()

symbolic::Expression sdfg::math::tensor::ConvNode::kernel_iteration_count ( ) const

Number of multiply-accumulate iterations per output element: (C_in / group) * prod(kernel_shape[i]).

◆ num_output_elements()

symbolic::Expression sdfg::math::tensor::ConvNode::num_output_elements ( ) const

Total number of output elements: N * C_out * prod(output_spatial_dim(i)).

◆ output_channels()

symbolic::Expression sdfg::math::tensor::ConvNode::output_channels ( ) const
inline

Get the output channels.

Returns
Number of output channels

◆ pointer_access_type()

data_flow::PointerAccessType sdfg::math::tensor::ConvNode::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.

◆ replace() [1/2]

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

Implements sdfg::Element.

◆ replace() [2/2]

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

Reimplemented from sdfg::Element.

◆ supports_integer_types()

bool sdfg::math::tensor::ConvNode::supports_integer_types ( ) const
inlineoverridevirtual

Check if this operation supports integer types.

Operations like add, sub, mul, div, min, max support both floating-point and integer types. Operations like exp, log, tanh, sigmoid only support floating-point types.

Returns
true if integer types are supported, false otherwise

Implements sdfg::math::tensor::TensorNode.

◆ symbols()

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

Get all symbols used in this node.

Returns
Set of symbolic expressions used by this node

Implements sdfg::data_flow::LibraryNode.

◆ toStr()

std::string sdfg::math::tensor::ConvNode::toStr ( ) const
overridevirtual

Convert node to string representation.

Returns
String representation of the node

Reimplemented from sdfg::data_flow::LibraryNode.

◆ validate()

void sdfg::math::tensor::ConvNode::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.

Member Data Documentation

◆ B_INPUT_IDX

int constexpr sdfg::math::tensor::ConvNode::B_INPUT_IDX = 3
staticconstexpr

◆ group_

symbolic::Expression sdfg::math::tensor::ConvNode::group_
protected

Number of groups for grouped convolution.

◆ output_channels_

symbolic::Expression sdfg::math::tensor::ConvNode::output_channels_
protected

Number of output channels (C_out).

◆ W_INPUT_IDX

int constexpr sdfg::math::tensor::ConvNode::W_INPUT_IDX = 2
staticconstexpr

◆ with_bias_

bool sdfg::math::tensor::ConvNode::with_bias_
protected

◆ X_INPUT_IDX

int constexpr sdfg::math::tensor::ConvNode::X_INPUT_IDX = 1
staticconstexpr

◆ Y_INPUT_IDX

int constexpr sdfg::math::tensor::ConvNode::Y_INPUT_IDX = 0
staticconstexpr

The documentation for this class was generated from the following file:
  • sdfg/include/sdfg/data_flow/library_nodes/math/tensor/conv_node.h