Compute Library
 23.08
GraphContext.cpp
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  */
25 
26 #include "arm_compute/graph.h"
29 
30 namespace arm_compute
31 {
32 namespace graph
33 {
35  : _config(), _memory_managers(), _weights_managers()
36 {
37 }
38 
40 {
41  _memory_managers.clear();
42  _weights_managers.clear();
44 }
45 
47 {
48  return _config;
49 }
50 
52 {
53  _config = config;
54 }
55 
57 {
58  Target target = memory_ctx.target;
59  if(target == Target::UNSPECIFIED || _memory_managers.find(target) != std::end(_memory_managers))
60  {
61  return false;
62  }
63 
64  _memory_managers[target] = std::move(memory_ctx);
65  return true;
66 }
67 
69 {
70  return (_memory_managers.find(target) != std::end(_memory_managers)) ? &_memory_managers[target] : nullptr;
71 }
72 
73 std::map<Target, MemoryManagerContext> &GraphContext::memory_managers()
74 {
75  return _memory_managers;
76 }
77 
79 {
80  Target target = weights_managers.target;
81 
82  if(_weights_managers.find(target) != std::end(_weights_managers))
83  {
84  return false;
85  }
86 
87  _weights_managers[target] = std::move(weights_managers);
88 
89  return true;
90 }
91 
93 {
94  return (_weights_managers.find(target) != std::end(_weights_managers)) ? &_weights_managers[target] : nullptr;
95 }
96 
97 std::map<Target, WeightsManagerContext> &GraphContext::weights_managers()
98 {
99  return _weights_managers;
100 }
101 
103 {
104  const size_t num_pools = 1;
105  for(auto &mm_obj : _memory_managers)
106  {
107  ARM_COMPUTE_ERROR_ON(!mm_obj.second.allocator);
108 
109  // Finalize intra layer memory manager
110  if(mm_obj.second.intra_mm != nullptr)
111  {
112  mm_obj.second.intra_mm->populate(*mm_obj.second.allocator, num_pools);
113  }
114  // Finalize cross layer memory manager
115  if(mm_obj.second.cross_mm != nullptr)
116  {
117  mm_obj.second.cross_mm->populate(*mm_obj.second.allocator, num_pools);
118  }
119  }
120 }
121 } // namespace graph
122 } // namespace arm_compute
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:68
arm_compute::graph::WeightsManagerContext
Contains structs required for weights management.
Definition: GraphContext.h:50
arm_compute::graph::GraphContext::config
const GraphConfig & config() const
Graph configuration accessor.
Definition: GraphContext.cpp:46
GraphContext.h
arm_compute::graph::MemoryManagerContext
Contains structs required for memory management.
Definition: GraphContext.h:40
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:92
arm_compute::graph::GraphContext::finalize
void finalize()
Finalizes memory managers in graph context.
Definition: GraphContext.cpp:102
arm_compute::graph::GraphContext::~GraphContext
~GraphContext()
Destructor.
Definition: GraphContext.cpp:39
arm_compute::graph::GraphContext::insert_memory_management_ctx
bool insert_memory_management_ctx(MemoryManagerContext &&memory_ctx)
Inserts a memory manager context.
Definition: GraphContext.cpp:56
arm_compute::graph::GraphContext::set_config
void set_config(const GraphConfig &config)
Sets graph configuration.
Definition: GraphContext.cpp:51
arm_compute::graph::GraphConfig
Graph configuration structure.
Definition: Types.h:88
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
arm_compute::graph::Target
Target
Definition: Types.h:104
arm_compute::graph::Target::UNSPECIFIED
@ UNSPECIFIED
Unspecified Target.
arm_compute::graph::GraphContext::insert_weights_management_ctx
bool insert_weights_management_ctx(WeightsManagerContext &&weights_ctx)
Inserts a weights manager context.
Definition: GraphContext.cpp:78
BackendRegistry.h
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:73
arm_compute::mlgo::parser::end
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
Utils.h
arm_compute::graph::GraphContext::weights_managers
std::map< Target, WeightsManagerContext > & weights_managers()
Gets the weights managers map.
Definition: GraphContext.cpp:97
arm_compute::graph::release_default_graph_context
void release_default_graph_context(GraphContext &ctx)
Default releases the graph context if not done manually.
Definition: Utils.cpp:108
arm_compute::graph::GraphContext::GraphContext
GraphContext()
Constructor.
Definition: GraphContext.cpp:34
graph.h
Includes all the Graph headers at once.