forked from Samsung/ONE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[luci/import] Add Unique operation (Samsung#3605)
This commit will add unique operation to luci import ONE-DCO-1.0-Signed-off-by: venkat.iyer <[email protected]> Signed-off-by: venkat.iyer <[email protected]>
- Loading branch information
1 parent
cb81eee
commit 80ff3fd
Showing
4 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
compiler/luci/import/include/luci/Import/Nodes/CircleUnique.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __LUCI_IMPORT_OP_CIRCLE_UNIQUE_H__ | ||
#define __LUCI_IMPORT_OP_CIRCLE_UNIQUE_H__ | ||
|
||
#include "luci/Import/GraphBuilderBase.h" | ||
|
||
namespace luci | ||
{ | ||
|
||
class CircleUniqueGraphBuilder : public GraphBuilderBase | ||
{ | ||
public: | ||
bool validate(const ValidateArgs &args) const final; | ||
|
||
void build(const circle::OperatorT &op, GraphBuilderContext *context) const final; | ||
}; | ||
|
||
} // namespace luci | ||
|
||
#endif // __LUCI_IMPORT_OP_CIRCLE_UNIQUE_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "luci/Import/Nodes/CircleUnique.h" | ||
|
||
#include <luci/IR/Nodes/CircleUnique.h> | ||
#include <luci/IR/Nodes/CircleUniqueOut.h> | ||
|
||
#include <loco.h> | ||
|
||
namespace luci | ||
{ | ||
|
||
bool CircleUniqueGraphBuilder::validate(const ValidateArgs &args) const | ||
{ | ||
if (args.op.inputs.size() != 1) | ||
return false; | ||
|
||
if (args.op.outputs.size() != 2) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
void CircleUniqueGraphBuilder::build(const circle::OperatorT &op, | ||
GraphBuilderContext *context) const | ||
{ | ||
assert(context != nullptr); | ||
|
||
auto graph = context->graph(); | ||
|
||
const std::vector<int32_t> &inputs = op.inputs; | ||
const std::vector<int32_t> &outputs = op.outputs; | ||
const auto &tensors = context->reader()->tensors(); | ||
auto tensors_ptr = context->reader()->tensors_ptr(); | ||
assert(tensors_ptr != nullptr); | ||
|
||
std::vector<CircleNode *> input_nodes; | ||
for (const int32_t input_tensor_index : inputs) | ||
{ | ||
input_nodes.push_back(context->nodefinder()->node(input_tensor_index)); | ||
} | ||
|
||
// Create CircleUnique | ||
auto node = graph->nodes()->create<CircleUnique>(); | ||
node->input(input_nodes[0]); | ||
|
||
const auto *options = op.builtin_options.AsUniqueOptions(); | ||
node->output_type(luci_datatype(options->idx_out_type)); | ||
|
||
assert(int32_t(outputs.size()) == 2); | ||
// Let's use name of output 0 as Unique name | ||
const circle::TensorT &output_tensor = *tensors[outputs[0]]; | ||
node->name(tensor_name(output_tensor)); | ||
|
||
// Create virtual outputs of Unique | ||
for (int32_t n = 0; n < 2; ++n) | ||
{ | ||
const circle::TensorT &output_tensor = *tensors[outputs[n]]; | ||
|
||
auto *nodeout = graph->nodes()->create<CircleUniqueOut>(); | ||
copy_tensor_attributes(output_tensor, nodeout); | ||
// mark shape_status | ||
if (tensors_ptr->Get(outputs[n])->shape() == nullptr) | ||
nodeout->shape_status(ShapeStatus::NOSHAPE); | ||
else | ||
nodeout->shape_status(ShapeStatus::VALID); | ||
|
||
nodeout->input(node); | ||
nodeout->index(n); | ||
|
||
context->nodefinder()->enroll(outputs[n], nodeout); | ||
} | ||
} | ||
|
||
} // namespace luci |