2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "luci/Import/GraphBuilder.h"
24 void GraphBuilder::build(const circle::OperatorT &op, GraphBuilderContext *context) const
28 assert(context != nullptr);
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 auto tensors_ptr = context->reader()->tensors_ptr();
35 assert(tensors_ptr != nullptr);
37 std::vector<CircleNode *> input_nodes;
38 for (const int32_t input_tensor_index : inputs)
40 if (input_tensor_index >= 0)
42 auto input = context->nodefinder()->node(input_tensor_index);
44 INFO(l) << "[luci] Warning: input node is null " << input_tensor_index << std::endl;
45 input_nodes.push_back(input);
49 // If there is no tensor, insert CircleOutputExclude.
50 input_nodes.push_back(context->graph()->nodes()->create<luci::CircleOutputExclude>());
54 CircleNode *node = build_node(op, input_nodes, context->graph());
56 // Set up node parameters.
57 assert(outputs.size() == 1);
59 const circle::TensorT &output_tensor = *tensors[outputs[0]];
60 copy_tensor_attributes(output_tensor, node);
62 if (tensors_ptr->Get(outputs[0])->shape() == nullptr)
63 node->shape_status(ShapeStatus::NOSHAPE);
65 node->shape_status(ShapeStatus::VALID);
67 // mark operator version
68 node->op_version(opcodes[op.opcode_index].get()->version);
71 // Register node's only output.
72 assert(outputs.size() == 1);
74 context->nodefinder()->enroll(outputs[0], node);