From 98ffff81b91f4cec5d4a0310de1d4c746d704b2d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=B2=9C=EA=B5=90/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 9 May 2019 10:46:31 +0900 Subject: [PATCH] [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 --- contrib/locomotiv/src/Node/Pull.cpp | 34 ++++++++++++++++++++++ contrib/locomotiv/src/Node/Pull.test.cpp | 48 ++++++++++++++++++++++++++++++++ contrib/locomotiv/src/NodeExecution.cpp | 13 ++++++--- contrib/locomotiv/src/NodeExecution.h | 1 + 4 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 contrib/locomotiv/src/Node/Pull.cpp create mode 100644 contrib/locomotiv/src/Node/Pull.test.cpp 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 *); }; -- 2.7.4