blob: 5b4533cb6f673cd5b02b3921e74e1108b868e5f6 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitasd8734b52017-12-22 15:27:52 +00003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_GRAPH_WORKLOAD_H
25#define ARM_COMPUTE_GRAPH_WORKLOAD_H
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010027#include "arm_compute/graph/GraphContext.h"
Giorgio Arena6e9d0e02020-01-03 15:02:04 +000028#include "arm_compute/graph/Tensor.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000029#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010030#include "arm_compute/runtime/IMemoryGroup.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000031
Georgios Pinitase29e0d42018-05-10 12:31:54 +010032#include <functional>
Georgios Pinitasd8734b52017-12-22 15:27:52 +000033#include <memory>
34#include <vector>
35
36namespace arm_compute
37{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010038namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000039{
40// Forward declarations
41class ITensorHandle;
42class INode;
Georgios Pinitase0437672018-05-02 14:07:55 +010043class Graph;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000044
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010045struct ExecutionTask;
46
47void execute_task(ExecutionTask &task);
48
49/** Task executor */
50class TaskExecutor final
51{
52private:
53 /** Default constructor **/
54 TaskExecutor();
55
56public:
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
Georgios Pinitasd8734b52017-12-22 15:27:52 +000066/** Execution task
67 *
68 * Contains all the information required to execute a given task
69 */
70struct ExecutionTask
71{
Georgios Pinitas3ba0ab12018-12-12 19:01:46 +000072 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 */
85 ~ExecutionTask() = default;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000086 // TODO (geopin01) : Support vector of functions?
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010087 std::unique_ptr<arm_compute::IFunction> task = {}; /**< Task to execute */
88 INode *node = {}; /**< Node bound to this workload */
Georgios Pinitasd8734b52017-12-22 15:27:52 +000089
90 /** Function operator */
91 void operator()();
Georgios Pinitase0437672018-05-02 14:07:55 +010092
93 /** Prepare execution task */
94 void prepare();
Georgios Pinitasd8734b52017-12-22 15:27:52 +000095};
96
97/** Execution workload */
98struct ExecutionWorkload
99{
Georgios Pinitas3d1489d2018-05-03 20:47:16 +0100100 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 */
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000105};
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100106} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000107} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000108#endif /* ARM_COMPUTE_GRAPH_WORKLOAD_H */