blob: 7c11d35faff5606e29ca4c7e043569a602778d9e [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitasd8734b52017-12-22 15:27:52 +00003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H
25#define ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/IDeviceBackend.h"
28#include "arm_compute/graph/Types.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000029
30#include <map>
31#include <memory>
32
33namespace arm_compute
34{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010035namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000036{
37namespace backends
38{
39/** Registry holding all the supported backends */
40class BackendRegistry final
41{
42public:
43 /** Gets backend registry instance
44 *
45 * @return Backend registry instance
46 */
47 static BackendRegistry &get();
48 /** Finds a backend in the registry
49 *
50 * @param[in] target Backend target
51 *
52 * @return Pointer to the backend interface if found, else nullptr
53 */
54 IDeviceBackend *find_backend(Target target);
Anthony Barbier890ad1b2018-08-22 13:44:36 +010055
56 /** Get a backend from the registry
57 *
58 * The backend must be present and supported.
59 *
60 * @param[in] target Backend target
61 *
62 * @return Reference to the backend interface
63 */
64 IDeviceBackend &get_backend(Target target);
Georgios Pinitasd8734b52017-12-22 15:27:52 +000065 /** Checks if a backend for a given target exists
66 *
67 * @param[in] target Execution target
68 *
69 * @return True if exists else false
70 */
71 bool contains(Target target) const;
72 /** Backends accessor
73 *
74 * @return Map containing the registered backends
75 */
76 const std::map<Target, std::unique_ptr<IDeviceBackend>> &backends() const;
77 /** Registers a backend to the registry
78 *
79 * @param[in] target Execution target to register for
80 */
81 template <typename T>
82 void add_backend(Target target);
83
84private:
85 /** Default Constructor */
86 BackendRegistry();
87
88private:
89 std::map<Target, std::unique_ptr<IDeviceBackend>> _registered_backends;
90};
91
92template <typename T>
93inline void BackendRegistry::add_backend(Target target)
94{
Georgios Pinitas40f51a62020-11-21 03:04:18 +000095 _registered_backends[target] = std::make_unique<T>();
Georgios Pinitasd8734b52017-12-22 15:27:52 +000096}
97} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010098} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000099} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000100#endif /* ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H */