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