From: 남궁석/On-Device Lab(SR)/Engineer/삼성전자 Date: Thu, 25 Apr 2019 04:28:14 +0000 (+0900) Subject: [moco/ONNX] Introduce Identity operation (#3365) X-Git-Tag: nncc_backup~666 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0efc37aba7af76da188a1ae9531e349937962bc8;p=platform%2Fcore%2Fml%2Fnnfw.git [moco/ONNX] Introduce Identity operation (#3365) This commit will introduce Identity operation and add it to GraphBuilderRegisry Signed-off-by: Seok NamKoong --- diff --git a/contrib/moco/lib/frontend/onnx/src/GraphBuilderRegistry.h b/contrib/moco/lib/frontend/onnx/src/GraphBuilderRegistry.h index fa0fec7..1bf4d95 100644 --- a/contrib/moco/lib/frontend/onnx/src/GraphBuilderRegistry.h +++ b/contrib/moco/lib/frontend/onnx/src/GraphBuilderRegistry.h @@ -50,17 +50,29 @@ public: return me; } -private: - GraphBuilderRegistry() +public: + void add(const std::string op, std::unique_ptr &&builder) { - // TODO add operations + _builder_map[op] = std::move(builder); } private: - std::map> _builder_map; + std::map> _builder_map; }; } // namespace onnx } // namespace moco +#include + +#define REGISTER_OP_BUILDER(NAME, BUILDER) \ + namespace \ + { \ + __attribute__((constructor)) void reg_op(void) \ + { \ + std::unique_ptr builder = stdex::make_unique(); \ + moco::onnx::GraphBuilderRegistry::get().add(#NAME, std::move(builder)); \ + } \ + } + #endif // __MOCO_FRONTEND_ONNX_GRAPH_BUILDER_REGISTRY_H__ diff --git a/contrib/moco/lib/frontend/onnx/src/Op/Identity.cpp b/contrib/moco/lib/frontend/onnx/src/Op/Identity.cpp new file mode 100644 index 0000000..71df7b5 --- /dev/null +++ b/contrib/moco/lib/frontend/onnx/src/Op/Identity.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2019 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 "GraphBuilder.h" + +#include + +namespace moco +{ +namespace onnx +{ + +/** + * @brief GraphBuilder for Identity node + */ +class IdentityGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ::onnx::NodeProto &) const override; + void build(const ::onnx::NodeProto &, GraphBuilderContext *) const override; +}; + +bool IdentityGraphBuilder::validate(const ::onnx::NodeProto &node) const { return true; } + +void IdentityGraphBuilder::build(const ::onnx::NodeProto &node, GraphBuilderContext *context) const +{ + assert(context != nullptr); + + loco::Graph *graph = context->graph(); + SymbolTable *nodes = context->nodes(); + SymbolTable *input_names = context->input_names(); + + // Create a "Forward" node for Identity + auto forward_node = graph->nodes()->create(); + + nodes->enroll(node.name(), forward_node); + + // Record all inputs to forward_node + for (int i = 0; i < node.input_size(); ++i) + { + const auto &input_name = node.input(i); + input_names->list(forward_node, input_name); + } +} + +} // namespace onnx +} // namespace moco + +#include "GraphBuilderRegistry.h" + +REGISTER_OP_BUILDER(Identity, IdentityGraphBuilder)