2021-06-11 17:17:13 +08:00
|
|
|
//
|
|
|
|
// DenseConvolutionTiledExecutor
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2018/07/16.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef DenseConvolutionTiledExecutor_hpp
|
|
|
|
#define DenseConvolutionTiledExecutor_hpp
|
|
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include "backend/cpu/CPUConvolution.hpp"
|
|
|
|
#include "ConvolutionTiledExecutor.hpp"
|
|
|
|
// Tiled Slide Window or Im2Col + GEMM
|
|
|
|
namespace MNN {
|
|
|
|
class DenseConvolutionTiledImpl : public ConvolutionTiledImpl {
|
|
|
|
public:
|
|
|
|
DenseConvolutionTiledImpl(const Convolution2DCommon *common, Backend *b) : ConvolutionTiledImpl(common, b) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
ErrorCode onResize(const std::vector<Tensor*>& inputs,
|
|
|
|
const std::vector<Tensor*>& outputs) override;
|
2022-05-06 19:51:20 +08:00
|
|
|
ErrorCode onExecute(const std::vector<Tensor*>& inputs,
|
|
|
|
const std::vector<Tensor*>& outputs) override;
|
2021-06-11 17:17:13 +08:00
|
|
|
virtual ~DenseConvolutionTiledImpl() = default;
|
|
|
|
void getPackParameter(int* eP, int* lP, int* hP, const CoreFunctions* core) override;
|
2022-05-06 19:51:20 +08:00
|
|
|
static PerfConfig bestTileConvolutionConfig(const Convolution2DCommon *common, const Tensor *inputTensor,
|
|
|
|
const Tensor *outputTensor, int threadNumber, Backend* b);
|
2021-06-11 17:17:13 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
};
|
|
|
|
class DenseConvolutionTiledExecutor : public ConvolutionTiledExecutor {
|
|
|
|
public:
|
|
|
|
DenseConvolutionTiledExecutor(const Convolution2DCommon *common, Backend *b, const float *originWeight,
|
2023-05-18 19:11:50 +08:00
|
|
|
size_t originWeightSize, const float *bias, size_t biasSize, std::shared_ptr<ConvolutionCommon::Int8Common>);
|
2021-06-11 17:17:13 +08:00
|
|
|
|
|
|
|
DenseConvolutionTiledExecutor(std::shared_ptr<CPUConvolution::Resource> res, const Convolution2DCommon *common, Backend* b);
|
|
|
|
virtual ~DenseConvolutionTiledExecutor();
|
|
|
|
|
2023-05-18 19:11:50 +08:00
|
|
|
virtual ErrorCode onExecute(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
|
|
|
|
virtual ErrorCode onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
|
2021-06-11 17:17:13 +08:00
|
|
|
virtual bool onClone(Backend* bn, const Op* op, Execution** dst) override;
|
|
|
|
void initWeight(float *dest, const float *source, float* cache, int depth, int outputCount, int kernelSize, const CoreFunctions* function);
|
2022-05-06 19:51:20 +08:00
|
|
|
static PerfConfig bestTileConvolutionConfig(const Convolution2DCommon *common, const Tensor *inputTensor,
|
|
|
|
const Tensor *outputTensor, int threadNumber, Backend* b) {
|
|
|
|
return DenseConvolutionTiledImpl::bestTileConvolutionConfig(common, inputTensor, outputTensor, threadNumber, b);
|
|
|
|
}
|
2023-05-18 19:11:50 +08:00
|
|
|
struct DequantizeCache {
|
|
|
|
std::shared_ptr<MNN::Tensor> weight;
|
|
|
|
std::shared_ptr<MNN::Tensor> weightInt8;
|
|
|
|
};
|
2021-06-11 17:17:13 +08:00
|
|
|
protected:
|
2023-05-18 19:11:50 +08:00
|
|
|
DequantizeCache mWeightCache;
|
2021-06-11 17:17:13 +08:00
|
|
|
std::shared_ptr<DenseConvolutionTiledImpl> mProxy;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConvolutionTiledExecutorMultiInput : public Execution {
|
|
|
|
public:
|
|
|
|
ConvolutionTiledExecutorMultiInput(const Convolution2DCommon *common, Backend *b) : Execution(b) {
|
|
|
|
mProxy.reset(new DenseConvolutionTiledImpl(common, b));
|
|
|
|
}
|
|
|
|
virtual ~ConvolutionTiledExecutorMultiInput() = default;
|
|
|
|
virtual ErrorCode onExecute(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
|
|
|
|
virtual ErrorCode onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<Tensor> mTempWeight;
|
|
|
|
std::shared_ptr<Tensor> mTempWeightCache;
|
|
|
|
std::shared_ptr<Tensor> mTempBias;
|
|
|
|
std::shared_ptr<DenseConvolutionTiledImpl> mProxy;
|
|
|
|
std::vector<Tensor *> mInputs;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace MNN
|
|
|
|
|
|
|
|
#endif /* DenseConvolutionTiledExecutor_hpp */
|