Compute Library
 22.05
GraphManager Class Referencefinal

Graph manager class. More...

#include <GraphManager.h>

Public Member Functions

 GraphManager ()
 Default Constructor. More...
 
 GraphManager (const GraphManager &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 GraphManager (GraphManager &&)=default
 Default move constructor. More...
 
GraphManageroperator= (const GraphManager &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
GraphManageroperator= (GraphManager &&)=default
 Default move assignment operator. More...
 
void finalize_graph (Graph &graph, GraphContext &ctx, PassManager &pm, Target target)
 Finalizes a given graph. More...
 
void execute_graph (Graph &graph)
 Executes a graph. More...
 
void invalidate_graph (Graph &graph)
 Invalidates the graph execution workload. More...
 

Detailed Description

Graph manager class.

Manages a list of graphs along with their resources

Definition at line 45 of file GraphManager.h.

Constructor & Destructor Documentation

◆ GraphManager() [1/3]

Default Constructor.

Definition at line 42 of file GraphManager.cpp.

43  : _workloads()
44 {
45 }

◆ GraphManager() [2/3]

GraphManager ( const GraphManager )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ GraphManager() [3/3]

GraphManager ( GraphManager &&  )
default

Default move constructor.

Member Function Documentation

◆ execute_graph()

void execute_graph ( Graph graph)

Executes a graph.

Parameters
[in]graphGraph to execute

Definition at line 125 of file GraphManager.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_LOG_INFO_WITH_FUNCNAME_ACL, arm_compute::graph::detail::call_all_input_node_accessors(), arm_compute::graph::detail::call_all_output_node_accessors(), arm_compute::graph::detail::call_all_tasks(), arm_compute::mlgo::parser::end(), and Graph::id().

Referenced by Stream::run().

126 {
127  ARM_COMPUTE_LOG_INFO_WITH_FUNCNAME_ACL("Initiate graph execution!");
128 
129  // Check if graph is finalized
130  auto it = _workloads.find(graph.id());
131  ARM_COMPUTE_ERROR_ON_MSG(it == std::end(_workloads), "Graph is not registered!");
132 
133  while(true)
134  {
135  // Call input accessors
137  {
138  return;
139  }
140 
141  // Run graph
142  detail::call_all_tasks(it->second);
143 
144  // Call output accessors
146  {
147  return;
148  }
149  }
150 }
#define ARM_COMPUTE_LOG_INFO_WITH_FUNCNAME_ACL(msg)
Log an information message to the logger with function name before the message.
Definition: Log.h:99
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
bool call_all_input_node_accessors(ExecutionWorkload &workload)
Call all input node accessors.
void call_all_tasks(ExecutionWorkload &workload)
Executes all tasks of a workload.
bool call_all_output_node_accessors(ExecutionWorkload &workload)
Call all output node accessors.

◆ finalize_graph()

void finalize_graph ( Graph graph,
GraphContext ctx,
PassManager pm,
Target  target 
)

Finalizes a given graph.

Warning
At this given time finalize_graph will alter the passed graph, plan is to avoid by copying the graph structure, or provide another entry-point for this functionality as it will increase the memory requirements
Parameters
[in]graphGraph to finalize
[in]ctxGraph context
[in]pmPass manager to use for any optimization passes
[in]targetExecution target (Single target execution is currently supported)

Definition at line 47 of file GraphManager.cpp.

References arm_compute::graph::detail::allocate_all_tensors(), arm_compute::graph::detail::allocate_const_tensors(), ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_LOG_GRAPH_INFO, ARM_COMPUTE_LOG_GRAPH_VERBOSE, ARM_COMPUTE_LOG_INFO_WITH_FUNCNAME_ACL, IGraphMutator::Backend, GraphConfig::backend_type, arm_compute::graph::detail::call_all_const_node_accessors(), arm_compute::graph::CL, arm_compute::Clvk, arm_compute::graph::CLVK, GraphContext::config(), arm_compute::graph::detail::configure_all_nodes(), arm_compute::graph::detail::configure_all_tensors(), arm_compute::graph::detail::configure_transition_manager(), arm_compute::graph::dfs(), arm_compute::mlgo::parser::end(), GraphContext::finalize(), arm_compute::graph::force_target_to_graph(), arm_compute::graph::get_default_target(), Graph::id(), IGraphMutator::IR, arm_compute::graph::is_target_supported(), arm_compute::graph::detail::prepare_all_tasks(), PassManager::run_type(), GraphContext::set_config(), arm_compute::graph::setup_requested_backend_context(), GraphConfig::use_transition_memory_manager, arm_compute::graph::detail::validate_all_nodes(), and arm_compute::test::validation::workload.

Referenced by Stream::finalize().

48 {
49  ARM_COMPUTE_LOG_INFO_WITH_FUNCNAME_ACL("Initiate graph configuration!");
50 
51  // Check if graph has been registered
52  if(_workloads.find(graph.id()) != std::end(_workloads))
53  {
54  ARM_COMPUTE_ERROR("Graph is already registered!");
55  }
56 
57  // Apply IR mutating passes
58  pm.run_type(graph, IGraphMutator::MutationType::IR);
59 
60  // Force target to all graph construct
61  Target forced_target = target;
62 
63  // In case CLVK is selected, use the CL backend and
64  // update config
65  if(target == Target::CLVK)
66  {
67  forced_target = Target::CL;
68  GraphConfig config = ctx.config();
69  config.backend_type = CLBackendType::Clvk;
70 
71  ctx.set_config(config);
72  }
73 
74  if(!is_target_supported(target))
75  {
76  forced_target = get_default_target();
77  ARM_COMPUTE_LOG_GRAPH_INFO("Switching target from " << target << " to " << forced_target << std::endl);
78  }
79  force_target_to_graph(graph, forced_target);
80 
81  // Setup backend context
82  setup_requested_backend_context(ctx, forced_target);
83 
84  // Configure all tensors
86 
87  // Apply backend mutating passes
88  pm.run_type(graph, IGraphMutator::MutationType::Backend);
89 
90  // Perform topological sort
91  std::vector<NodeID> topological_sorted_nodes = dfs(graph);
92 
93  // Validate all nodes
95 
96  // Configure all nodes
97  auto workload = detail::configure_all_nodes(graph, ctx, topological_sorted_nodes);
98  ARM_COMPUTE_ERROR_ON_MSG(workload.tasks.empty(), "Could not configure all nodes!");
99 
100  // Allocate const tensors and call accessors
103 
104  // Prepare graph
106 
107  // Setup tensor memory (Allocate all tensors or setup transition manager)
108  if(ctx.config().use_transition_memory_manager)
109  {
111  }
112  else
113  {
115  }
116 
117  // Finalize Graph context
118  ctx.finalize();
119 
120  // Register graph
121  _workloads.insert(std::make_pair(graph.id(), std::move(workload)));
122  ARM_COMPUTE_LOG_GRAPH_VERBOSE("Created workload for graph with ID : " << graph.id() << std::endl);
123 }
void force_target_to_graph(Graph &g, Target target)
Forces a single target to all graph constructs.
Definition: Utils.cpp:52
#define ARM_COMPUTE_LOG_INFO_WITH_FUNCNAME_ACL(msg)
Log an information message to the logger with function name before the message.
Definition: Log.h:99
void configure_transition_manager(Graph &g, GraphContext &ctx, ExecutionWorkload &workload)
Configures transition manager and execution workload.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
void allocate_all_tensors(Graph &g)
Allocates all tensors of a graph.
CLVK capable target device.
void prepare_all_tasks(ExecutionWorkload &workload)
Prepares all tasks for execution.
#define ARM_COMPUTE_LOG_GRAPH_INFO(x)
Definition: Logger.h:54
Target get_default_target()
Returns default target for execution.
Definition: Utils.cpp:39
void configure_all_tensors(Graph &g)
Configures all nodes of a graph.
void validate_all_nodes(Graph &g)
Validates all nodes.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
void setup_requested_backend_context(GraphContext &ctx, Target target)
Setups requested backend context if it exists, is supported and hasn&#39;t been initialized already...
Definition: Utils.cpp:130
bool is_target_supported(Target target)
Checks if a specific target is supported.
Definition: Utils.cpp:34
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
void call_all_const_node_accessors(Graph &g)
Call all const node accessors.
std::vector< NodeID > dfs(Graph &g)
Depth first search traversal.
ExecutionWorkload configure_all_nodes(Graph &g, GraphContext &ctx, const std::vector< NodeID > &node_order)
Configures all nodes of graph.
void allocate_const_tensors(Graph &g)
Allocates const tensor of a given graph.
#define ARM_COMPUTE_LOG_GRAPH_VERBOSE(x)
Definition: Logger.h:50
OpenCL capable target device.

◆ invalidate_graph()

void invalidate_graph ( Graph graph)

Invalidates the graph execution workload.

Parameters
[in]graphGraph to invalidate

Definition at line 152 of file GraphManager.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, arm_compute::mlgo::parser::end(), and Graph::id().

153 {
154  auto it = _workloads.find(graph.id());
155  ARM_COMPUTE_ERROR_ON_MSG(it == std::end(_workloads), "Graph is not registered!");
156 
157  _workloads.erase(it);
158 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290

◆ operator=() [1/2]

GraphManager& operator= ( const GraphManager )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

GraphManager& operator= ( GraphManager &&  )
default

Default move assignment operator.


The documentation for this class was generated from the following files: