ONE - On-device Neural Engine
Loading...
Searching...
No Matches
GraphBuilder.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
18
19#include <luci/Log.h>
20
21namespace luci
22{
23
24CircleNode *GraphBuilder::build(const circle::OperatorT &op, GraphBuilderContext *context) const
25{
26 LOGGER(l);
27
28 assert(context != nullptr);
29
30 const std::vector<int32_t> &inputs = op.inputs;
31 const std::vector<int32_t> &outputs = op.outputs;
32 const auto tensors = context->reader()->tensors();
33 const auto opcodes = context->reader()->opcodes();
34 assert(!tensors.null());
35
36 std::vector<CircleNode *> input_nodes;
37 for (const int32_t input_tensor_index : inputs)
38 {
39 if (input_tensor_index >= 0)
40 {
41 auto input = context->nodefinder()->node(input_tensor_index);
42 if (input == nullptr)
43 INFO(l) << "[luci] Warning: input node is null " << input_tensor_index << std::endl;
44 input_nodes.push_back(input);
45 }
46 else
47 {
48 // If there is no tensor, insert CircleOutputExclude.
49 auto *node = context->graph()->nodes()->create<luci::CircleOutputExclude>();
50 input_nodes.push_back(node);
51 }
52 }
53
54 CircleNode *node = build_node(op, input_nodes, context->graph());
55
56 // Set up node parameters.
57 assert(outputs.size() == 1);
58 {
59 const auto output_tensor = tensors[outputs[0]];
60 assert(output_tensor != nullptr);
61 copy_tensor_attributes(output_tensor, node);
62 // mark shape_status
63 if (output_tensor->shape() == nullptr)
65 else
67
68 // mark operator version
69 assert(opcodes[op.opcode_index] != nullptr);
70 node->op_version(opcodes[op.opcode_index]->version());
71 }
72
73 // Register node's only output.
74 assert(outputs.size() == 1);
75 {
76 context->nodefinder()->enroll(outputs[0], node);
77 }
78
79 return node;
80}
81
82} // namespace luci
#define LOGGER(name)
Definition Log.h:65
#define INFO(name)
Definition Log.h:68
NodeContext * nodes(void)
Definition Graph.h:218
Derived * create(Args &&...args)
Definition NodePool.h:37
CircleOutputExclude is used to specifying not exported nodes.
CircleOperatorCodes opcodes() const
CircleTensors tensors() const
Class to store context to build loco graph IR from TensorFlow.
IndexNodeFinder * nodefinder()
CircleNode * build(const circle::OperatorT &op, GraphBuilderContext *context) const final
void enroll(TensorIndex idx, CircleNode *node)
CircleNode * node(TensorIndex idx) const
void copy_tensor_attributes(const circle::Tensor *tensor, CircleNode *node)
Copy common tensor attributes such as name, type, etc. to node.
int32_t op_version(void) const
ShapeStatus shape_status(void) const