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 27 #include "arm_compute/graph/GraphContext.h" 28 #include "arm_compute/graph/Tensor.h" 29 #include "arm_compute/runtime/IFunction.h" 30 #include "arm_compute/runtime/IMemoryGroup.h" 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 */ 70 struct ExecutionTask 71 { ExecutionTaskExecutionTask72 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; 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 */ 98 struct ExecutionWorkload 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 */ 109