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

84 lines
2.8 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
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"
2019-04-17 10:49:11 +08:00
namespace MNN {
namespace OpenCL {
class ConvBufCommonExecution : public Execution {
2019-04-17 10:49:11 +08:00
public:
ConvBufCommonExecution(const Convolution2D *op, Backend *backend);
virtual ~ConvBufCommonExecution();
2019-04-17 10:49:11 +08:00
std::pair<std::vector<uint32_t>, uint32_t> gws2dLwsTune(const cl::Kernel &kernel, const std::vector<uint32_t> &gws, const std::string &kernelName, const uint32_t maxWorkGroupSize);
2019-04-17 10:49:11 +08:00
protected:
std::shared_ptr<Tensor> mBias;
OpenCLBackend *mOpenCLBackend;
2019-04-17 10:49:11 +08:00
};
class ConvBufExecution : public ConvBufCommonExecution {
2019-04-17 10:49:11 +08:00
public:
ConvBufExecution(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs, 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;
static std::shared_ptr<Tensor> getBias(OpenCLBackend *backend, const Convolution2D *conv);
void setConv1x1WeightBuffer(int packCout, int packCin, const float* filterDataPtr);
2019-04-17 10:49:11 +08:00
private:
2023-04-27 15:11:05 +08:00
void _generateFilterConvertRegion(Tensor *virtualFilter, Tensor *originBuffer) const;
void transformWeight(const Tensor *weightDest, const Tensor *source);
2019-04-17 10:49:11 +08:00
const Convolution2DCommon *mConv2dCommonParams;
const Convolution2D *mConv2dParams;
2019-04-17 10:49:11 +08:00
std::vector<int> mStrides{1, 1};
std::vector<int> mPaddings{0, 0};
std::vector<int> mDilations{1, 1};
std::vector<uint32_t> mGlobalWorkSize{1, 1, 1};
std::vector<uint32_t> mLocalWorkSize{1, 1, 1, 1};
std::shared_ptr<Tensor> mFilter;
cl::Kernel mKernel;
uint32_t mMaxWorkGroupSize;
bool mIsTurn = false;
bool mConv1x1Opt{false};
bool mUseLocalMem{false};
2023-04-27 15:11:05 +08:00
bool mUseSubgroup{false};
std::shared_ptr<cl::Buffer> mKernelBuffer;
std::shared_ptr<cl::Buffer> mBiasBuffer;
2023-04-27 15:11:05 +08:00
std::shared_ptr<Tensor> mSource;
cl::Kernel mKernelSub[2];
std::vector<uint32_t> mGlobalWorkSizeSub[2];
std::vector<uint32_t> mLocalWorkSizeSub[2];
int mKernelWidth;
int mKernelHeight;
int mOutputChannel;
int mInputChannel;
const float* mFilterDataPtr = nullptr;
std::set<std::string> mBuildOptions;
std::shared_ptr<Execution> mRasterExe;
2019-04-17 10:49:11 +08:00
};
} // namespace OpenCL
} // namespace MNN
#endif /* ConvBufExecution_hpp */
#endif /* MNN_OPENCL_BUFFER_CLOSED */