// // ConvBufExecution.hpp // MNN // // Created by MNN on 2019/01/31. // Copyright © 2018, Alibaba Group Holding Limited // #ifndef MNN_OPENCL_BUFFER_CLOSED #ifndef ConvBufExecution_hpp #define ConvBufExecution_hpp #include "backend/opencl/execution/image/CommonExecution.hpp" #include "backend/opencl/execution/buffer/StrassenMatmulOpenCLComputor.hpp" namespace MNN { namespace OpenCL { struct ConvBufResource { const Convolution2DCommon *mConv2dCommonParams; const Convolution2D *mConv2dParams; std::shared_ptr mKernelBuffer; std::shared_ptr mKernelImage; std::shared_ptr mDequantScaleOffsetBuffer; std::shared_ptr mFilter; std::shared_ptr mBias; std::shared_ptr mSlope; int mKernelWidth; int mKernelHeight; int mOutputChannel; int mInputChannel; int mBlockSize; bool mRelu = false; bool mRelu6 = false; bool mPrelu = false; std::vector mStrides{1, 1}; std::vector mDilations{1, 1}; std::set mBuildOptions; bool mConv1x1Opt = false; bool mConv1x1C8Opt = false; bool mConv1x1Local = false; float mCoef = 1.0f; /* 0 -> not use 1 -> use small tile 2 -> use quieter large tile */ int mConvGemmOptLevel = 0; std::shared_ptr mRasterExe; bool mUseImage = false; int mNumQuantBit = 0; int mAlignK = 1; int mAlignN = 1; }; class ConvBufCommonExecution { public: ConvBufCommonExecution(Backend *backend); ConvBufCommonExecution(const Convolution2D *op, Backend *backend); ConvBufCommonExecution(const Op *op, Backend *backend, bool isExtra); virtual ~ConvBufCommonExecution(); protected: std::shared_ptr mResource; OpenCLBackend *mOpenCLBackend; bool mConvComValid = true; }; class ConvBufExecution : public ConvBufCommonExecution, public CommonExecution { public: ConvBufExecution(const std::vector &inputs, const std::vector &outputs, const MNN::Op *op, Backend *backend, bool isExtra = false); ConvBufExecution(std::shared_ptr resource, const MNN::Op* op, Backend* backend); virtual ~ConvBufExecution(); virtual ErrorCode onResize(const std::vector &inputs, const std::vector &outputs) override; virtual ErrorCode onExecute(const std::vector &inputs, const std::vector &outputs) override; virtual bool onClone(Backend* bn, const Op* op, Execution** dst) override; private: void _generateFilterConvertRegion(Tensor *virtualFilter, Tensor *originBuffer) const; std::vector mPaddings{0, 0}; std::vector mGlobalWorkSize{1, 1, 1}; std::vector mLocalWorkSize{1, 1, 1, 1}; std::vector> mKernel; std::shared_ptr mConvGemmInpTensor; std::shared_ptr mConvGemmOutTensor; std::shared_ptr mPreKernel = nullptr; std::vector mPreGlobalWorkSize{1, 1, 1}; std::vector mPreLocalWorkSize{1, 1, 1, 1}; std::shared_ptr mPostKernel = nullptr; std::vector mPostGlobalWorkSize{1, 1, 1}; std::vector mPostLocalWorkSize{1, 1, 1, 1}; const float* mFilterDataPtr = nullptr; private: int mAlignM = 1; std::shared_ptr mStrassenComputor; }; } // namespace OpenCL } // namespace MNN #endif /* ConvBufExecution_hpp */ #endif /* MNN_OPENCL_BUFFER_CLOSED */