blob: 8ff0a548aef203222d22c67504efaad37c14e926 [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{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 ExecutionTask(std::unique_ptr<arm_compute::IFunction> &&f, INode *n) : task(std::move(f)), node(n)
Georgios Pinitas3ba0ab12018-12-12 19:01:46 +000073 {
74 }
75 /** Prevent instances of this class from being copied (As this class contains pointers) */
76 ExecutionTask(const ExecutionTask &) = delete;
77 /** Prevent instances of this class from being copied (As this class contains pointers) */
78 ExecutionTask &operator=(const ExecutionTask &) = delete;
79 /** Default Move Constructor. */
80 ExecutionTask(ExecutionTask &&) noexcept = default;
81 /** Default move assignment operator */
82 ExecutionTask &operator=(ExecutionTask &&) noexcept = default;
83 /** Default destructor */
84 ~ExecutionTask() = default;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000085 // TODO (geopin01) : Support vector of functions?
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010086 std::unique_ptr<arm_compute::IFunction> task = {}; /**< Task to execute */
87 INode *node = {}; /**< Node bound to this workload */
Georgios Pinitasd8734b52017-12-22 15:27:52 +000088
89 /** Function operator */
90 void operator()();
Georgios Pinitase0437672018-05-02 14:07:55 +010091
92 /** Prepare execution task */
93 void prepare();
Georgios Pinitasd8734b52017-12-22 15:27:52 +000094};
95
96/** Execution workload */
97struct ExecutionWorkload
98{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010099 std::vector<Tensor *> inputs = {}; /**< Input handles */
100 std::vector<Tensor *> outputs = {}; /**< Output handles */
101 std::vector<ExecutionTask> tasks = {}; /**< Execution workload */
102 Graph *graph = {nullptr}; /**< Graph bound to the workload */
103 GraphContext *ctx = {nullptr}; /**< Graph execution context */
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000104};
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100105} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000106} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000107#endif /* ARM_COMPUTE_GRAPH_WORKLOAD_H */