// // GeometryComputer.hpp // MNN // // Created by MNN on 2020/04/01. // Copyright © 2018, Alibaba Group Holding Limited // #ifndef GeometryComputer_hpp #define GeometryComputer_hpp #include #include #include "MNN_generated.h" #include "core/Command.hpp" #include "core/TensorUtils.hpp" #include "core/Backend.hpp" namespace MNN { class GeometryComputer { public: virtual ~GeometryComputer() { // Do nothing } class MNN_PUBLIC Context { public: Context(int mask, std::shared_ptr allocBackend, MNNForwardType type = MNN_FORWARD_CPU, BackendConfig::PrecisionMode precision = BackendConfig::Precision_Normal); ~Context(); void clear(); void setBackend(Backend* backend); void getRasterCacheCreateRecursive(Tensor* src, CommandBuffer& cmd); // If has cache, return. Otherwise create cache const std::vector>& searchConst(const Op* op); std::shared_ptr allocConst(const Op* key, const std::vector& shape, halide_type_t type, Tensor::DimensionType dimType = Tensor::TENSORFLOW); bool allocTensor(Tensor* tenosr); inline MNNForwardType forwardType() const { return mForwardType; } inline BackendConfig::PrecisionMode precisionType() const { return mPrecision; } inline bool support(int option) const { return mMask & option; } std::shared_ptr mRasterOp; bool mNeedRelease = true; private: void getRasterCacheCreate(Tensor* src, CommandBuffer& cmd); std::map>> mConstTensors; std::vector> mEmpty; std::vector> mTempConstTensors; std::shared_ptr mBackend; MNNForwardType mForwardType; BackendConfig::PrecisionMode mPrecision; TensorUtils::FuseWrap mFuseUtils; const int mMask; }; static void init(); MNN_PUBLIC static const GeometryComputer* search(int opType, Runtime::CompilerType compType); static void registerGeometryComputer(std::shared_ptr comp, std::vector type, Runtime::CompilerType compType = Runtime::Compiler_Geometry); virtual bool onCompute(const Op* op, const std::vector& inputs, const std::vector& outputs, Context& context, CommandBuffer& cmd) const = 0; virtual bool onRecompute(const Op* op, const std::vector& inputs, const std::vector& outputs, Context& context, CommandBuffer& cmd) const { return false; } static bool ComputePermuteRegion(Tensor* input, Tensor* output, int* newshape, int shapeDim); }; class DefaultGeometryComputer : public GeometryComputer { public: DefaultGeometryComputer() { // Do nothing } virtual bool onRecompute(const Op* op, const std::vector& inputs, const std::vector& outputs, Context& context, CommandBuffer& cmd) const override; virtual bool onCompute(const Op* op, const std::vector& inputs, const std::vector& outputs, Context& context, CommandBuffer& cmd) const override; }; void registerGeometryOps(); #define REGISTER_GEOMETRY(f, c) \ extern void ___##f##__##c##__() { \ c(); \ } } // namespace MNN #endif