| 
									
										
										
										
											2020-03-02 22:13:38 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  ConvolutionCommon.hpp
 | 
					
						
							|  |  |  | //  MNN
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  | //  Created by MNN on 2020/03/02.
 | 
					
						
							| 
									
										
										
										
											2020-03-02 22:13:38 +08:00
										 |  |  | //  Copyright © 2018, Alibaba Group Holding Limited
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 22:13:38 +08:00
										 |  |  | #ifndef ConvolutionCommon_hpp
 | 
					
						
							|  |  |  | #define ConvolutionCommon_hpp
 | 
					
						
							|  |  |  | #include "AutoStorage.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  | #include "Execution.hpp"
 | 
					
						
							|  |  |  | #include "MNN_generated.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-02 22:13:38 +08:00
										 |  |  | namespace MNN { | 
					
						
							|  |  |  | class MNN_PUBLIC ConvolutionCommon : public Execution { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     struct Int8Common { | 
					
						
							|  |  |  |         AutoStorage<int8_t> weight; | 
					
						
							|  |  |  |         AutoStorage<float> alpha; | 
					
						
							|  |  |  |         AutoStorage<float> weightFloat; | 
					
						
							|  |  |  |         const IDSTQuan* quan; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 |  |  |     static std::shared_ptr<Int8Common> load(const IDSTQuan* quan, bool forceFloat = false, bool forceInt8 = false); | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  |     static void getConvParameters(std::shared_ptr<ConvolutionCommon::Int8Common> *quanCommon, const MNN::Convolution2D *conv2d, const float** originWeight, int* originWeightSize); | 
					
						
							| 
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 |  |  |     static bool getConvInt8Parameters(const MNN::Convolution2D* conv2d, std::shared_ptr<Int8Common>& quanCommon, | 
					
						
							| 
									
										
										
										
											2021-04-08 14:24:07 +08:00
										 |  |  |                                       const int8_t*& weight, float*& scale, int32_t*& bias, float inputScale, float outputScale, int inputZeroPoint, int outputZeroPoint); | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 20:29:43 +08:00
										 |  |  |     // Return padX, padY
 | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  |     static std::pair<int, int> convolutionPad(const Tensor* input, const Tensor* output, | 
					
						
							|  |  |  |                                               const Convolution2DCommon* common); | 
					
						
							| 
									
										
										
										
											2021-01-06 16:29:37 +08:00
										 |  |  |     // Return padLeft, padTop, padRight, padBottom
 | 
					
						
							|  |  |  |     static std::tuple<int, int, int, int> convolutionPadFull(const Tensor* input, const Tensor* output, | 
					
						
							|  |  |  |                                               const Convolution2DCommon* common); | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  |     static std::pair<int, int> convolutionTransposePad(const Tensor* input, const Tensor* output, | 
					
						
							|  |  |  |                                                        const Convolution2DCommon* common); | 
					
						
							|  |  |  |     struct Im2ColParameter { | 
					
						
							|  |  |  |         int32_t padX; | 
					
						
							|  |  |  |         int32_t padY; | 
					
						
							|  |  |  |         int32_t dilateX; | 
					
						
							|  |  |  |         int32_t dilateY; | 
					
						
							|  |  |  |         int32_t strideX; | 
					
						
							|  |  |  |         int32_t strideY; | 
					
						
							|  |  |  |         int32_t kernelX; | 
					
						
							|  |  |  |         int32_t kernelY; | 
					
						
							|  |  |  |         int32_t icDiv4; | 
					
						
							|  |  |  |         int32_t kernelCountUnit; | 
					
						
							|  |  |  |         int32_t iw; | 
					
						
							|  |  |  |         int32_t ih; | 
					
						
							|  |  |  |         int32_t ow; | 
					
						
							|  |  |  |         int32_t oh; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-03-02 22:13:38 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  | } // namespace MNN
 | 
					
						
							| 
									
										
										
										
											2020-03-12 20:29:43 +08:00
										 |  |  | #endif
 |