87 std::vector<symbolic::Expression>
shape_;
109 const std::vector<symbolic::Expression>&
shape,
110 const std::vector<int64_t>&
axes,
123 const std::vector<symbolic::Expression>&
shape()
const {
131 const std::vector<int64_t>&
axes()
const {
224 const std::vector<symbolic::Expression>& output_shape,
225 const std::vector<int64_t>& sorted_axes
239 j[
"shape"] = nlohmann::json::array();
240 for (
auto& dim : reduce_node.
shape()) {
241 j[
"shape"].push_back(
serializer.expression(dim));
244 j[
"axes"] = reduce_node.
axes();
245 j[
"keepdims"] = reduce_node.
keepdims();
254 assert(j.contains(
"element_id"));
255 assert(j.contains(
"code"));
256 assert(j.contains(
"debug_info"));
257 assert(j.contains(
"shape"));
258 assert(j.contains(
"axes"));
259 assert(j.contains(
"keepdims"));
261 auto code = j[
"code"].get<std::string>();
263 std::vector<symbolic::Expression> shape;
264 for (
const auto& dim : j[
"shape"]) {
268 std::vector<int64_t> axes = j[
"axes"].get<std::vector<int64_t>>();
269 bool keepdims = j[
"keepdims"].get<
bool>();
275 return static_cast<ReduceNode&
>(
builder.add_library_node<T>(parent, debug_info, shape, axes, keepdims));
Dispatchers for dataflow blocks and library nodes.
size_t element_id() const
const DebugInfo & debug_info() const
std::string value() const
Definition exceptions.h:47
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
Definition data_flow_graph.h:29
graph::Vertex vertex() const
Get the graph vertex for this node.
Base class for all library nodes in the dataflow graph.
Definition library_node.h:106
const LibraryNodeCode & code() const
Get the operation code.
Edge in the dataflow graph representing data movement.
Definition memlet.h:131
Definition reduce_node.h:230
data_flow::LibraryNode & deserialize(const nlohmann::json &j, builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &parent) override
Deserialize a library node from JSON.
Definition reduce_node.h:250
nlohmann::json serialize(const data_flow::LibraryNode &library_node) override
Serialize a library node to JSON.
Definition reduce_node.h:232
Base class for tensor reduction operations.
Definition reduce_node.h:85
virtual passes::LibNodeExpander::ExpandOutcome expand_inner(passes::LibNodeExpander::AccessNodeExpand &expansion, structured_control_flow::Block &block, const data_flow::Memlet *iedge_input, const data_flow::Memlet *iedge_result, const std::vector< symbolic::Expression > &output_shape, const std::vector< int64_t > &sorted_axes)
symbolic::SymbolSet symbols() const override
Get all symbols used in this node.
std::vector< int64_t > axes_
Axes to reduce over.
Definition reduce_node.h:88
std::string toStr() const override
Convert node to string representation.
void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override
bool keepdims_
Whether to keep reduced dimensions with size 1.
Definition reduce_node.h:89
static auto constexpr X_INPUT_IDX
Definition reduce_node.h:115
std::vector< symbolic::Expression > shape_
Input tensor shape.
Definition reduce_node.h:87
void validate(const Function &function) const override
Validate the code node's configuration.
ReduceNode(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::vector< int64_t > &axes, bool keepdims)
Construct a reduction node.
passes::LibNodeExpander::ExpandOutcome expand(passes::LibNodeExpander::ExpandContext &context, Block &block) override
Expand into nested maps with reduction logic.
virtual std::optional< structured_control_flow::ReductionOperation > reduction_operation() const
Get the ReductionOperation for this reduction.
Definition reduce_node.h:210
static auto constexpr RESULT_PTR_IDX
Definition reduce_node.h:114
void replace(const symbolic::ExpressionMapping &replacements) override
data_flow::PointerAccessType pointer_access_type(int input_idx) const override
Describes what a pointer is used for.
virtual std::string identity(types::PrimitiveType primitive_type) const =0
Get the identity value for this reduction.
const std::vector< symbolic::Expression > & shape() const
Get the input tensor shape.
Definition reduce_node.h:123
const std::vector< int64_t > & axes() const
Get the reduction axes.
Definition reduce_node.h:131
virtual bool expand_reduction(passes::LibNodeExpander::AccessNodeExpand &expansion, builder::StructuredSDFGBuilder &builder, structured_control_flow::Sequence &body, const types::Tensor &input_type, const types::Tensor &output_type, const data_flow::Subset &input_subset, const data_flow::Subset &output_subset)=0
Generate the actual reduction code.
bool keepdims() const
Check if reduced dimensions are kept.
Definition reduce_node.h:139
types::PrimitiveType primitive_type(const data_flow::DataFlowGraph &graph) const
Get the primitive type of this tensor operation.
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:45
Definition lib_node_expander.h:122
Definition json_serializer.h:22
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
Expression parse(const std::string &expr_str)
Parses a string into a symbolic expression.
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
symbolic::MultiExpression Subset
Type alias for a subset specification (array of symbolic expressions).
Definition memlet.h:103
StringEnum LibraryNodeCode
Definition library_node.h:65
std::unique_ptr< PointerAccessMeta, PtrAccessDeleter > PointerAccessType
Definition pointer_metadata.h:32
boost::graph_traits< Graph >::vertex_descriptor Vertex
Definition graph.h:25
Definition arange_node.h:8
Definition batched_gemm_node.h:12
Definition cutout_serializer.h:13
PrimitiveType
Enumeration of all primitive data types supported by sdfglib.
Definition type.h:35
Definition lib_node_expander.h:12
Abstract base class for tensor library nodes.