From: 박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 Date: Mon, 26 Aug 2019 07:25:42 +0000 (+0900) Subject: [logo] Introduce PhaseRunner (#6909) X-Git-Tag: accepted/tizen/unified/20190903.052428~136 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0303810e6d00980d9871e518d7fbcf23ea1dbbc9;p=platform%2Fcore%2Fml%2Fnnfw.git [logo] Introduce PhaseRunner (#6909) This will introduce PhaseRunner that runs group of Pass(es) that is defined as a Phase Signed-off-by: SaeHie Park --- diff --git a/compiler/logo/include/logo/Phase.h b/compiler/logo/include/logo/Phase.h new file mode 100644 index 0000000..1a1a6f0 --- /dev/null +++ b/compiler/logo/include/logo/Phase.h @@ -0,0 +1,75 @@ +/* + * 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 __LOGO_PHASE_H__ +#define __LOGO_PHASE_H__ + +#include + +#include + +#include +#include + +namespace logo +{ + +// Phase is a collection of Pass(es) +using Phase = std::vector>; + +enum class PhaseStrategy +{ + // Run all the passes until there is no pass that makes a change + Saturate, + // Same as Saturate but will restart from the first when there is a change + Restart, +}; + +template class PhaseRunner; + +template <> class PhaseRunner +{ +public: + PhaseRunner(loco::Graph *graph) : _graph{graph} + { + // DO NOTHING + } + +public: + void run(const Phase &) const; + +private: + loco::Graph *_graph; +}; + +template <> class PhaseRunner +{ +public: + PhaseRunner(loco::Graph *graph) : _graph{graph} + { + // DO NOTHING + } + +public: + void run(const Phase &) const; + +private: + loco::Graph *_graph; +}; + +} // namespace logo + +#endif // __LOGO_PHASE_H__ diff --git a/compiler/logo/src/Phase.cpp b/compiler/logo/src/Phase.cpp new file mode 100644 index 0000000..6964302 --- /dev/null +++ b/compiler/logo/src/Phase.cpp @@ -0,0 +1,57 @@ +/* + * 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 + +namespace logo +{ + +void PhaseRunner::run(const Phase &phase) const +{ + for (bool changed = true; changed;) + { + changed = false; + + for (auto &pass : phase) + { + bool pass_changed = pass->run(_graph); + changed = changed || pass_changed; + } + } +} + +void PhaseRunner::run(const Phase &phase) const +{ + for (bool changed = true; changed;) + { + changed = false; + + for (auto &pass : phase) + { + if (pass->run(_graph)) + { + changed = true; + } + + if (changed) + { + break; + } + } + } +} + +} // namespace logo