#ifndef MNN_Executor_hpp
#define MNN_Executor_hpp
#include <MNN/ErrorCode.hpp>
#include <MNN/expr/Expr.hpp>
#include <MNN/Tensor.hpp>
#include <MNN/Interpreter.hpp>
#include <vector>
#include <mutex>
#include <set>
#include <MNN/MNNForwardType.h>
namespace MNN {
class Backend;
class Execution;
class Runtime;
struct Op;
namespace Express {
struct RuntimeAttr;
struct ExecutorAttr;
class MNN_PUBLIC Executor {
public:
class ComputeCache;
class RuntimeExecuteWrap;
struct DebugTools;
struct Requirement {
std::vector<bool> contentNeedContent;
std::vector<bool> shapeNeedContent;
};
~Executor();
Requirement getRequirement(Expr* expr) const;
ErrorCode computeInfo(Expr* expr);
void makeCache(const std::vector<EXPRP>& expr, bool forceCPU = false);
bool lazyEval = true;
enum LazyMode {
LAZY_FULL = 0,
LAZY_CONTENT = 1 << 0,
LAZY_COMPUTE_ONCE = 1 << 1,
};
uint32_t getLazyMode() const {
return mLazyMode;
}
void setLazyComputeMode(uint32_t mode);
void setGlobalExecutorConfig(MNNForwardType type, const BackendConfig& config, int numberThread);
int getCurrentRuntimeStatus(RuntimeStatus statusEnum);
enum GCFlag {
FULL,
PART
};
void gc(GCFlag flag = FULL);
static std::shared_ptr<Executor> getGlobalExecutor();
static std::shared_ptr<Executor> newExecutor(MNNForwardType type,
const BackendConfig& config,
int numberThread);
void resetProfile();
void dumpProfile();
struct SubGraph;
bool registerSubGraph(const std::string& submoduleName, VARPS outputs, VARPS inputs);
std::shared_ptr<SubGraph> findSubGraph(const std::string& submoduleName);
static RuntimeInfo getRuntime();
void setCallBack(TensorCallBackWithInfo&& before, TensorCallBackWithInfo&& after);
const DebugTools* getDebugTools() const {
return mDebug.get();
}
ExecutorAttr* getAttr() const;
class MNN_PUBLIC RuntimeManager {
public:
~RuntimeManager();
static RuntimeManager* createRuntimeManager(const ScheduleConfig& config);
static void destroy(RuntimeManager* rtmgr);
static RuntimeManager* createRuntimeManager(std::vector<ScheduleConfig>& configs);
void setCache(std::string cacheName);
void setExternalPath(std::string path, int type);
void setExternalFile(std::string fileName);
void updateCache();
std::vector<bool> isBackendSupport(const std::vector<MNNForwardType> type);
friend class Executor;
void setMode(Interpreter::SessionMode mode);
void setHint(Interpreter::HintMode mode, int value);
void setHint(Interpreter::HintMode mode, int* value, size_t size);
void setHintPtr(Interpreter::HintMode mode, void* value);
bool getInfo(Interpreter::SessionInfoCode code, void* ptr);
static bool getDeviceInfo(const std::string& deviceKey, const MNNForwardType type, std::string& deviceValue);
BackendConfig* getBnConfig();
const RuntimeAttr* getInside() const {
return mInside;
}
private:
std::mutex mLock;
RuntimeAttr* mInside;
friend class StaticModule;
RuntimeManager();
};
static bool getComputeInfo(EXPRP expr, Interpreter::SessionInfoCode code, void* ptr);
#ifndef MNN_REDUCE_SIZE
std::map<std::string, std::shared_ptr<SubGraph>>& subgraph() {
return mSubGraph;
};
#endif
private:
std::shared_ptr<Runtime> _getOrCreateRuntime(MNNForwardType type, const BackendConfig* config, int numberThread, bool reset = true);
Executor(std::shared_ptr<Runtime> backend, MNNForwardType type, int numberThread);
void _makeCache(const std::vector<EXPRP>& outputs, bool forceCPU);
RuntimeInfo mRuntimeInfo;
std::shared_ptr<DebugTools> mDebug;
#ifndef MNN_REDUCE_SIZE
std::map<std::string, std::shared_ptr<SubGraph>> mSubGraph;
#endif
uint32_t mLazyMode = 0;
std::shared_ptr<ExecutorAttr> mAttr;
std::mutex mMutex;
};
} } #endif