Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / exec / IExecutor.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file  IExecutor.h
19  * @brief This file defines interface of Executor
20  */
21 #ifndef __ONERT_EXEC_I_EXECUTOR_H__
22 #define __ONERT_EXEC_I_EXECUTOR_H__
23
24 #include "ir/Graph.h"
25 #include "IFunction.h"
26 #include "IODescription.h"
27 #include "ir/Index.h"
28 #include "ir/OperationIndexMap.h"
29
30 #include <cstdint>
31 #include <memory>
32 #include <unordered_map>
33
34 namespace onert
35 {
36 namespace backend
37 {
38 class IPortableTensor;
39 namespace controlflow
40 {
41 class IOTensor;
42 }
43 }
44 }
45 namespace onert
46 {
47 namespace exec
48 {
49 class IExecutionObserver;
50 /**
51  * @brief Struct to define interface of Executor
52  */
53 struct IExecutor
54 {
55   /**
56    * @brief Construct a new IExecutor object
57    */
58   IExecutor() = default;
59   /**
60    * @brief Destroy the IExecutor object
61    */
62   virtual ~IExecutor() = default;
63
64   /**
65    * @brief Returns graph object
66    *
67    * @return Graph object
68    */
69   virtual const ir::Graph &graph() = 0;
70
71   /**
72    * @brief     Set an ordering on operations
73    * @param[in] ranks   The table encoding the ordering
74    */
75   virtual void setIndexedRanks(std::shared_ptr<ir::OperationIndexMap<int64_t>>) = 0;
76
77   /**
78    * @brief     Execute with user-given input/output description (for primary subgraph)
79    * @param[in] desc Input and output description
80    * @note      This method should be thread-safe
81    */
82   virtual void execute(const IODescription &desc) = 0;
83
84   /**
85    * @brief Execute with given input/output tensors
86    *
87    * For non-primary subgraphs, input and output tensors must be given.
88    *
89    * @param[in] inputs tensors that are passed as inputs
90    * @param[in] outputs tensors that are passed as outputs
91    */
92   virtual void execute(const std::vector<backend::IPortableTensor *> &inputs,
93                        const std::vector<backend::IPortableTensor *> &outputs) = 0;
94
95   /**
96    * @brief Get output tensor objects
97    *
98    * @return Vector of @c IOTensor
99    */
100   virtual const std::vector<backend::controlflow::IOTensor *> &getOutputTensors() const = 0;
101 };
102
103 using ExecutorMap = std::unordered_map<ir::SubgraphIndex, std::unique_ptr<IExecutor>>;
104
105 } // namespace exec
106 } // namespace onert
107
108 #endif // __ONERT_EXEC_I_EXECUTOR_H__