docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
elementwise_node.h File Reference

Tensor elementwise operation nodes. More...

Go to the source code of this file.

Classes

class  sdfg::math::tensor::ElementWiseDataflowTensorNode
 Defined by each element of the output tensor (defined by shape) can be defined independently of any other output. More...
struct  sdfg::math::tensor::ElementWiseDataflowTensorNode::ElementOutput
struct  sdfg::math::tensor::ElementWiseDataflowTensorNode::ElementInput
class  sdfg::math::tensor::BaseElementWiseDataflowTensorNodeSerializer
struct  sdfg::math::tensor::BaseElementWiseDataflowTensorNodeSerializer::BaseDeser
class  sdfg::math::tensor::SimpleElementWiseDataflowTensorNodeSerializer< T >

Namespaces

namespace  sdfg
namespace  sdfg::math
namespace  sdfg::math::tensor

Detailed Description

Tensor elementwise operation nodes.

This file defines base classes for tensor elementwise operations. Elementwise operations are mathematical operations applied independently to each element of a tensor or pair of tensors.

Tensor Library Nodes

Tensor library nodes expect scalars or flat pointers of scalars as inputs. The tensor operation is performed with linearized indices. This means:

  • Multi-dimensional tensor operations are represented using 1D indexing
  • The shape parameter specifies the logical dimensions
  • Data access uses linearized (flat) memory layout

For example, a 2D tensor of shape [M, N] is accessed using index i*N + j where i and j are the row and column indices.

Elementwise Operations

Elementwise operations include:

  • Unary operations: abs, sqrt, exp, tanh, sigmoid, relu, etc.
  • Binary operations: add, sub, mul, div, pow, etc.

These operations are expanded into maps that iterate over the tensor shape with linearized indexing.

Example

Creating an elementwise addition:

// Create tensor addition node for shape [32, 64]
std::vector<symbolic::Expression> shape = {
symbolic::integer(32), symbolic::integer(64)
};
auto& add_node = builder.add_library_node<math::tensor::AddNode>(
block, debug_info, shape
);
// Connect flat pointer inputs
types::Scalar element_type(types::PrimitiveType::Float);
types::Pointer ptr_type(element_type);
builder.add_computational_memlet(block, input_a, add_node, "A", {}, ptr_type, debug_info);
builder.add_computational_memlet(block, input_b, add_node, "B", {}, ptr_type, debug_info);
builder.add_computational_memlet(block, add_node, "Y", output, {}, ptr_type, debug_info);
// Expand into map with linearized indexing
analysis::AnalysisManager analysis_manager(sdfg);
add_node.expand(builder, analysis_manager);
Definition analysis.h:7
See also
math::tensor::ReduceNode for reduction operations
math::MathNode for expansion interface