Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | f4261ad | 2019-12-02 11:58:19 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #include "arm_compute/graph/PassManager.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 25 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 26 | #include "arm_compute/graph/Logger.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 27 | |
| 28 | namespace arm_compute |
| 29 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 30 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 31 | { |
| 32 | PassManager::PassManager() |
| 33 | : _passes() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | const std::vector<std::unique_ptr<IGraphMutator>> &PassManager::passes() const |
| 38 | { |
| 39 | return _passes; |
| 40 | } |
| 41 | |
| 42 | IGraphMutator *PassManager::pass(size_t index) |
| 43 | { |
| 44 | return (index >= _passes.size()) ? nullptr : _passes.at(index).get(); |
| 45 | } |
| 46 | |
Georgios Pinitas | 1c32bf396 | 2018-11-12 18:36:19 +0000 | [diff] [blame] | 47 | void PassManager::append(std::unique_ptr<IGraphMutator> pass, bool conditional) |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 48 | { |
Georgios Pinitas | 1c32bf396 | 2018-11-12 18:36:19 +0000 | [diff] [blame] | 49 | if(pass && conditional) |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 50 | { |
| 51 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Appending mutating pass : " << pass->name() << std::endl); |
| 52 | _passes.push_back(std::move(pass)); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void PassManager::clear() |
| 57 | { |
| 58 | _passes.clear(); |
| 59 | } |
| 60 | |
| 61 | void PassManager::run_all(Graph &g) |
| 62 | { |
| 63 | for(auto &pass : _passes) |
| 64 | { |
| 65 | if(pass) |
| 66 | { |
| 67 | ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl); |
| 68 | pass->mutate(g); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
Georgios Pinitas | f4261ad | 2019-12-02 11:58:19 +0000 | [diff] [blame] | 73 | void PassManager::run_type(Graph &g, IGraphMutator::MutationType type) |
| 74 | { |
| 75 | for(auto &pass : _passes) |
| 76 | { |
| 77 | if(pass && (pass->type() == type)) |
| 78 | { |
| 79 | ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl); |
| 80 | pass->mutate(g); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void PassManager::run_index(Graph &g, size_t index) |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 86 | { |
| 87 | if(index >= _passes.size()) |
| 88 | { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | auto &pass = _passes.at(index); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 93 | if(pass != nullptr) |
| 94 | { |
Georgios Pinitas | f4261ad | 2019-12-02 11:58:19 +0000 | [diff] [blame] | 95 | ARM_COMPUTE_LOG_GRAPH_INFO("Running mutating pass : " << pass->name() << std::endl); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 96 | pass->mutate(g); |
| 97 | } |
| 98 | } |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 99 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 100 | } // namespace arm_compute |