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/Nodes/CircleUnique.h"
19 #include <luci/IR/Nodes/CircleUnique.h>
20 #include <luci/IR/Nodes/CircleUniqueOut.h>
27 bool CircleUniqueGraphBuilder::validate(const ValidateArgs &args) const
29 if (args.op.inputs.size() != 1)
32 if (args.op.outputs.size() != 2)
38 void CircleUniqueGraphBuilder::build(const circle::OperatorT &op,
39 GraphBuilderContext *context) const
41 assert(context != nullptr);
43 auto graph = context->graph();
45 const std::vector<int32_t> &inputs = op.inputs;
46 const std::vector<int32_t> &outputs = op.outputs;
47 const auto &tensors = context->reader()->tensors();
48 auto tensors_ptr = context->reader()->tensors_ptr();
49 assert(tensors_ptr != nullptr);
51 std::vector<CircleNode *> input_nodes;
52 for (const int32_t input_tensor_index : inputs)
54 input_nodes.push_back(context->nodefinder()->node(input_tensor_index));
57 // Create CircleUnique
58 auto node = graph->nodes()->create<CircleUnique>();
59 node->input(input_nodes[0]);
61 const auto *options = op.builtin_options.AsUniqueOptions();
62 node->output_type(luci_datatype(options->idx_out_type));
64 assert(int32_t(outputs.size()) == 2);
65 // Let's use name of output 0 as Unique name
66 const circle::TensorT &output_tensor = *tensors[outputs[0]];
67 node->name(tensor_name(output_tensor));
69 // Create virtual outputs of Unique
70 for (int32_t n = 0; n < 2; ++n)
72 const circle::TensorT &output_tensor = *tensors[outputs[n]];
74 auto *nodeout = graph->nodes()->create<CircleUniqueOut>();
75 copy_tensor_attributes(output_tensor, nodeout);
77 if (tensors_ptr->Get(outputs[n])->shape() == nullptr)
78 nodeout->shape_status(ShapeStatus::NOSHAPE);
80 nodeout->shape_status(ShapeStatus::VALID);
85 context->nodefinder()->enroll(outputs[n], nodeout);