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
|
|
|
|
|
2020-02-26 09:57:17 +08:00
|
|
|
#include "CPUConvolution.hpp"
|
2024-04-19 11:58:21 +08:00
|
|
|
#include "compute/CommonOptFunction.h"
|
2020-02-26 09:57:17 +08:00
|
|
|
#include "compute/StrassenMatmulComputor.hpp"
|
2023-04-18 18:54:46 +08:00
|
|
|
#include "core/TensorUtils.hpp"
|
2019-04-17 10:49:11 +08:00
|
|
|
namespace MNN {
|
2025-02-12 11:14:19 +08:00
|
|
|
struct DeconvolutionResource {
|
|
|
|
struct Param {
|
|
|
|
int outputCount;
|
|
|
|
int srcCount;
|
|
|
|
int fh;
|
|
|
|
int fw;
|
|
|
|
};
|
|
|
|
Param mParam;
|
|
|
|
std::shared_ptr<Tensor> mBias;
|
|
|
|
std::shared_ptr<Tensor> mWeight;
|
|
|
|
};
|
2019-06-17 20:10:35 +08:00
|
|
|
class CPUDeconvolutionBasic : public CPUConvolution {
|
2019-04-17 10:49:11 +08:00
|
|
|
public:
|
2025-02-12 11:14:19 +08:00
|
|
|
CPUDeconvolutionBasic(int inputChannel, const Op *convOp, Backend *b);
|
2019-06-17 20:10:35 +08:00
|
|
|
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;
|
2021-04-08 15:34:23 +08:00
|
|
|
std::vector<float> mPostParameters;
|
2019-04-17 10:49:11 +08:00
|
|
|
};
|
|
|
|
|
2019-06-17 20:10:35 +08:00
|
|
|
class CPUDeconvolutionOrigin : public CPUDeconvolutionBasic {
|
|
|
|
public:
|
2025-02-12 11:14:19 +08:00
|
|
|
CPUDeconvolutionOrigin(int inputChannel, const Op *convOp, Backend *b);
|
2019-06-17 20:10:35 +08:00
|
|
|
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:
|
2024-12-19 16:20:00 +08:00
|
|
|
MemChunk mGemmOutput;
|
|
|
|
MemChunk mGemmInput;
|
|
|
|
MemChunk mExtraOutput;
|
|
|
|
|
|
|
|
std::vector<std::pair<std::function<void(uint8_t*, int)>, int>> mExecuteFuntion;
|
2019-06-17 20:10:35 +08:00
|
|
|
};
|
|
|
|
|
2025-02-12 11:14:19 +08:00
|
|
|
class CPUDeconvolution : public CPUDeconvolutionBasic {
|
2019-06-17 20:10:35 +08:00
|
|
|
public:
|
2025-02-12 11:14:19 +08:00
|
|
|
static std::shared_ptr<DeconvolutionResource> makeResource(int inputChannel, const Op *convOp, Backend *b, bool dynamic);
|
|
|
|
CPUDeconvolution(int inputChannel, const Op *convOp, Backend *b, bool dynamicWeight, std::shared_ptr<DeconvolutionResource> res);
|
2019-06-17 20:10:35 +08:00
|
|
|
virtual ~CPUDeconvolution();
|
2023-12-04 11:12:20 +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;
|
2025-02-12 11:14:19 +08:00
|
|
|
virtual bool onClone(Backend* bn, const Op* op, Execution** dst) override;
|
2019-06-17 20:10:35 +08:00
|
|
|
|
|
|
|
private:
|
2025-02-12 11:14:19 +08:00
|
|
|
bool mDynamicWeight;
|
|
|
|
std::shared_ptr<DeconvolutionResource> mResource;
|
2019-06-17 20:10:35 +08:00
|
|
|
std::shared_ptr<Tensor> mWeight;
|
2025-02-12 11:14:19 +08:00
|
|
|
std::shared_ptr<Tensor> mBias;
|
2023-12-04 11:12:20 +08:00
|
|
|
std::shared_ptr<Tensor> mWeightTransformCache;
|
2019-06-17 20:10:35 +08:00
|
|
|
std::vector<Tensor *> mTempInputs;
|
|
|
|
std::shared_ptr<CPUDeconvolutionOrigin> mOrigin;
|
2019-04-17 10:49:11 +08:00
|
|
|
};
|
|
|
|
} // namespace MNN
|
|
|
|
#endif /* CPUDeconvolution_hpp */
|