| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  Pipeline.hpp
 | 
					
						
							|  |  |  | //  MNN
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Created by MNN on 2019/01/14.
 | 
					
						
							|  |  |  | //  Copyright © 2018, Alibaba Group Holding Limited
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef Pipeline_hpp
 | 
					
						
							|  |  |  | #define Pipeline_hpp
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Execution.hpp"
 | 
					
						
							|  |  |  | #include "Schedule.hpp"
 | 
					
						
							| 
									
										
											  
											
												- build:
	- unify schema building in core and converter;
	- add more build script for android;
	- add linux build script for python;
- ops impl:
	- add floor mod support in binary;
	- use eltwise impl in add/max/sub/mul binary for optimization;
	- remove fake double support in cast;
	- fix 5d support for concat;
	- add adjX and adjY support for batch matmul;
	- optimize conv2d back prop filter;
	- add pad mode support for conv3d;
	- fix bug in conv2d & conv depthwise with very small feature map;
	- optimize binary without broacast;
	- add data types support for gather;
	- add gather ND support;
	- use uint8 data type in gather v2;
	- add transpose support for matmul;
	- add matrix band part;
	- add dim != 4 support for padding, reshape & tensor convert;
	- add pad type support for pool3d;
	- make ops based on TensorFlow Lite quantization optional;
	- add all & any support for reduction;
	- use type in parameter as output type in reduction;
	- add int support for unary;
	- add variable weight support for conv2d;
	- fix conv2d depthwise weights initialization;
	- fix type support for transpose;
	- fix grad outputs count for  reduce grad and reshape grad;
	- fix priorbox & detection output;
	- fix metal softmax error;
- python:
	- add runSessionWithCallBackInfo interface;
	- add max nodes limit (1400) for visualization tool;
	- fix save error in python3;
	- align default dim;
- convert:
	- add extra design for optimization;
	- add more post converting optimizers;
	- add caffe v1 weights blob support;
	- add cast, unary, conv transpose support for onnx model;
	- optimize batchnorm, conv with variable weights, prelu, reshape, slice, upsample for onnx model;
	- add cos/sin/atan/tan support for unary for tensorflow model;
	- add any/all support for reduction for tensorflow model;
	- add elu, conv3d, pool3d support for tensorflow model;
	- optimize argmax, batchnorm, concat, batch to space, conv with variable weights, prelu, slice for tensorflow model;
- others:
	- fix size computer lock;
	- fix thread pool deadlock;
	- add express & parameters in express;
	- rewrite blitter chooser without static map;
	- add tests for expr;
											
										 
											2019-10-29 13:37:26 +08:00
										 |  |  | #include "MNN_generated.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace MNN { | 
					
						
							|  |  |  | struct OperatorInfo::Info { | 
					
						
							|  |  |  |     std::string name; | 
					
						
							|  |  |  |     std::string type; | 
					
						
							|  |  |  |     float flops = 0.0f; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | class SizeComputer; | 
					
						
							|  |  |  | /** pipeline. one session may contains multiple pipeline, and one pipeline may contains more than one unit. */ | 
					
						
							|  |  |  | class Pipeline : public NonCopyable { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * @brief initialize with pipeline info, major backend and backup backend (usually CPU). | 
					
						
							|  |  |  |      * @param info      given pipeline info. | 
					
						
							|  |  |  |      * @param major     given major backend used to create execution. | 
					
						
							|  |  |  |      * @param backup    given backend backend if op is not supported by major backend. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     Pipeline(const std::vector<Schedule::PipelineInfo>& info, Backend* major, Backend* backup); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * @brief prepare all units. | 
					
						
							|  |  |  |      * @return result code. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     ErrorCode prepare(); | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * @brief execute all units. | 
					
						
							|  |  |  |      * @return result code. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     ErrorCode execute(); | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * @brief execute all units with callbacks. | 
					
						
							|  |  |  |      * @param before    callback before execute each op. | 
					
						
							|  |  |  |      * @param after     callback after execute each op. | 
					
						
							|  |  |  |      * @return result code. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     ErrorCode executeCallBack(const TensorCallBackWithInfo& before, const TensorCallBackWithInfo& after); | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * @brief the Pipline need not prepare any more, release all cache used for resize. | 
					
						
							|  |  |  |      * @return errorcode | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     ErrorCode releaseCache(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** op unit in pipeline */ | 
					
						
							|  |  |  |     class Unit : public NonCopyable, public OperatorInfo { | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         /**
 | 
					
						
							|  |  |  |          * @brief initialize with given op and its in-out tensors. | 
					
						
							|  |  |  |          * @param op        given op. | 
					
						
							|  |  |  |          * @param inputs    execution input tensors. | 
					
						
							|  |  |  |          * @param outputs   execution output tensors. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         Unit(const Op* op, const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /**
 | 
					
						
							|  |  |  |          * @brief prepare unit. | 
					
						
							|  |  |  |          * @return result code. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         ErrorCode prepare(Backend* major, Backend* backup); | 
					
						
							|  |  |  |         /**
 | 
					
						
							|  |  |  |          * @brief execute unit. | 
					
						
							|  |  |  |          * @return result code. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         ErrorCode execute(); | 
					
						
							|  |  |  |         /**
 | 
					
						
							|  |  |  |          * @brief execute unit with callbacks. | 
					
						
							|  |  |  |          * @param before    callback before execute each op. | 
					
						
							|  |  |  |          * @param after     callback after execute each op. | 
					
						
							|  |  |  |          * @return result code. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         ErrorCode executeCallBack(const TensorCallBackWithInfo& before, const TensorCallBackWithInfo& after); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         /** op execution */ | 
					
						
							|  |  |  |         std::shared_ptr<Execution> mExecution; | 
					
						
							|  |  |  |         /** op type*/ | 
					
						
							|  |  |  |         OpType mType; | 
					
						
							|  |  |  |         /** input tensors */ | 
					
						
							|  |  |  |         std::vector<Tensor*> mInputs; | 
					
						
							|  |  |  |         /** output tensors */ | 
					
						
							|  |  |  |         std::vector<Tensor*> mOutputs; | 
					
						
							|  |  |  |         /** op */ | 
					
						
							|  |  |  |         const Op* mOriginOp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         bool _createExecution(Backend* bn, Backend* cpuBn); | 
					
						
							|  |  |  |         bool _allocTensors(Backend* bn, const std::vector<Tensor*>& tensors); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         bool mConst                   = false; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     /*Used for Unit Test*/ | 
					
						
							|  |  |  |     const std::vector<std::shared_ptr<Unit>>& getUnit() const { | 
					
						
							|  |  |  |         return this->mUnits; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     Backend* mBackend; | 
					
						
							|  |  |  |     Backend* mBackupBackend; | 
					
						
							|  |  |  |     std::vector<std::shared_ptr<Unit>> mUnits; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | } // namespace MNN
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* Pipeline_hpp */
 |