2019-04-17 10:49:11 +08:00
|
|
|
//
|
|
|
|
// CPUDeconvolution.hpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on 2018/07/20.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef CPUDeconvolution_hpp
|
|
|
|
#define CPUDeconvolution_hpp
|
|
|
|
|
2019-12-27 22:16:57 +08:00
|
|
|
#include "backend/cpu/CPUConvolution.hpp"
|
|
|
|
#include "backend/cpu/compute/StrassenMatmulComputor.hpp"
|
2019-04-17 10:49:11 +08:00
|
|
|
|
|
|
|
namespace MNN {
|
2019-06-17 20:10:35 +08:00
|
|
|
class CPUDeconvolutionBasic : public CPUConvolution {
|
2019-04-17 10:49:11 +08:00
|
|
|
public:
|
2019-06-17 20:10:35 +08:00
|
|
|
CPUDeconvolutionBasic(const Tensor *input, const Op *convOp, Backend *b);
|
|
|
|
virtual ~CPUDeconvolutionBasic() = default;
|
2019-04-17 10:49:11 +08:00
|
|
|
virtual ErrorCode onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int mSrcCount;
|
|
|
|
};
|
|
|
|
|
2019-06-17 20:10:35 +08:00
|
|
|
class CPUDeconvolutionCommon : public CPUDeconvolutionBasic {
|
2019-04-17 10:49:11 +08:00
|
|
|
public:
|
2019-06-17 20:10:35 +08:00
|
|
|
CPUDeconvolutionCommon(const Tensor *input, const Op *convOp, Backend *b);
|
|
|
|
virtual ~CPUDeconvolutionCommon();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::shared_ptr<Tensor> mBias;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CPUDeconvolutionOrigin : public CPUDeconvolutionBasic {
|
|
|
|
public:
|
|
|
|
CPUDeconvolutionOrigin(const Tensor *input, const Op *convOp, Backend *b)
|
|
|
|
: CPUDeconvolutionBasic(input, convOp, b) {
|
|
|
|
mTempColBuffer.reset(new Tensor(4));
|
|
|
|
mTempSrcBuffer.reset(new Tensor(4));
|
|
|
|
}
|
|
|
|
virtual ~CPUDeconvolutionOrigin() = default;
|
2019-04-17 10:49:11 +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;
|
|
|
|
|
|
|
|
private:
|
2019-06-17 20:10:35 +08:00
|
|
|
struct Unit {
|
|
|
|
std::vector<std::shared_ptr<StrassenMatrixComputor>> matrixMulti;
|
|
|
|
std::pair<int, std::function<void(int)>> postFunction;
|
|
|
|
};
|
|
|
|
std::vector<Unit> mComputors;
|
2019-04-17 10:49:11 +08:00
|
|
|
std::shared_ptr<Tensor> mTempSrcBuffer;
|
|
|
|
std::shared_ptr<Tensor> mTempColBuffer;
|
|
|
|
std::function<void(const float *, float *, int)> mFunction;
|
2019-06-17 20:10:35 +08:00
|
|
|
};
|
|
|
|
class CPUDeconvolutionMultiInput : public CPUDeconvolutionBasic {
|
|
|
|
public:
|
|
|
|
CPUDeconvolutionMultiInput(const Tensor *input, const Op *convOp, Backend *b)
|
|
|
|
: CPUDeconvolutionBasic(input, convOp, b) {
|
|
|
|
mOrigin.reset(new CPUDeconvolutionOrigin(input, convOp, b));
|
|
|
|
}
|
|
|
|
virtual ~CPUDeconvolutionMultiInput() = 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> mWeight;
|
|
|
|
std::shared_ptr<Tensor> mCacheWeight;
|
|
|
|
std::shared_ptr<Tensor> mBias;
|
|
|
|
std::vector<Tensor *> mTempInputs;
|
|
|
|
std::shared_ptr<CPUDeconvolutionOrigin> mOrigin;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CPUDeconvolution : public CPUDeconvolutionCommon {
|
|
|
|
public:
|
|
|
|
CPUDeconvolution(const Tensor *input, const Op *convOp, Backend *b);
|
|
|
|
virtual ~CPUDeconvolution();
|
|
|
|
virtual ErrorCode onExecute(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override {
|
|
|
|
mOrigin->onExecute(mTempInputs, outputs);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
virtual ErrorCode onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override {
|
|
|
|
mTempInputs = {inputs[0], mWeight.get(), mBias.get()};
|
|
|
|
return mOrigin->onResize(mTempInputs, outputs);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<Tensor> mWeight;
|
|
|
|
std::vector<Tensor *> mTempInputs;
|
|
|
|
std::shared_ptr<CPUDeconvolutionOrigin> mOrigin;
|
2019-04-17 10:49:11 +08:00
|
|
|
};
|
|
|
|
} // namespace MNN
|
|
|
|
#endif /* CPUDeconvolution_hpp */
|