From 2e335e8c36f582389ed0c66cc2e5cf05d7fc2801 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: Wed, 8 May 2019 10:29:58 +0900 Subject: [PATCH] [locomotiv] Introduce NodeExecution helper class (#3402) This commit introduces NodeExecution class. This class serves as helper class for Session::infer(). This class is responsible to calculate one specific node. Signed-off-by: Cheongyo Bahk --- contrib/locomotiv/CMakeLists.txt | 1 + contrib/locomotiv/src/Node/Push.cpp | 30 +++++++++++++++++ contrib/locomotiv/src/NodeExecution.cpp | 37 +++++++++++++++++++++ contrib/locomotiv/src/NodeExecution.h | 59 +++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 contrib/locomotiv/src/Node/Push.cpp create mode 100644 contrib/locomotiv/src/NodeExecution.cpp create mode 100644 contrib/locomotiv/src/NodeExecution.h diff --git a/contrib/locomotiv/CMakeLists.txt b/contrib/locomotiv/CMakeLists.txt index 27afa0d..d3a64a4 100644 --- a/contrib/locomotiv/CMakeLists.txt +++ b/contrib/locomotiv/CMakeLists.txt @@ -4,6 +4,7 @@ list(REMOVE_ITEM SOURCES ${TESTS}) add_library(locomotiv SHARED ${SOURCES}) target_include_directories(locomotiv PUBLIC include) +target_include_directories(locomotiv PRIVATE src) target_link_libraries(locomotiv PUBLIC loco) target_link_libraries(locomotiv PUBLIC angkor) # Let's apply nncc common compile options diff --git a/contrib/locomotiv/src/Node/Push.cpp b/contrib/locomotiv/src/Node/Push.cpp new file mode 100644 index 0000000..c4c5fcd --- /dev/null +++ b/contrib/locomotiv/src/Node/Push.cpp @@ -0,0 +1,30 @@ +/* + * 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 + +namespace locomotiv +{ + +void NodeExecution::execute(loco::Push *) +{ + // to be filled + throw std::runtime_error("NYI"); +} + +} // namespace locomotiv diff --git a/contrib/locomotiv/src/NodeExecution.cpp b/contrib/locomotiv/src/NodeExecution.cpp new file mode 100644 index 0000000..5330810 --- /dev/null +++ b/contrib/locomotiv/src/NodeExecution.cpp @@ -0,0 +1,37 @@ +/* + * 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 + +namespace locomotiv +{ + +// TODO Use visitor pattern of loco when available +void NodeExecution::run(loco::Node *node) +{ + if (as(node)) + { + execute(as(node)); + } + else + { + 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 new file mode 100644 index 0000000..8065bc9 --- /dev/null +++ b/contrib/locomotiv/src/NodeExecution.h @@ -0,0 +1,59 @@ +/* + * 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. + */ + +#ifndef _LOCOMOTIV_NODEEXECUTION_H_ +#define _LOCOMOTIV_NODEEXECUTION_H_ + +#include + +namespace locomotiv +{ + +/** + * @brief Helper class for Session, responsible to process one node calculation. + */ +class NodeExecution +{ +public: + /// @brief Run calculation for one unspecified Node + void run(loco::Node *node); + + static NodeExecution &get() + { + static NodeExecution me; + return me; + } + +private: + NodeExecution() {} + + template Derived *as(loco::Node *node) + { + return dynamic_cast(node); + } + + /** + * @brief Calculate for one specified node and update its result as NodeData. + * Abort program when its ingredients are not ready or not supported. + * + * @note Definitions of overloaded execute() are in 'Node/' directory + */ + void execute(loco::Push *); +}; + +} // namespace locomotiv + +#endif // _LOCOMOTIV_NODEEXECUTION_H_ -- 2.7.4