doc/API/html/_interpreter_8hpp_source.html
| MNN 1.0 |
Interpreter.hpp
1 //
2 // Interpreter.hpp
3 // MNN
4 //
5 // Created by MNN on 2018/07/23.
6 // Copyright © 2018, Alibaba Group Holding Limited
7 //
8
9 #ifndef Interpreter_hpp
10 #define Interpreter_hpp
11
12 #include <functional>
13 #include <map>
14 #include <string>
15 #include "ErrorCode.hpp"
16 #include "MNNForwardType.h"
17 #include "Tensor.hpp"
18
19 namespace MNN {
20
22 struct ScheduleConfig {
24 std::vector<std::string> saveTensors;
26MNNForwardType type = MNN_FORWARD_CPU;
29
32 std::vector<std::string> inputs;
33 std::vector<std::string> outputs;
34
44
52 };
53
56 };
58
60MNNForwardType backupType = MNN_FORWARD_CPU;
61
63 BackendConfig* backendConfig = nullptr;
64 };
65
66 class Session;
67 struct Content;
68 class Tensor;
69 class Backend;
70
71 class MNN_PUBLIC OperatorInfo {
72struct Info;
73
74 public:
76const std::string& name() const;
77
79const std::string& type() const;
80
82float flops() const;
83
84 protected:
85OperatorInfo();
86 ~OperatorInfo();
88 };
89
90 typedef std::function<bool(const std::vector<Tensor*>&, const std::string& /*opName*/)> TensorCallBack;
91 typedef std::function<bool(const std::vector<Tensor*>&, const OperatorInfo*)> TensorCallBackWithInfo;
92
94 class MNN_PUBLIC Interpreter {
95 public:
101static Interpreter* createFromFile(const char* file);
108static Interpreter* createFromBuffer(const void* buffer, size_t size);
109 ~Interpreter();
110
111 public:
117 Session* createSession(const ScheduleConfig& config);
118
124 Session* createMultiPathSession(const std::vector<ScheduleConfig>& configs);
125
131bool releaseSession(Session* session);
132
138void resizeSession(Session* session);
139
144void releaseModel();
145
151ErrorCode runSession(Session* session) const;
152
153/*
154 * @brief run session.
155 * @param session given session.
156 * @param before callback before each op. return true to run the op; return false to skip the op.
157 * @param after callback after each op. return true to continue running; return false to interrupt the session.
158 * @param sync synchronously wait for finish of execution or not.
159 * @return result of running.
160 */
161ErrorCode runSessionWithCallBack(const Session* session, const TensorCallBack& before, const TensorCallBack& end,
162bool sync = false) const;
163
164/*
165 * @brief run session.
166 * @param session given session.
167 * @param before callback before each op. return true to run the op; return false to skip the op.
168 * @param after callback after each op. return true to continue running; return false to interrupt the session.
169 * @param sync synchronously wait for finish of execution or not.
170 * @return result of running.
171 */
172ErrorCode runSessionWithCallBackInfo(const Session* session, const TensorCallBackWithInfo& before,
173const TensorCallBackWithInfo& end, bool sync = false) const;
174
181Tensor* getSessionInput(const Session* session, const char* name);
188Tensor* getSessionOutput(const Session* session, const char* name);
189
195const std::map<std::string, Tensor*>& getSessionOutputAll(const Session* session) const;
201const std::map<std::string, Tensor*>& getSessionInputAll(const Session* session) const;
202
203 public:
209void resizeTensor(Tensor* tensor, const std::vector<int>& dims);
210
217const Backend* getBackend(const Session* session, const Tensor* tensor) const;
218
223const char* bizCode() const;
224
225 private:
226static Interpreter* createFromBufferInternal(Content* net);
227
228 Content* mNet = nullptr;
229Interpreter(Content* net);
230
231Interpreter(const Interpreter&) = delete;
232Interpreter(const Interpreter&&) = delete;
233Interpreter& operator=(const Interpreter&) = delete;
234Interpreter& operator=(const Interpreter&&) = delete;
235 };
236 } // namespace MNN
237
238 #endif /* Interpreter_hpp */
MNN::ScheduleConfig::Path::Mode
Mode
Definition: Interpreter.hpp:35
MNNForwardType
Definition: MNNForwardType.h:12
MNN::ScheduleConfig::saveTensors
std::vector< std::string > saveTensors
Definition: Interpreter.hpp:24
MNN::ScheduleConfig::backupType
MNNForwardType backupType
Definition: Interpreter.hpp:60
Info * mContent
Definition: Interpreter.hpp:87
MNNForwardType type
Definition: Interpreter.hpp:26
Definition: Interpreter.hpp:71
Definition: Interpreter.hpp:43
Definition: Tensor.hpp:25
Definition: Interpreter.hpp:31
#define MNN_PUBLIC
Definition: MNNDefine.h:53
Definition: Interpreter.hpp:22
Definition: Interpreter.hpp:94
Definition: MNNForwardType.h:13
std::function< bool(const std::vector< Tensor * > &, const OperatorInfo *)> TensorCallBackWithInfo
Definition: Interpreter.hpp:91
MNN::ScheduleConfig::backendConfig
BackendConfig * backendConfig
Definition: Interpreter.hpp:63
Definition: AutoTime.hpp:16
MNN::ScheduleConfig::numThread
int numThread
Definition: Interpreter.hpp:28
Path path
Definition: Interpreter.hpp:57
ErrorCode
Definition: ErrorCode.hpp:13
std::function< bool(const std::vector< Tensor * > &, const std::string &)> TensorCallBack
Definition: Interpreter.hpp:90
MNN::ScheduleConfig::Path::inputs
std::vector< std::string > inputs
Definition: Interpreter.hpp:32
MNN::ScheduleConfig::Path::mode
Mode mode
Definition: Interpreter.hpp:55
MNN::ScheduleConfig::Path::outputs
std::vector< std::string > outputs
Definition: Interpreter.hpp:33