MNN/source/backend/opencl/execution/image/ConvExecution.hpp

84 lines
2.5 KiB
C++
Raw Permalink Normal View History

2019-04-17 10:49:11 +08:00
//
// ConvExecution.hpp
// MNN
//
// Created by MNN on 2019/01/31.
// Copyright © 2018, Alibaba Group Holding Limited
//
#ifndef ConvExecution_hpp
#define ConvExecution_hpp
2019-12-27 22:16:57 +08:00
#include "core/Execution.hpp"
2019-04-17 10:49:11 +08:00
#include <array>
#include <functional>
#include <memory>
#include <vector>
2019-12-27 22:16:57 +08:00
#include "backend/opencl/core/OpenCLBackend.hpp"
#include "backend/opencl/core/OpenCLRunningUtils.hpp"
2024-04-19 11:58:21 +08:00
#include "CommonExecution.hpp"
2019-04-17 10:49:11 +08:00
namespace MNN {
namespace OpenCL {
2024-04-19 11:58:21 +08:00
struct ConvResource {
const Convolution2D *mConv2dParams;
const Convolution2DCommon *mConv2dCommonParams;
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
std::shared_ptr<cl::Buffer> mKernelBuffer;
2024-07-04 11:53:45 +08:00
std::shared_ptr<cl::Buffer> dequantScaleOffset;
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 mIsTurn = false;
bool mConv1x1Opt = false;
bool mWeightUseBuffer = false;
bool gemmOpt = false;
2024-07-04 11:53:45 +08:00
int mBlockSize;
2024-04-19 11:58:21 +08:00
int mKernelWidth;
int mKernelHeight;
int mOutputChannel;
int mInputChannel;
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
uint32_t mMaxWorkGroupSize;
};
class ConvCommonExecution {
2019-04-17 10:49:11 +08:00
public:
ConvCommonExecution(const Convolution2D *op, Backend *backend);
2025-07-23 14:10:58 +08:00
ConvCommonExecution(const Op *op, Backend *backend, bool isExtra);
2024-04-19 11:58:21 +08:00
ConvCommonExecution(Backend *backend) {
2023-12-27 17:26:44 +08:00
mOpenCLBackend = static_cast<OpenCLBackend *>(backend);
}
2019-04-17 10:49:11 +08:00
virtual ~ConvCommonExecution();
protected:
2024-04-19 11:58:21 +08:00
std::shared_ptr<ConvResource> mResource;
2023-12-27 17:26:44 +08:00
OpenCLBackend *mOpenCLBackend;
2019-04-17 10:49:11 +08:00
};
2024-04-19 11:58:21 +08:00
class ConvExecution : public ConvCommonExecution, public CommonExecution {
2019-04-17 10:49:11 +08:00
public:
2025-07-23 14:10:58 +08:00
ConvExecution(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
ConvExecution(std::shared_ptr<ConvResource> resource, const Op* op, Backend* backend);
2019-04-17 10:49:11 +08:00
virtual ~ConvExecution();
2024-04-19 11:58:21 +08:00
virtual ErrorCode onEncode(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
virtual bool onClone(Backend* bn, const Op* op, Execution** dst) override;
2019-04-17 10:49:11 +08:00
static std::shared_ptr<Tensor> getBias(OpenCLBackend *backend, const Convolution2D *conv);
private:
std::vector<int> mPaddings{0, 0};
std::vector<uint32_t> mGlobalWorkSize{1, 1, 1};
std::vector<uint32_t> mLocalWorkSize{1, 1, 1, 1};
};
} // namespace OpenCL
} // namespace MNN
#endif /* ConvExecution_hpp */