Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_GRAPH_WORKLOAD_H |
| 25 | #define ARM_COMPUTE_GRAPH_WORKLOAD_H |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 26 | |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 27 | #include "arm_compute/graph/GraphContext.h" |
Giorgio Arena | 6e9d0e0 | 2020-01-03 15:02:04 +0000 | [diff] [blame] | 28 | #include "arm_compute/graph/Tensor.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 29 | #include "arm_compute/runtime/IFunction.h" |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/IMemoryGroup.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 31 | |
Georgios Pinitas | e29e0d4 | 2018-05-10 12:31:54 +0100 | [diff] [blame] | 32 | #include <functional> |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 33 | #include <memory> |
| 34 | #include <vector> |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 38 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 39 | { |
| 40 | // Forward declarations |
| 41 | class ITensorHandle; |
| 42 | class INode; |
Georgios Pinitas | e043767 | 2018-05-02 14:07:55 +0100 | [diff] [blame] | 43 | class Graph; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 44 | |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 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 | |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 66 | /** Execution task |
| 67 | * |
| 68 | * Contains all the information required to execute a given task |
| 69 | */ |
| 70 | struct ExecutionTask |
| 71 | { |
Georgios Pinitas | 3ba0ab1 | 2018-12-12 19:01:46 +0000 | [diff] [blame] | 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 */ |
| 85 | ~ExecutionTask() = default; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 86 | // TODO (geopin01) : Support vector of functions? |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 87 | std::unique_ptr<arm_compute::IFunction> task = {}; /**< Task to execute */ |
| 88 | INode *node = {}; /**< Node bound to this workload */ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 89 | |
| 90 | /** Function operator */ |
| 91 | void operator()(); |
Georgios Pinitas | e043767 | 2018-05-02 14:07:55 +0100 | [diff] [blame] | 92 | |
| 93 | /** Prepare execution task */ |
| 94 | void prepare(); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | /** Execution workload */ |
| 98 | struct ExecutionWorkload |
| 99 | { |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 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 */ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 105 | }; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 106 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 107 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 108 | #endif /* ARM_COMPUTE_GRAPH_WORKLOAD_H */ |