ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleOperationExporter.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
19
20#include <luci/IR/CircleNode.h>
23#include <loco/IR/Algorithm.h>
24
25namespace luci
26{
27
30{
31 uint32_t node_position = 0;
33 {
34 ExportContext ctx{builder, md, gd};
35 OperationExporterRule exporter_rule{ctx};
36
37 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
38 circle_node->accept(&exporter_rule);
39
40 const auto ops_size = gd._operators.size();
41
42 if (has_origin(circle_node) && ops_size != gd._operators.size())
43 {
44 const auto node_id = gd._operators.size() - 1;
45 for (auto source : get_origin(circle_node)->sources())
46 {
47 md._metadata.add_op_table(node_id, source->id());
48 }
49 }
50 if (has_execution_plan(circle_node))
51 {
52 // Add to node (in node_position) metadata vector with execution_plan information:
53 // order of execution, and offsets output tensors.
54 const auto execution_plan = get_execution_plan(circle_node);
55 std::vector<uint32_t> execution_plan_vector;
56 execution_plan_vector.push_back(execution_plan.order_in_plan());
57 for (auto offset : execution_plan.offsets())
58 {
59 execution_plan_vector.push_back(offset);
60 }
61 md._metadata.add_execution_plan_table(node_position, execution_plan_vector);
62 }
63
64 node_position++;
65 }
66}
67
68} // namespace luci
Helper class to hold data needed in creation of a FlatBuffer. To serialize data, you typically call o...
A neural network graph.
Definition Graph.h:161
void add_execution_plan_table(uint32_t node_id, const std::vector< uint32_t > &execution_plan_inform)
void add_op_table(uint32_t node_id, uint32_t source_id)
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
std::vector< loco::Node * > postorder_traversal(const std::vector< loco::Node * > &roots)
Generate postorder traversal sequence starting from "roots".
Definition Algorithm.cpp:53
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101
void exportNodes(loco::Graph *g, flatbuffers::FlatBufferBuilder &builder, SerializedModelData &md, SerializedGraphData &gd)
create Operators corresponding to model nodes
bool has_execution_plan(const luci::CircleNode *circle_node)
luci::CircleNodeExecutionPlan get_execution_plan(const luci::CircleNode *circle_node)
std::vector< flatbuffers::Offset< circle::Operator > > _operators
CircleExportMetadata _metadata