MNN/source/backend/opencl/execution/buffer/ConvBufExecution.hpp

106 lines
3.4 KiB
C++
Raw Normal View History

2019-04-17 10:49:11 +08:00
//
// ConvBufExecution.hpp
2019-04-17 10:49:11 +08:00
// 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
2019-04-17 10:49:11 +08:00
2024-04-19 11:58:21 +08:00
#include "backend/opencl/execution/image/CommonExecution.hpp"
2024-08-24 15:46:21 +08:00
#include "backend/opencl/execution/buffer/StrassenMatmulOpenCLComputor.hpp"
2019-04-17 10:49:11 +08:00
namespace MNN {
namespace OpenCL {
2024-04-19 11:58:21 +08:00
struct ConvBufResource {
const Convolution2DCommon *mConv2dCommonParams;
const Convolution2D *mConv2dParams;
std::shared_ptr<cl::Buffer> mKernelBuffer;
2024-05-11 19:17:02 +08:00
std::shared_ptr<cl::Image2D> mKernelImage;
2024-07-04 11:53:45 +08:00
std::shared_ptr<Tensor> dequantScaleOffset;
2024-04-19 11:58:21 +08:00
std::shared_ptr<Tensor> mFilter;
std::shared_ptr<Tensor> mBias;
2025-07-23 14:10:58 +08:00
std::shared_ptr<Tensor> mSlope;
2024-04-19 11:58:21 +08:00
int mKernelWidth;
int mKernelHeight;
int mOutputChannel;
int mInputChannel;
2024-07-04 11:53:45 +08:00
int mBlockSize;
2025-07-23 14:10:58 +08:00
bool mRelu = false;
bool mRelu6 = false;
bool mPrelu = false;
2024-04-19 11:58:21 +08:00
std::vector<int> mStrides{1, 1};
std::vector<int> mDilations{1, 1};
std::set<std::string> mBuildOptions;
bool mConv1x1Opt = false;
bool mConv1x1C8Opt = false;
2024-09-12 12:57:57 +08:00
bool mConv1x1Local = false;
2025-01-22 14:47:50 +08:00
float mCoef = 1.0f;
2024-06-03 20:09:34 +08:00
/*
0 -> not use
1 -> use small tile
2 -> use quieter large tile
*/
int mConvGemmOptLevel = 0;
2024-04-19 11:58:21 +08:00
std::shared_ptr<Execution> mRasterExe;
2024-05-11 19:17:02 +08:00
bool mUseImage = false;
2024-07-04 11:53:45 +08:00
int mNumQuantBit = 0;
2024-09-12 12:57:57 +08:00
int mAlignK = 1;
int mAlignN = 1;
2024-04-19 11:58:21 +08:00
};
class ConvBufCommonExecution {
2019-04-17 10:49:11 +08:00
public:
2023-12-27 17:26:44 +08:00
ConvBufCommonExecution(Backend *backend);
ConvBufCommonExecution(const Convolution2D *op, Backend *backend);
2025-07-23 14:10:58 +08:00
ConvBufCommonExecution(const Op *op, Backend *backend, bool isExtra);
virtual ~ConvBufCommonExecution();
2019-04-17 10:49:11 +08:00
protected:
2024-04-19 11:58:21 +08:00
std::shared_ptr<ConvBufResource> mResource;
OpenCLBackend *mOpenCLBackend;
2019-04-17 10:49:11 +08:00
};
2024-04-19 11:58:21 +08:00
class ConvBufExecution : public ConvBufCommonExecution, public CommonExecution {
2019-04-17 10:49:11 +08:00
public:
2025-07-23 14:10:58 +08:00
ConvBufExecution(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs, const MNN::Op *op, Backend *backend, bool isExtra = false);
2024-04-19 11:58:21 +08:00
ConvBufExecution(std::shared_ptr<ConvBufResource> resource, const MNN::Op* op, Backend* backend);
virtual ~ConvBufExecution();
2019-04-17 10:49:11 +08:00
virtual ErrorCode onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
virtual ErrorCode onExecute(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
2024-04-19 11:58:21 +08:00
virtual bool onClone(Backend* bn, const Op* op, Execution** dst) override;
2019-04-17 10:49:11 +08:00
private:
2023-04-27 15:11:05 +08:00
void _generateFilterConvertRegion(Tensor *virtualFilter, Tensor *originBuffer) const;
2019-04-17 10:49:11 +08:00
std::vector<int> mPaddings{0, 0};
std::vector<uint32_t> mGlobalWorkSize{1, 1, 1};
std::vector<uint32_t> mLocalWorkSize{1, 1, 1, 1};
2024-12-31 15:34:08 +08:00
std::vector<std::shared_ptr<KernelWrap>> mKernel;
2024-06-03 20:09:34 +08:00
std::shared_ptr<Tensor> mConvGemmInpTensor;
std::shared_ptr<Tensor> mConvGemmOutTensor;
std::shared_ptr<KernelWrap> mPreKernel = nullptr;
std::vector<uint32_t> mPreGlobalWorkSize{1, 1, 1};
std::vector<uint32_t> mPreLocalWorkSize{1, 1, 1, 1};
std::shared_ptr<KernelWrap> mPostKernel = nullptr;
std::vector<uint32_t> mPostGlobalWorkSize{1, 1, 1};
std::vector<uint32_t> mPostLocalWorkSize{1, 1, 1, 1};
const float* mFilterDataPtr = nullptr;
2024-09-12 12:57:57 +08:00
2024-08-24 15:46:21 +08:00
private:
2024-09-12 12:57:57 +08:00
int mAlignM = 1;
2024-08-24 15:46:21 +08:00
std::shared_ptr<StrassenMatrixComputor> mStrassenComputor;
2019-04-17 10:49:11 +08:00
};
} // namespace OpenCL
} // namespace MNN
#endif /* ConvBufExecution_hpp */
#endif /* MNN_OPENCL_BUFFER_CLOSED */