Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H |
| 25 | #define ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 26 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 27 | #include "arm_compute/graph/IDeviceBackend.h" |
| 28 | #include "arm_compute/graph/Types.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 29 | #include "support/MemorySupport.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 30 | |
| 31 | #include <map> |
| 32 | #include <memory> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 36 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 37 | { |
| 38 | namespace backends |
| 39 | { |
| 40 | /** Registry holding all the supported backends */ |
| 41 | class BackendRegistry final |
| 42 | { |
| 43 | public: |
| 44 | /** Gets backend registry instance |
| 45 | * |
| 46 | * @return Backend registry instance |
| 47 | */ |
| 48 | static BackendRegistry &get(); |
| 49 | /** Finds a backend in the registry |
| 50 | * |
| 51 | * @param[in] target Backend target |
| 52 | * |
| 53 | * @return Pointer to the backend interface if found, else nullptr |
| 54 | */ |
| 55 | IDeviceBackend *find_backend(Target target); |
Anthony Barbier | 890ad1b | 2018-08-22 13:44:36 +0100 | [diff] [blame] | 56 | |
| 57 | /** Get a backend from the registry |
| 58 | * |
| 59 | * The backend must be present and supported. |
| 60 | * |
| 61 | * @param[in] target Backend target |
| 62 | * |
| 63 | * @return Reference to the backend interface |
| 64 | */ |
| 65 | IDeviceBackend &get_backend(Target target); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 66 | /** Checks if a backend for a given target exists |
| 67 | * |
| 68 | * @param[in] target Execution target |
| 69 | * |
| 70 | * @return True if exists else false |
| 71 | */ |
| 72 | bool contains(Target target) const; |
| 73 | /** Backends accessor |
| 74 | * |
| 75 | * @return Map containing the registered backends |
| 76 | */ |
| 77 | const std::map<Target, std::unique_ptr<IDeviceBackend>> &backends() const; |
| 78 | /** Registers a backend to the registry |
| 79 | * |
| 80 | * @param[in] target Execution target to register for |
| 81 | */ |
| 82 | template <typename T> |
| 83 | void add_backend(Target target); |
| 84 | |
| 85 | private: |
| 86 | /** Default Constructor */ |
| 87 | BackendRegistry(); |
| 88 | |
| 89 | private: |
| 90 | std::map<Target, std::unique_ptr<IDeviceBackend>> _registered_backends; |
| 91 | }; |
| 92 | |
| 93 | template <typename T> |
| 94 | inline void BackendRegistry::add_backend(Target target) |
| 95 | { |
| 96 | _registered_backends[target] = support::cpp14::make_unique<T>(); |
| 97 | } |
| 98 | } // namespace backends |
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 |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 101 | #endif /* ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H */ |