xref: /aosp_15_r20/external/ComputeLibrary/arm_compute/graph/GraphManager.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-2019 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 #ifndef ARM_COMPUTE_GRAPH_GRAPH_MANAGER_H
25 #define ARM_COMPUTE_GRAPH_GRAPH_MANAGER_H
26 
27 #include "arm_compute/graph/Types.h"
28 #include "arm_compute/graph/Workload.h"
29 
30 #include <map>
31 
32 namespace arm_compute
33 {
34 namespace graph
35 {
36 // Forward declaration
37 class Graph;
38 class GraphContext;
39 class PassManager;
40 
41 /** Graph manager class
42  *
43  * Manages a list of graphs along with their resources
44  */
45 class GraphManager final
46 {
47 public:
48     /** Default Constructor **/
49     GraphManager();
50     /** Prevent instances of this class from being copied (As this class contains pointers) */
51     GraphManager(const GraphManager &) = delete;
52     /** Default move constructor */
53     GraphManager(GraphManager &&) = default;
54     /** Prevent instances of this class from being copied (As this class contains pointers) */
55     GraphManager &operator=(const GraphManager &) = delete;
56     /** Default move assignment operator */
57     GraphManager &operator=(GraphManager &&) = default;
58     /** Finalizes a given graph
59      *
60      * @warning At this given time finalize_graph will alter the passed graph,
61      *          plan is to avoid by copying the graph structure,
62      *          or provide another entry-point for this functionality as it will increase the memory requirements
63      *
64      * @param[in] graph  Graph to finalize
65      * @param[in] ctx    Graph context
66      * @param[in] pm     Pass manager to use for any optimization passes
67      * @param[in] target Execution target (Single target execution is currently supported)
68      */
69     void finalize_graph(Graph &graph, GraphContext &ctx, PassManager &pm, Target target);
70     /** Executes a graph
71      *
72      * @param[in] graph Graph to execute
73      */
74     void execute_graph(Graph &graph);
75     /** Invalidates the graph execution workload
76      *
77      * @param[in] graph Graph to invalidate
78      */
79     void invalidate_graph(Graph &graph);
80 
81 private:
82     std::map<GraphID, ExecutionWorkload> _workloads = {}; /**< Graph workloads */
83 };
84 } // namespace graph
85 } // namespace arm_compute
86 #endif /* ARM_COMPUTE_GRAPH_GRAPH_MANAGER_H */
87