Compute Library
 21.05
GraphContext.h
Go to the documentation of this file.
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_CONTEXT_H
25 #define ARM_COMPUTE_GRAPH_GRAPH_CONTEXT_H
26 
28 
31 
32 #include <map>
33 #include <memory>
34 
35 namespace arm_compute
36 {
37 namespace graph
38 {
39 /** Contains structs required for memory management */
41 {
42  Target target = { Target::UNSPECIFIED }; /**< Target */
43  std::shared_ptr<arm_compute::IMemoryManager> intra_mm = { nullptr }; /**< Intra-function memory manager */
44  std::shared_ptr<arm_compute::IMemoryManager> cross_mm = { nullptr }; /**< Cross-function memory manager */
45  std::shared_ptr<arm_compute::IMemoryGroup> cross_group = { nullptr }; /**< Cross-function memory group */
46  IAllocator *allocator = { nullptr }; /**< Backend allocator to use */
47 };
48 
49 /** Contains structs required for weights management */
51 {
52  Target target = { Target::UNSPECIFIED }; /**< Target */
53  std::shared_ptr<arm_compute::IWeightsManager> wm = { nullptr }; /**< Weights manager */
54 };
55 
56 /** Graph context **/
57 class GraphContext final
58 {
59 public:
60  /** Constructor */
61  GraphContext();
62  /** Destructor */
63  ~GraphContext();
64  /** Prevent instances of this class from being copied (As this class contains pointers) */
65  GraphContext(const GraphContext &) = delete;
66  /** Default move constructor */
67  GraphContext(GraphContext &&) = default;
68  /** Prevent instances of this class from being copied (As this class contains pointers) */
69  GraphContext &operator=(const GraphContext &) = delete;
70  /** Default move assignment operator */
71  GraphContext &operator=(GraphContext &&) = default;
72  /** Graph configuration accessor
73  *
74  * @note Every alteration has to be done before graph finalization
75  *
76  * @return The graph configuration
77  */
78  const GraphConfig &config() const;
79  /** Sets graph configuration
80  *
81  * @param[in] config Configuration to use
82  */
83  void set_config(const GraphConfig &config);
84  /** Inserts a memory manager context
85  *
86  * @param[in] memory_ctx Memory manage context
87  *
88  * @return True if the insertion succeeded else false
89  */
91  /** Gets a memory manager context for a given target
92  *
93  * @param[in] target To retrieve the management context
94  *
95  * @return Management context for the target if exists else nullptr
96  */
98  /** Gets the memory managers map
99  *
100  * @return Memory manager contexts
101  */
102  std::map<Target, MemoryManagerContext> &memory_managers();
103  /** Inserts a weights manager context
104  *
105  * @param[in] weights_ctx Weights manager context
106  *
107  * @return True if the insertion succeeded else false
108  */
110 
111  /** Gets a weights manager context for a given target
112  *
113  * @param[in] target To retrieve the weights management context
114  *
115  * @return Management context for the target if exists else nullptr
116  */
118 
119  /** Gets the weights managers map
120  *
121  * @return Weights manager contexts
122  */
123  std::map<Target, WeightsManagerContext> &weights_managers();
124  /** Finalizes memory managers in graph context */
125  void finalize();
126 
127 private:
128  GraphConfig _config; /**< Graph configuration */
129  std::map<Target, MemoryManagerContext> _memory_managers; /**< Memory managers for each target */
130  std::map<Target, WeightsManagerContext> _weights_managers; /**< Weights managers for each target */
131 };
132 } // namespace graph
133 } // namespace arm_compute
134 #endif /* ARM_COMPUTE_GRAPH_GRAPH_CONTEXT_H */
Graph configuration structure Device target types.
Definition: Types.h:83
std::map< Target, WeightsManagerContext > & weights_managers()
Gets the weights managers map.
std::map< Target, MemoryManagerContext > & memory_managers()
Gets the memory managers map.
bool insert_weights_management_ctx(WeightsManagerContext &&weights_ctx)
Inserts a weights manager context.
std::shared_ptr< arm_compute::IMemoryGroup > cross_group
Cross-function memory group.
Definition: GraphContext.h:45
bool insert_memory_management_ctx(MemoryManagerContext &&memory_ctx)
Inserts a memory manager context.
WeightsManagerContext * weights_management_ctx(Target target)
Gets a weights manager context for a given target.
Copyright (c) 2017-2021 Arm Limited.
void set_config(const GraphConfig &config)
Sets graph configuration.
GraphContext & operator=(const GraphContext &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
void finalize()
Finalizes memory managers in graph context.
std::shared_ptr< arm_compute::IMemoryManager > intra_mm
Intra-function memory manager.
Definition: GraphContext.h:43
const GraphConfig & config() const
Graph configuration accessor.
std::shared_ptr< arm_compute::IMemoryManager > cross_mm
Cross-function memory manager.
Definition: GraphContext.h:44
Contains structs required for weights management.
Definition: GraphContext.h:50
Contains structs required for memory management.
Definition: GraphContext.h:40
Allocator interface.
Definition: IAllocator.h:35
IAllocator * allocator
Backend allocator to use.
Definition: GraphContext.h:46
MemoryManagerContext * memory_management_ctx(Target target)
Gets a memory manager context for a given target.
std::shared_ptr< arm_compute::IWeightsManager > wm
Weights manager.
Definition: GraphContext.h:53