docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
load_const_node.h
Go to the documentation of this file.
1#pragma once
2
4
7
8namespace sdfg {
9namespace data_flow {
10
12
14 // TODO may need format info (endianness, multi-dim alignment? at least for producing the data)
15
16public:
17 using byte_iterator = std::vector<uint8_t>::const_iterator;
18
19 virtual ~ConstSource() = default;
20
24 // virtual bool read_data(void* output) const = 0;
25
26 virtual std::unique_ptr<ConstSource> clone() const = 0;
27
28 virtual bool in_external_file() const = 0;
29 virtual const std::filesystem::path& filename() const = 0;
30
31 virtual bool is_inlineable() const = 0;
32 virtual byte_iterator inline_begin() const = 0;
33 virtual byte_iterator inline_end() const = 0;
34 virtual size_t num_bytes() const = 0;
35
36 virtual std::string toStr() const = 0;
37};
38
44
45 std::vector<uint8_t> data_;
46
47public:
48 InMemoryConstSource(std::vector<uint8_t>&& data) : data_(std::move(data)) {
49 }
50 InMemoryConstSource(int size) : data_(size) {
51 }
52 template<class InputIt>
53 InMemoryConstSource(InputIt begin, InputIt end) : data_(begin, end) {
54 }
55
56
57 std::unique_ptr<ConstSource> clone() const override {
58 std::vector<uint8_t> data(data_.begin(), data_.end());
59 return std::make_unique<InMemoryConstSource>(std::move(data));
60 }
61
62 bool is_inlineable() const override {
63 return true;
64 }
65 byte_iterator inline_begin() const override {
66 return data_.begin();
67 }
68 byte_iterator inline_end() const override {
69 return data_.end();
70 }
71
72 size_t num_bytes() const override {
73 return data_.size();
74 }
75
76 bool in_external_file() const override {
77 return false;
78 }
79 const std::filesystem::path& filename() const override {
80 throw std::runtime_error("no external file");
81 }
82
83 std::string toStr() const override {
84 return "InMemory(" + std::to_string(data_.size()) + " B)";
85 }
86};
87
93 std::filesystem::path filename_;
94 size_t num_bytes_;
95
96public:
97 RawFileConstSource(std::filesystem::path filename, size_t num_bytes)
98 : filename_(std::move(filename)), num_bytes_(num_bytes) {
99 }
100 // virtual bool read_data(void* output) override;
101
102 std::unique_ptr<ConstSource> clone() const override {
103 return std::make_unique<RawFileConstSource>(filename_, num_bytes_);
104 }
105
106 bool is_inlineable() const override {
107 return false;
108 }
109
110 bool in_external_file() const override {
111 return true;
112 }
113 const std::filesystem::path& filename() const override {
114 return filename_;
115 }
116
117 byte_iterator inline_begin() const override {
118 throw std::runtime_error("inlining not supported");
119 }
120 byte_iterator inline_end() const override {
121 throw std::runtime_error("inlining not supported");
122 }
123
124 size_t num_bytes() const override {
125 return num_bytes_;
126 }
127
128 std::string toStr() const override {
129 return "RawFile(" + filename_.string() + ", " + std::to_string(num_bytes_) + " B)";
130 }
131};
132
134protected:
135 std::unique_ptr<ConstSource> data_source_;
136 std::unique_ptr<types::IType> type_;
137
138public:
140 size_t element_id,
141 const DebugInfo& debug_info,
142 const graph::Vertex vertex,
143 DataFlowGraph& parent,
144 std::unique_ptr<types::IType> type,
145 std::unique_ptr<ConstSource> data_source
146 );
147
148 symbolic::SymbolSet symbols() const override;
149
150 const types::IType& type() const;
151
153
154 void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override;
155
156 void replace(const symbolic::ExpressionMapping& replacements) override;
157
158 std::unique_ptr<DataFlowNode> clone(size_t element_id, const graph::Vertex vertex, DataFlowGraph& parent) const override;
159
160 std::string toStr() const override;
161};
162
164public:
165 nlohmann::json serialize(const LibraryNode& library_node) override;
166 static void const_source_to_json(nlohmann::json& j, const ConstSource& source);
167 static std::unique_ptr<ConstSource> json_to_const_source(const nlohmann::json& j);
168
171 ) override;
172};
173
175public:
177 codegen::LanguageExtension& language_extension,
178 const Function& function,
179 const DataFlowGraph& data_flow_graph,
180 const LoadConstNode& node
181 );
182
185 codegen::PrettyPrinter& globals_stream,
186 codegen::CodeSnippetFactory& library_snippet_factory
187 ) override;
188
191 codegen::PrettyPrinter& globals_stream,
192 codegen::CodeSnippetFactory& library_snippet_factory,
193 const ConstSource& source,
194 const std::string& output_container
195 );
196
199 codegen::PrettyPrinter& globals_stream,
200 codegen::CodeSnippetFactory& library_snippet_factory,
201 const RawFileConstSource& source,
202 const std::string& output_container
203 );
204
206 codegen::PrettyPrinter& globals_stream, codegen::CodeSnippetFactory& library_snippet_factory
207 );
208};
209
210} // namespace data_flow
211} // namespace sdfg
Dispatchers for dataflow blocks and library nodes.
Definition element.h:30
size_t element_id() const
const DebugInfo & debug_info() const
Definition function.h:43
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
Originally started out as a handler for additional source files, like hardware-accelerator kernels th...
Definition code_snippet_factory.h:69
Definition language_extension.h:39
Base class for library node code generation dispatchers.
Definition block_dispatcher.h:163
Definition utils.h:16
Definition load_const_node.h:13
virtual byte_iterator inline_begin() const =0
virtual ~ConstSource()=default
virtual std::unique_ptr< ConstSource > clone() const =0
for passes to access the data to potentially fold operations into it etc.
virtual const std::filesystem::path & filename() const =0
virtual byte_iterator inline_end() const =0
virtual std::string toStr() const =0
virtual bool in_external_file() const =0
virtual size_t num_bytes() const =0
std::vector< uint8_t >::const_iterator byte_iterator
Definition load_const_node.h:17
virtual bool is_inlineable() const =0
Definition data_flow_graph.h:29
graph::Vertex vertex() const
Get the graph vertex for this node.
InMemoryConstSource(std::vector< uint8_t > &&data)
Definition load_const_node.h:48
InMemoryConstSource(InputIt begin, InputIt end)
Definition load_const_node.h:53
byte_iterator inline_end() const override
Definition load_const_node.h:68
bool is_inlineable() const override
Definition load_const_node.h:62
byte_iterator inline_begin() const override
Definition load_const_node.h:65
size_t num_bytes() const override
Definition load_const_node.h:72
const std::filesystem::path & filename() const override
Definition load_const_node.h:79
friend class LoadConstNodeSerializer
Definition load_const_node.h:43
std::string toStr() const override
Definition load_const_node.h:83
std::unique_ptr< ConstSource > clone() const override
for passes to access the data to potentially fold operations into it etc.
Definition load_const_node.h:57
InMemoryConstSource(int size)
Definition load_const_node.h:50
bool in_external_file() const override
Definition load_const_node.h:76
Base class for all library nodes in the dataflow graph.
Definition library_node.h:106
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.
static void ensure_arg_capture_dep(codegen::PrettyPrinter &globals_stream, codegen::CodeSnippetFactory &library_snippet_factory)
void dispatch_inline_const(codegen::PrettyPrinter &stream, codegen::PrettyPrinter &globals_stream, codegen::CodeSnippetFactory &library_snippet_factory, const ConstSource &source, const std::string &output_container)
LoadConstNodeDispatcher(codegen::LanguageExtension &language_extension, const Function &function, const DataFlowGraph &data_flow_graph, const LoadConstNode &node)
static void dispatch_runtime_load(codegen::PrettyPrinter &stream, codegen::PrettyPrinter &globals_stream, codegen::CodeSnippetFactory &library_snippet_factory, const RawFileConstSource &source, const std::string &output_container)
void dispatch_code(codegen::PrettyPrinter &stream, codegen::PrettyPrinter &globals_stream, codegen::CodeSnippetFactory &library_snippet_factory) override
Generate the operation-specific code.
Definition load_const_node.h:163
static std::unique_ptr< ConstSource > json_to_const_source(const nlohmann::json &j)
nlohmann::json serialize(const LibraryNode &library_node) override
Serialize a library node to JSON.
LibraryNode & deserialize(const nlohmann::json &j, builder::StructuredSDFGBuilder &builder, structured_control_flow::Block &parent) override
Deserialize a library node from JSON.
static void const_source_to_json(nlohmann::json &j, const ConstSource &source)
Definition load_const_node.h:133
symbolic::SymbolSet symbols() const override
Get all symbols used in this node.
LoadConstNode(size_t element_id, const DebugInfo &debug_info, const graph::Vertex vertex, DataFlowGraph &parent, std::unique_ptr< types::IType > type, std::unique_ptr< ConstSource > data_source)
std::unique_ptr< ConstSource > data_source_
Definition load_const_node.h:135
ConstSource & data_source() const
std::string toStr() const override
Convert node to string representation.
const types::IType & type() const
std::unique_ptr< DataFlowNode > clone(size_t element_id, const graph::Vertex vertex, DataFlowGraph &parent) const override
Clone this node for graph transformations.
void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override
void replace(const symbolic::ExpressionMapping &replacements) override
std::unique_ptr< types::IType > type_
Definition load_const_node.h:136
Constant data stored in external files, using arg_capture_io code to read (raw data,...
Definition load_const_node.h:92
bool in_external_file() const override
Definition load_const_node.h:110
byte_iterator inline_end() const override
Definition load_const_node.h:120
std::string toStr() const override
Definition load_const_node.h:128
const std::filesystem::path & filename() const override
Definition load_const_node.h:113
RawFileConstSource(std::filesystem::path filename, size_t num_bytes)
Definition load_const_node.h:97
bool is_inlineable() const override
Definition load_const_node.h:106
size_t num_bytes() const override
Definition load_const_node.h:124
byte_iterator inline_begin() const override
Definition load_const_node.h:117
std::unique_ptr< ConstSource > clone() const override
for passes to access the data to potentially fold operations into it etc.
Definition load_const_node.h:102
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
Abstract base interface for all types in the sdfglib type system.
Definition type.h:625
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
Library node definitions for calling functions beyond simple instructions.
Definition function_builder.h:10
Definition access_node.h:67
StringEnum LibraryNodeCode
Definition library_node.h:65
LibraryNodeCode LibraryNodeType_LoadConst("LoadConst")
boost::graph_traits< Graph >::vertex_descriptor Vertex
Definition graph.h:25
Definition analysis.h:7