From: 이한종/On-Device Lab(SR)/Engineer/삼성전자 Date: Mon, 25 Feb 2019 09:21:41 +0000 (+0900) Subject: [neurun] Introduce FunctionSequence (#4473) X-Git-Tag: submit/tizen/20190325.013700~211 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=526eeac3c42f52c8118069233aa6d072f95dd87b;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Introduce FunctionSequence (#4473) Introduce `exec::FunctionSequence` class which is a linear composite of `IFunction`. Signed-off-by: Hanjoung Lee --- 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__