// // Executor.hpp // MNN // // Created by MNN on 2019/07/25. // Copyright © 2018, Alibaba Group Holding Limited // #ifndef Executor_hpp #define Executor_hpp #include #include #include #include #include #include #include #include namespace MNN { class Backend; class Execution; class Runtime; struct Op; namespace Express { class MNN_PUBLIC Executor { public: class ComputeCache; struct Unit; static void setShapeDirty(ComputeCache* cache); static void setContentDirty(ComputeCache* cache); static void* mapOutput(ComputeCache* cache, int offset, Tensor* dest); struct Requirement { std::vector contentNeedContent; std::vector shapeNeedContent; }; ~Executor(); Requirement getRequirement(Expr* expr) const; ErrorCode computeInfo(Expr* expr); void makeCache(const std::vector& expr, bool forceCPU = false); ErrorCode runCache(std::shared_ptr cache); void setGlobalExecutorConfig(MNNForwardType type, const BackendConfig& config, int numberThread); enum GCFlag { FULL, PART }; void gc(GCFlag flag = FULL); static std::shared_ptr getGlobalExecutor(); static std::shared_ptr newExecutor(MNNForwardType type, const BackendConfig& config, int numberThread); void resetProfile(); void dumpProfile(); void addOpCostTime(int op, float costTime); void addOpCostTime(const std::string& type, float costTime); void addOpFlops(const std::string& type, float flops); class Profiler; static RuntimeInfo getRuntime(); private: void _makeCache(const std::vector& outputs, bool forceCPU); void _create(const std::vector& outputs, std::set>&& inputCaches, std::set>&& inputNode, bool forceCPU); void _visit(EXPRP expr, std::set>& inputCaches, std::set>& inputNode); Executor(std::shared_ptr backend, MNNForwardType type); std::pair, MNNForwardType> mRuntime; std::pair, MNNForwardType> mBackupRuntime; std::mutex mMutex; std::shared_ptr mProfiler; }; } // namespace Express } // namespace MNN #endif