blob: 69114ed26de5450034a0ba11abc40c2877bc00b8 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
2 * Copyright (c) 2018 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 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010024#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#include "support/ToolchainSupport.h"
30
31#include <map>
32#include <memory>
33
34namespace arm_compute
35{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010036namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000037{
38namespace backends
39{
40/** Registry holding all the supported backends */
41class BackendRegistry final
42{
43public:
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);
56 /** Checks if a backend for a given target exists
57 *
58 * @param[in] target Execution target
59 *
60 * @return True if exists else false
61 */
62 bool contains(Target target) const;
63 /** Backends accessor
64 *
65 * @return Map containing the registered backends
66 */
67 const std::map<Target, std::unique_ptr<IDeviceBackend>> &backends() const;
68 /** Registers a backend to the registry
69 *
70 * @param[in] target Execution target to register for
71 */
72 template <typename T>
73 void add_backend(Target target);
74
75private:
76 /** Default Constructor */
77 BackendRegistry();
78
79private:
80 std::map<Target, std::unique_ptr<IDeviceBackend>> _registered_backends;
81};
82
83template <typename T>
84inline void BackendRegistry::add_backend(Target target)
85{
86 _registered_backends[target] = support::cpp14::make_unique<T>();
87}
88} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010089} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000090} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010091#endif /* __ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H__ */