Imported Upstream version 1.9.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/OperationIndexMap.h"
28 #include "backend/IDynamicTensorManager.h"
29
30 namespace onert
31 {
32 namespace exec
33 {
34 class IExecutionObserver;
35 /**
36  * @brief Struct to define interface of Executor
37  */
38 struct IExecutor
39 {
40   /**
41    * @brief Construct a new IExecutor object
42    */
43   IExecutor() = default;
44   /**
45    * @brief Destroy the IExecutor object
46    */
47   virtual ~IExecutor() = default;
48
49   /**
50    * @brief Returns graph object
51    *
52    * @return Graph object
53    */
54   virtual const ir::Graph &graph() = 0;
55
56   /**
57    * @brief     Set an ordering on operations
58    * @param[in] ranks   The table encoding the ordering
59    */
60   virtual void setIndexedRanks(std::shared_ptr<ir::OperationIndexMap<int64_t>>) = 0;
61
62   /**
63    * @brief     Start execution
64    * @param[in] desc Input and output description
65    * @note      This method should be thread-safe
66    */
67   virtual void execute(const IODescription &desc) = 0;
68 };
69
70 using ExecutorMap = std::unordered_map<ir::SubgraphIndex, std::unique_ptr<IExecutor>>;
71
72 // TODO Move this structure to suitable place
73 /**
74  * @brief Dynamic allocation info for input tensors
75  *        When user sets shape of input having unknown dims after compilation, memory for the input
76  * should be allocated before executing kernels. This struct contains information to allocate
77  * memory.
78  */
79 struct DynAllocInfo
80 {
81   /// @brief index of input tensor whose memory needs to be allocated at execution time
82   ir::OperandIndex ind;
83 };
84
85 using DynAllocInfoMap = std::unordered_map<std::shared_ptr<backend::ITensor>, DynAllocInfo>;
86
87 } // namespace exec
88 } // namespace onert
89
90 #endif // __ONERT_EXEC_I_EXECUTOR_H_