From 526eeac3c42f52c8118069233aa6d072f95dd87b Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 25 Feb 2019 18:21:41 +0900 Subject: [PATCH] [neurun] Introduce FunctionSequence (#4473) Introduce `exec::FunctionSequence` class which is a linear composite of `IFunction`. Signed-off-by: Hanjoung Lee --- runtimes/neurun/src/exec/FunctionSequence.cc | 46 ++++++++++++++++++++++++ runtimes/neurun/src/exec/FunctionSequence.h | 52 ++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 runtimes/neurun/src/exec/FunctionSequence.cc create mode 100644 runtimes/neurun/src/exec/FunctionSequence.h diff --git a/runtimes/neurun/src/exec/FunctionSequence.cc b/runtimes/neurun/src/exec/FunctionSequence.cc new file mode 100644 index 0000000..293b98d --- /dev/null +++ b/runtimes/neurun/src/exec/FunctionSequence.cc @@ -0,0 +1,46 @@ +/* + * 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 "FunctionSequence.h" + +namespace neurun +{ +namespace exec +{ + +void FunctionSequence::run() +{ + for (const auto &function : _functions) + { + function->run(); + } +} + +void FunctionSequence::prepare() +{ + for (const auto &function : _functions) + { + function->prepare(); + } +} + +void FunctionSequence::append(std::unique_ptr &&function) +{ + _functions.push_back(std::move(function)); +} + +} // namespace exec +} // namespace neurun diff --git a/runtimes/neurun/src/exec/FunctionSequence.h b/runtimes/neurun/src/exec/FunctionSequence.h new file mode 100644 index 0000000..464d105 --- /dev/null +++ b/runtimes/neurun/src/exec/FunctionSequence.h @@ -0,0 +1,52 @@ +/* + * 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 __NEURUN_EXEC_FUNCTION_SEQUENCE_H__ +#define __NEURUN_EXEC_FUNCTION_SEQUENCE_H__ + +#include +#include + +#include "exec/interface/IFunction.h" + +namespace neurun +{ +namespace exec +{ + +class FunctionSequence : public IFunction +{ +public: + virtual ~FunctionSequence() = default; + + virtual void run() override; + virtual void prepare() override; + + /** + * @brief Appends an IFunction object to the function sequence + * + * @param function IFunction object to be appended + */ + void append(std::unique_ptr &&function); + +private: + std::vector> _functions; +}; + +} // namespace exec +} // namespace neurun + +#endif // __NEURUN_EXEC_FUNCTION_SEQUENCE_H__ -- 2.7.4