Interpreter.hpp
浏览该文件的文档.
//
// Interpreter.hpp
// MNN
//
// Created by MNN on 2018/07/23.
// Copyright © 2018, Alibaba Group Holding Limited
//
#ifndef Interpreter_hpp
#define Interpreter_hpp
#include <functional>
#include <map>
#include <string>
#include "ErrorCode.hpp"
#include "MNNForwardType.h"
#include "Tensor.hpp"
namespace MNN {
struct ScheduleConfig {
std::vector<std::string> saveTensors;
MNNForwardType type = MNN_FORWARD_CPU;
int numThread = 4;
struct Path {
std::vector<std::string> inputs;
std::vector<std::string> outputs;
enum Mode {
Op = 0,
Tensor = 1
};
Mode mode = Op;
};
Path path;
MNNForwardType backupType = MNN_FORWARD_CPU;
BackendConfig* backendConfig = nullptr;
};
class Session;
struct Content;
class Tensor;
class Backend;
class MNN_PUBLIC OperatorInfo {
struct Info;
public:
const std::string& name() const;
const std::string& type() const;
float flops() const;
protected:
OperatorInfo();
~OperatorInfo();
Info* mContent;
};
typedef std::function<bool(const std::vector<Tensor*>&, const std::string& /*opName*/)> TensorCallBack;
typedef std::function<bool(const std::vector<Tensor*>&, const OperatorInfo*)> TensorCallBackWithInfo;
class MNN_PUBLIC Interpreter {
public:
static Interpreter* createFromFile(const char* file);
static Interpreter* createFromBuffer(const void* buffer, size_t size);
~Interpreter();
public:
Session* createSession(const ScheduleConfig& config);
Session* createMultiPathSession(const std::vector<ScheduleConfig>& configs);
bool releaseSession(Session* session);
void resizeSession(Session* session);
void releaseModel();
ErrorCode runSession(Session* session) const;
/*
* @brief run session.
* @param session given session.
* @param before callback before each op. return true to run the op; return false to skip the op.
* @param after callback after each op. return true to continue running; return false to interrupt the session.
* @param sync synchronously wait for finish of execution or not.
* @return result of running.
*/
ErrorCode runSessionWithCallBack(const Session* session, const TensorCallBack& before, const TensorCallBack& end,
bool sync = false) const;
/*
* @brief run session.
* @param session given session.
* @param before callback before each op. return true to run the op; return false to skip the op.
* @param after callback after each op. return true to continue running; return false to interrupt the session.
* @param sync synchronously wait for finish of execution or not.
* @return result of running.
*/
ErrorCode runSessionWithCallBackInfo(const Session* session, const TensorCallBackWithInfo& before,
const TensorCallBackWithInfo& end, bool sync = false) const;
Tensor* getSessionInput(const Session* session, const char* name);
Tensor* getSessionOutput(const Session* session, const char* name);
const std::map<std::string, Tensor*>& getSessionOutputAll(const Session* session) const;
const std::map<std::string, Tensor*>& getSessionInputAll(const Session* session) const;
public:
void resizeTensor(Tensor* tensor, const std::vector<int>& dims);
const Backend* getBackend(const Session* session, const Tensor* tensor) const;
const char* bizCode() const;
private:
static Interpreter* createFromBufferInternal(Content* net);
Content* mNet = nullptr;
Interpreter(Content* net);
Interpreter(const Interpreter&) = delete;
Interpreter(const Interpreter&&) = delete;
Interpreter& operator=(const Interpreter&) = delete;
Interpreter& operator=(const Interpreter&&) = delete;
};
} // namespace MNN
#endif /* Interpreter_hpp */
MNN::ScheduleConfig::Path::Mode
Mode
Definition: Interpreter.hpp:35
MNNForwardType
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
ErrorCode.hpp
MNN::OperatorInfo::mContent
Info * mContent
Definition: Interpreter.hpp:87
MNN::ScheduleConfig::type
MNNForwardType type
Definition: Interpreter.hpp:26
MNN::OperatorInfo
Definition: Interpreter.hpp:71
MNN::ScheduleConfig::Path::Op
Definition: Interpreter.hpp:43
MNN::Tensor
Definition: Tensor.hpp:25
MNN::ScheduleConfig::Path
Definition: Interpreter.hpp:31
MNN_PUBLIC
#define MNN_PUBLIC
Definition: MNNDefine.h:53
MNN::ScheduleConfig
Definition: Interpreter.hpp:22
MNN::Interpreter
Definition: Interpreter.hpp:94
MNN_FORWARD_CPU
Definition: MNNForwardType.h:13
MNN::TensorCallBackWithInfo
std::function< bool(const std::vector< Tensor * > &, const OperatorInfo *)> TensorCallBackWithInfo
Definition: Interpreter.hpp:91
MNN::ScheduleConfig::backendConfig
BackendConfig * backendConfig
Definition: Interpreter.hpp:63
MNN
Definition: AutoTime.hpp:16
MNN::ScheduleConfig::numThread
int numThread
Definition: Interpreter.hpp:28
Tensor.hpp
MNN::ScheduleConfig::path
Path path
Definition: Interpreter.hpp:57
MNN::ErrorCode
ErrorCode
Definition: ErrorCode.hpp:13
MNN::TensorCallBack
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
MNNForwardType.h
MNN::ScheduleConfig::Path::outputs
std::vector< std::string > outputs
Definition: Interpreter.hpp:33