Georgios Pinitas | 0c29cd3 | 2017-10-18 17:29:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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 | */ |
| 24 | #include "arm_compute/graph/OperationRegistry.h" |
| 25 | |
| 26 | using namespace arm_compute::graph; |
| 27 | |
| 28 | OperationRegistry::OperationRegistry() |
| 29 | : _registered_ops() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | OperationRegistry &OperationRegistry::get() |
| 34 | { |
| 35 | static OperationRegistry instance; |
| 36 | return instance; |
| 37 | } |
| 38 | |
Georgios Pinitas | 407c3e6 | 2017-10-25 18:26:46 +0100 | [diff] [blame] | 39 | IOperation *OperationRegistry::find_operation(OperationType operation, TargetHint target) |
Georgios Pinitas | 0c29cd3 | 2017-10-18 17:29:27 +0100 | [diff] [blame] | 40 | { |
| 41 | ARM_COMPUTE_ERROR_ON(!contains(operation, target)); |
| 42 | auto it = std::find_if(_registered_ops[operation].begin(), _registered_ops[operation].end(), [&](const std::unique_ptr<IOperation> &op) |
| 43 | { |
| 44 | return (op->target() == target); |
| 45 | }); |
| 46 | ARM_COMPUTE_ERROR_ON(it == _registered_ops[operation].end()); |
| 47 | return (*it).get(); |
| 48 | } |
| 49 | |
Georgios Pinitas | 407c3e6 | 2017-10-25 18:26:46 +0100 | [diff] [blame] | 50 | bool OperationRegistry::contains(OperationType operation, TargetHint target) const |
Georgios Pinitas | 0c29cd3 | 2017-10-18 17:29:27 +0100 | [diff] [blame] | 51 | { |
| 52 | auto it = _registered_ops.find(operation); |
| 53 | if(it != _registered_ops.end()) |
| 54 | { |
| 55 | return std::any_of(it->second.begin(), it->second.end(), [&](const std::unique_ptr<IOperation> &op) |
| 56 | { |
| 57 | return (op->target() == target); |
| 58 | }); |
| 59 | } |
| 60 | return false; |
| 61 | } |