Compute Library
 21.05
Workload.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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_WORKLOAD_H
25 #define ARM_COMPUTE_GRAPH_WORKLOAD_H
26 
31 
32 #include <functional>
33 #include <memory>
34 #include <vector>
35 
36 namespace arm_compute
37 {
38 namespace graph
39 {
40 // Forward declarations
41 class ITensorHandle;
42 class INode;
43 class Graph;
44 
45 struct ExecutionTask;
46 
47 void execute_task(ExecutionTask &task);
48 
49 /** Task executor */
50 class TaskExecutor final
51 {
52 private:
53  /** Default constructor **/
54  TaskExecutor();
55 
56 public:
57  /** Task executor accessor
58  *
59  * @return Task executor instance
60  */
61  static TaskExecutor &get();
62  /** Function that is responsible for executing tasks */
63  std::function<decltype(execute_task)> execute_function;
64 };
65 
66 /** Execution task
67  *
68  * Contains all the information required to execute a given task
69  */
71 {
72  ExecutionTask(std::unique_ptr<arm_compute::IFunction> &&f, INode *n)
73  : task(std::move(f)), node(n)
74  {
75  }
76  /** Prevent instances of this class from being copied (As this class contains pointers) */
77  ExecutionTask(const ExecutionTask &) = delete;
78  /** Prevent instances of this class from being copied (As this class contains pointers) */
79  ExecutionTask &operator=(const ExecutionTask &) = delete;
80  /** Default Move Constructor. */
81  ExecutionTask(ExecutionTask &&) noexcept = default;
82  /** Default move assignment operator */
83  ExecutionTask &operator=(ExecutionTask &&) noexcept = default;
84  /** Default destructor */
86  // TODO (geopin01) : Support vector of functions?
87  std::unique_ptr<arm_compute::IFunction> task = {}; /**< Task to execute */
88  INode *node = {}; /**< Node bound to this workload */
89 
90  /** Function operator */
91  void operator()();
92 
93  /** Prepare execution task */
94  void prepare();
95 };
96 
97 /** Execution workload */
99 {
100  std::vector<Tensor *> inputs = {}; /**< Input handles */
101  std::vector<Tensor *> outputs = {}; /**< Output handles */
102  std::vector<ExecutionTask> tasks = {}; /**< Execution workload */
103  Graph *graph = { nullptr }; /**< Graph bound to the workload */
104  GraphContext *ctx = { nullptr }; /**< Graph execution context */
105 };
106 } // namespace graph
107 } // namespace arm_compute
108 #endif /* ARM_COMPUTE_GRAPH_WORKLOAD_H */
std::vector< Tensor * > inputs
Input handles.
Definition: Workload.h:100
void operator()()
Function operator.
Definition: Workload.cpp:36
Base class for all functions.
Definition: IFunction.h:30
void prepare()
Prepare execution task.
Definition: Workload.cpp:62
Copyright (c) 2017-2021 Arm Limited.
std::unique_ptr< arm_compute::IFunction > task
Task to execute.
Definition: Workload.h:87
Node interface.
Definition: INode.h:45
std::vector< ExecutionTask > tasks
Execution workload.
Definition: Workload.h:102
void execute_task(ExecutionTask &task)
Definition: Workload.cpp:41
ExecutionTask(std::unique_ptr< arm_compute::IFunction > &&f, INode *n)
Definition: Workload.h:72
ExecutionTask & operator=(const ExecutionTask &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
static TaskExecutor & get()
Task executor accessor.
Definition: Workload.cpp:75
Graph * graph
Graph bound to the workload.
Definition: Workload.h:103
Graph class.
Definition: Graph.h:53
GraphContext * ctx
Graph execution context.
Definition: Workload.h:104
INode * node
Node bound to this workload.
Definition: Workload.h:88
std::vector< Tensor * > outputs
Output handles.
Definition: Workload.h:101
std::function< decltype(execute_task)> execute_function
Function that is responsible for executing tasks.
Definition: Workload.h:63