docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
spatial_tensor_node.h
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <cstddef>
5#include <vector>
8
10
11namespace sdfg {
12namespace math {
13namespace tensor {
14
37protected:
39 std::vector<symbolic::Expression> shape_;
40 std::vector<symbolic::Expression> kernel_shape_;
41 std::vector<symbolic::Expression> strides_;
42 std::vector<symbolic::Expression> pads_;
43 std::vector<symbolic::Expression> dilations_;
44
45public:
47 size_t element_id,
48 const DebugInfo& debug_info,
52 const std::vector<std::string>& outputs,
53 const std::vector<std::string>& inputs,
54 const data_flow::ImplementationType& impl_type,
56 const std::vector<symbolic::Expression>& shape,
57 const std::vector<symbolic::Expression>& kernel_shape,
58 const std::vector<symbolic::Expression>& strides,
59 const std::vector<symbolic::Expression>& pads,
60 const std::vector<symbolic::Expression>& dilations
61 );
62
63 const std::vector<symbolic::Expression>& shape() const {
64 return shape_;
65 }
66 const std::vector<symbolic::Expression>& kernel_shape() const {
67 return kernel_shape_;
68 }
69 const std::vector<symbolic::Expression>& strides() const {
70 return strides_;
71 }
72 const std::vector<symbolic::Expression>& pads() const {
73 return pads_;
74 }
75 const std::vector<symbolic::Expression>& dilations() const {
76 return dilations_;
77 }
78
82
87
92 std::optional<QuantizationType> uniform_quantization(const data_flow::DataFlowGraph& dataflow) const;
93
99
101
102 symbolic::SymbolSet symbols() const override;
103
104 void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override;
105
106 void replace(const symbolic::ExpressionMapping& replacements) override;
112 size_t num_spatial_dims() const;
113
126
134
142
143 std::basic_ostream<char>& operator<<(std::basic_ostream<char>& os) const;
144};
145
147public:
148 struct BaseDeser {
149 std::vector<symbolic::Expression> shape;
150 std::vector<symbolic::Expression> kernel_shape;
151 std::vector<symbolic::Expression> strides;
152 std::vector<symbolic::Expression> pads;
153 std::vector<symbolic::Expression> dilations;
156 };
157
158 void fill_base_values(const SpatialTensorNode& node, nlohmann::json& j);
159
160 BaseDeser deserialize_base_values(const nlohmann::json& j);
161};
162
163} // namespace tensor
164} // namespace math
165} // namespace sdfg
Definition element.h:30
size_t element_id() const
const DebugInfo & debug_info() const
const std::vector< std::string > & outputs() const
Get output connector names (const).
const std::vector< std::string > & inputs() const
Get input connector names (const).
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).
const LibraryNodeCode & code() const
Get the operation code.
Definition spatial_tensor_node.h:146
void fill_base_values(const SpatialTensorNode &node, nlohmann::json &j)
BaseDeser deserialize_base_values(const nlohmann::json &j)
Specialization of TensorNode for spatial operations such as Convolution and Pooling.
Definition spatial_tensor_node.h:36
std::basic_ostream< char > & operator<<(std::basic_ostream< char > &os) const
std::vector< symbolic::Expression > pads_
Padding (start and end for each axis).
Definition spatial_tensor_node.h:42
symbolic::Expression output_spatial_volume() const
Total number of output spatial elements: prod(output_spatial_dim(i)).
symbolic::Expression output_spatial_dim(size_t i) const
Compute the output size for spatial dimension i.
QuantizationType quantization(const data_flow::DataFlowGraph &dataflow) const
type of the math calculations.
QuantizationType fixed_quantization() const
configuration of the type for the math calculations, independent of current input types etc.
const std::vector< symbolic::Expression > & shape() const
Definition spatial_tensor_node.h:63
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
std::optional< QuantizationType > uniform_quantization(const data_flow::DataFlowGraph &dataflow) const
Same result as quantization if it matches all the inputs.
QuantizationType fixed_quantization_
Definition spatial_tensor_node.h:38
std::vector< symbolic::Expression > dilations_
Dilation along each spatial axis.
Definition spatial_tensor_node.h:43
std::vector< symbolic::Expression > shape_
Input shape [N, C, D1, ..., Dn].
Definition spatial_tensor_node.h:39
symbolic::Expression kernel_volume() const
Total number of kernel / window elements: prod(kernel_shape[i]).
symbolic::SymbolSet symbols() const override
Get all symbols used in this node.
void set_fixed_quantization(const QuantizationType quant)
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)
QuantizationType quantization() const
Definition spatial_tensor_node.h:79
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
void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override
std::vector< symbolic::Expression > strides_
Stride along each spatial axis.
Definition spatial_tensor_node.h:41
size_t num_spatial_dims() const
Number of spatial dimensions.
std::vector< symbolic::Expression > kernel_shape_
Pooling window shape [k1, ..., kn].
Definition spatial_tensor_node.h:40
void replace(const symbolic::ExpressionMapping &replacements) override
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.
Base class for library node serialization.
Definition json_serializer.h:195
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
StringEnum ImplementationType
Implementation type identifier for library nodes.
Definition library_node.h:75
StringEnum LibraryNodeCode
Definition library_node.h:65
boost::graph_traits< Graph >::vertex_descriptor Vertex
Definition graph.h:25
Definition arange_node.h:8
types::PrimitiveType QuantizationType
Definition tensor_node.h:26
Definition batched_gemm_node.h:12
Definition analysis.h:7
std::vector< symbolic::Expression > strides
Definition spatial_tensor_node.h:151
std::vector< symbolic::Expression > pads
Definition spatial_tensor_node.h:152
DebugInfo debug_info
Definition spatial_tensor_node.h:155
std::vector< symbolic::Expression > dilations
Definition spatial_tensor_node.h:153
std::vector< symbolic::Expression > shape
Definition spatial_tensor_node.h:149
QuantizationType quantization
Definition spatial_tensor_node.h:154
std::vector< symbolic::Expression > kernel_shape
Definition spatial_tensor_node.h:150
Symbolic system for integer-based symbol analysis.
Abstract base class for tensor library nodes.