Compute Library
 21.05
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
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.
bool insert_memory_management_ctx(MemoryManagerContext &&memory_ctx)
Inserts a memory manager context.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Includes all the Graph headers at once.
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.
void finalize()
Finalizes memory managers in graph context.
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
const GraphConfig & config() const
Graph configuration accessor.
Contains structs required for weights management.
Definition: GraphContext.h:50
Contains structs required for memory management.
Definition: GraphContext.h:40
MemoryManagerContext * memory_management_ctx(Target target)
Gets a memory manager context for a given target.
void release_default_graph_context(GraphContext &ctx)
Default releases the graph context if not done manually.
Definition: Utils.cpp:108