// // Utils.hpp // MNN // // Created by MNN on 2019/07/26. // Copyright © 2018, Alibaba Group Holding Limited // #ifndef Utils_hpp #define Utils_hpp #include #include "Type_generated.h" #include "MNN_generated.h" #include #include "core/AutoStorage.h" namespace MNN { class Session; namespace Express { struct Expr::Inside { Inside(int outputSize); Inside(Tensor* tensor, bool own = false); ~ Inside(); std::vector mOutputInfos; std::vector mOutputTensors; Executor::Requirement mReq; std::shared_ptr mCache; int mCacheOffset = 0; bool mInfoDirty = true; bool mContentDirty = true; bool mOwnTensor = true; Tensor* mHostTensor = nullptr; std::shared_ptr mHoldBackend; }; struct Executor::DebugTools { TensorCallBackWithInfo before = nullptr; TensorCallBackWithInfo after = nullptr; mutable float flops = 0.0f; }; struct Executor::SubGraph { std::unique_ptr info; std::vector depends; }; class Executor::ComputeCache { public: void setContentDirty(); void* mapOutput(int offset, Tensor* dest); ~ ComputeCache(); ComputeCache() { // Do nothing } ErrorCode compute(); ErrorCode resize(); ErrorCode resizeImpl(); Session* getSession() { return mSession.get(); } friend class Executor; private: std::set> mInputInside; std::set> mInputs; std::shared_ptr mSession; bool mContentDirty = true; bool mShapeDirty = true; std::vector> mCacheBuffers; #ifdef MNN_EXPRESS_MEMLEAK_DEBUG static int gInstanceCount; #endif }; class Utils { public: static void copyInfoToTensor(Tensor* dest, const Variable::Info* source); static void copyTensorToInfo(Variable::Info* dest, const Tensor* source); static DataType convertDataType(halide_type_t type); static int convertFormat(Dimensionformat format); static Express::Dimensionformat revertFormat(int format); static halide_type_t revertDataType(DataType dataType); static bool allocMemoryForHostTensor(Tensor* dest); static bool releaseMemoryForHostTensor(Tensor* dest); static Tensor* getTensor(VARP var); static EXPRP makeRaster(const std::vector& vars, const std::vector& regions, const std::vector& shape, halide_type_t dataType, MNN_DATA_FORMAT format); }; class Executor::RuntimeExecuteWrap { public: RuntimeExecuteWrap(const RuntimeInfo& info); ~ RuntimeExecuteWrap(); private: const RuntimeInfo& mRt; }; } // namespace Express } // namespace MNN #endif