From: 박천교/On-Device Lab(SR)/Engineer/삼성전자 Date: Thu, 9 May 2019 01:46:31 +0000 (+0900) Subject: [locomotiv] Support Pull node (#3415) X-Git-Tag: nncc_backup~633 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98ffff81b91f4cec5d4a0310de1d4c746d704b2d;p=platform%2Fcore%2Fml%2Fnnfw.git [locomotiv] Support Pull node (#3415) This commit introduces support for Pull node execution. Pull node basically do nothing, but aborts if input data annotation not ready. Signed-off-by: Cheongyo Bahk --- diff --git a/contrib/locomotiv/src/Node/Pull.cpp b/contrib/locomotiv/src/Node/Pull.cpp new file mode 100644 index 0000000..b5b49a6 --- /dev/null +++ b/contrib/locomotiv/src/Node/Pull.cpp @@ -0,0 +1,34 @@ +/* + * 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 "NodeExecution.h" + +#include "NodeDataImpl.h" + +#include + +namespace locomotiv +{ + +void NodeExecution::execute(loco::Pull *pull) +{ + if (!annot_data(pull)) + { + throw std::runtime_error("Input data for Pull node not ready"); + } +} + +} // namespace locomotiv diff --git a/contrib/locomotiv/src/Node/Pull.test.cpp b/contrib/locomotiv/src/Node/Pull.test.cpp new file mode 100644 index 0000000..7dd748d --- /dev/null +++ b/contrib/locomotiv/src/Node/Pull.test.cpp @@ -0,0 +1,48 @@ +/* + * 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 "NodeExecution.h" + +#include "locomotiv/NodeData.h" +#include "NodeDataImpl.h" + +#include +#include +#include + +#include + +using nncc::core::ADT::tensor::Shape; +using nncc::core::ADT::tensor::LexicalLayout; +using nncc::core::ADT::tensor::make_buffer; + +TEST(NodeExecution_Pull, check_data_ready) +{ + // Make graph with Pull node only + auto g = loco::make_graph(); + auto pull = g->nodes()->create(); + + // Data not ready yet + ASSERT_ANY_THROW(locomotiv::NodeExecution::get().run(pull)); + + // Make and assign data to pull node + auto pull_buf = make_buffer(Shape{1}); + auto pull_data = locomotiv::make_data(pull_buf); + locomotiv::annot_data(pull, std::move(pull_data)); + + // Valid run + ASSERT_NO_THROW(locomotiv::NodeExecution::get().run(pull)); +} diff --git a/contrib/locomotiv/src/NodeExecution.cpp b/contrib/locomotiv/src/NodeExecution.cpp index 5330810..5cdf787 100644 --- a/contrib/locomotiv/src/NodeExecution.cpp +++ b/contrib/locomotiv/src/NodeExecution.cpp @@ -24,14 +24,19 @@ namespace locomotiv // TODO Use visitor pattern of loco when available void NodeExecution::run(loco::Node *node) { - if (as(node)) + if (as(node)) { - execute(as(node)); + execute(as(node)); + return; } - else + + if (as(node)) { - throw std::runtime_error("Not supported loco::Node type"); + execute(as(node)); + return; } + + throw std::runtime_error("Not supported loco::Node type"); } } // namespace locomotiv diff --git a/contrib/locomotiv/src/NodeExecution.h b/contrib/locomotiv/src/NodeExecution.h index 8065bc9..0b3e7a3 100644 --- a/contrib/locomotiv/src/NodeExecution.h +++ b/contrib/locomotiv/src/NodeExecution.h @@ -51,6 +51,7 @@ private: * * @note Definitions of overloaded execute() are in 'Node/' directory */ + void execute(loco::Pull *); void execute(loco::Push *); };