MCPcopy Create free account
hub / github.com/Samsung/ONE / cook_graph

Function cook_graph

compiler/circlechef/core/src/ModelChef.cpp:219–519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217};
218
219template <typename T> void cook_graph(const T &graph, CookParams &cp)
220{
221 LOGGER(l);
222
223 std::vector<flatbuffers::Offset<::circle::Buffer>> &buffer_vec = cp.buffer_vec;
224 std::vector<flatbuffers::Offset<::circle::OperatorCode>> &code_vec = cp.code_vec;
225 std::vector<flatbuffers::Offset<::circle::SubGraph>> &subgraph_vec = cp.subgraph_vec;
226 std::unique_ptr<flatbuffers::FlatBufferBuilder> &flatbuffer_builder = cp.flatbuffer_builder;
227 std::map<circle::BuiltinOperator, int32_t> &builtin_code_map = cp.builtin_code_map;
228
229 // Operand-related
230 std::vector<flatbuffers::Offset<::circle::Tensor>> tensor_vec;
231
232 // Operation-related
233 std::vector<flatbuffers::Offset<::circle::Operator>> operator_vec;
234
235 // default name for graph
236 std::string graph_name = cp.noname;
237 if (graph.has_name())
238 graph_name = graph.name();
239
240 // Tensor Name -> Tensor ID mapping (per Graph)
241 std::map<std::string, int32_t> symbol_table;
242
243 auto lookup = [&symbol_table, &graph_name](const std::string &name) {
244 if (symbol_table.find(name) != symbol_table.end())
245 return symbol_table.at(name);
246 else if (name == "")
247 return -1; // -1 in circle means that optional input tensor is empty.
248 else
249 {
250 std::string msg = "circlechef : input not found in " + graph_name + " graph";
251 throw std::runtime_error(msg.c_str());
252 }
253 };
254
255 int32_t buffer_start = buffer_vec.size();
256 int32_t buffer_index = 0;
257
258 // Create buffer(s) 1~n(I) for input(s)
259 const auto size_input = graph.input_size();
260 for (int ci = 0; ci < size_input; ++ci)
261 {
262 circle::BufferBuilder buffer_builder{*flatbuffer_builder};
263 buffer_vec.emplace_back(buffer_builder.Finish());
264 }
265 // Create buffer(s) n(I)+1~n(I)+n(O) for output(s)
266 const auto size_output = graph.output_size();
267 for (int co = 0; co < size_output; ++co)
268 {
269 circle::BufferBuilder buffer_builder{*flatbuffer_builder};
270 buffer_vec.emplace_back(buffer_builder.Finish());
271 }
272
273 auto input_names = as_dataset(graph.input()).vectorize();
274 auto output_names = as_dataset(graph.output()).vectorize();
275
276 for (const auto &operand : graph.operand())

Callers

nothing calls this directly

Calls 15

as_datasetFunction · 0.85
ranged_argumentsFunction · 0.85
as_circle_tensortypeFunction · 0.85
has_typeMethod · 0.80
tagMethod · 0.80
operationMethod · 0.80
custom_codeMethod · 0.80
as_dimsFunction · 0.50
element_countFunction · 0.50
nameMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected