2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//  Pipeline.cpp
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//  MNN
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//  Created by MNN on 2019/01/14.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//  Copyright © 2018, Alibaba Group Holding Limited
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <string.h>
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/Pipeline.hpp"
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/Backend.hpp"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "core/Macro.h"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "core/TensorUtils.hpp"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "core/WrapExecution.hpp"
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "geometry/GeometryComputerUtils.hpp"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "shape/SizeComputer.hpp"
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "core/OpCommonUtils.hpp"
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
											 
										 
										
											
												[MNN:Sync] Sync internal github
Commits:
        8148ae75c  弗人  bugfix
        14cb8ec7f  弗人  [Converter:Bugfix] bugfix for onnx depthwise convtranspose
        476fbcd90  雁行  [MNN:Feature] Open AVX cast and bugfix for contentCFG.
        5e26b9fd3  雁行  [Test:Feature] Add android test.
        37e147b25  雁行  [MNN:Bugfix] Bugfix for floordiv.
        144c185f5  tianbu.xsw  hangxing fix hiai
        b4fd429d6  tianbu.xsw  updateCacheFile bugfix -- update cache size
        d4ba572a8  雁行  [MNN:Bugfix] Support int8 in AVX2 and some Bugfix.
        43061f07e  xiaying  [MNN:Bugfix] Fix bug for module mode run part of model
        398cc5ab6  tianhang.yth  refactor demo
        736380600  xiaying  [Express:Bugfix] Fix memory leak for copy branch
        b8dab0a27  tianhang.yth  MNNFloat2Int8 sizeQuad=0 crash fix
        94b95bfed  ghz  [BugFix]1.Better method for fast pack valid check
        6a921f85e  xiaying  [Converter:Bugfix] Fix bug for Fuseconsttosubgraph
        5f77ae889  tianhang.yth  numThread bugfix
        a807ef879  tianhang.yth  add createSession(configs, runtimeinfo) API, add pymnn demo, pymnn logcat bugfix
        ad05409d3  xiaying  [MNN:Bugfix] Fix bug for StaticModule's sizecompute overflow, add error print for module mode
        9d81b8299  xiaying  [MNN:Bugfix] Fix bug for Unique op for output size = 1
        03b15e9af  xiaying  [Test:Feature] Add MatMulBConst Test, Fix bug for single Convert
        c944a76ee  tianhang.yth  add auto backend and getSessionInfo @tianbu
        91fa7267b  ghz  [BugFix]1.fix the error in eP check
        bf0041f77  ghz  [BugFix]1.Fix the logic error in eP check. 2.Fix the sp align error
        693871672  雁行  [CPU:Bugfix] rm adrp instruction for clang compiler bug.
        1b8f6b3d8  ghz  1.Fix the wronly use of r13 in arm32 version. 2.Fix the missing callee register save and restore process.
        feb7ecc4c  弗人  modify log of python offline quant
        040c04811  ghz  [BufFix]1.replace platform-related regs. 2.fix the same problem in arm32 version
        609f37db8  弗人  add log for python quant, python convert
        5511dd30a  ghz  [BugFix]1.Add testcases in SparseConv to check all functional code branch. 2. Fix the bug in "MNNPackC4ForMatMul_A.S" in arm64, which is caused by the missing check of eReal parameter.
        a93ff9280  tianhang.yth  add tf.Unique op support
        9729ff773  allen.lk  [Bugfix] Fix one arm32 instruction syntax that clang works but gcc DOES NOT work. use index instruction instead.
        297c1ad14  雁行  [Expr:Bugfix] bugfix for tensor content used by shape compute.
        ef8c369e3  弗人  catch exception
        07c2dd670  弗人  add dependence to setup, base64 encode url, add time log
        177e590c1  弗人  [Python:Feature] add aliyun log for python quant tool
        40a7928cf  allen.lk  [Debug:Sparse] 1.Add group parameter in torchscript converter. 2. Stop split running to avoid memory corruption when check failed in TransformGroupConvolution 3. fix Op split issue in TransformGroupConvolution
        3bdea84a1  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        c3c6fbdbd  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        bc590eee4  雁行  [Converter:Bugfix] bugfix for onnx instancenormalization convert.
        d8918593f  tianhang.yth  add auto backend and getSessionInfo @tianbu
        83a198ed7  杭行  update
        d0dd3e09b  杭行  update
        99540202e  xiaying  [Converter:Optimize] Opt the tensor convert insert
        333d8db82  allen.lk  [Debug:Sparse] Fix All platform-register r9 / x18 issue on arm32 and arm64.
        db5994672  杭行  merge
        6293de7b8  tianbu.xsw  fix pymnn updateCacheFile
        5c2e11cb1  tianbu.xsw  do updateCache in createSession
        6e7641ff4  tianbu.xsw  do not limit cacheFile for a model
        5287a65e4  tianbu.xsw  bugfix
        52ba53a91  tianbu.xsw  revert pymnn api
        60284d830  tianbu.xsw  bugfix
        6d8077490  tianbu.xsw  rename updateCacheFile api params
        3cb172710  tianhang.yth  updateCacheFile API size default value is 0
        c5b69aabf  tianbu.xsw  updateCacheFile python api fix
        5d5da7aa5  tianbu.xsw  reflector code
        5707877a4  雁行  [MNN:Speed] Speedup for softmax in x86 and arm.
        2a211825c  tianbu.xsw  reflector code for updateCacheFile
        76db3a835  tianbu.xsw  [Cache Feature]: Add updateCacheFile API for increment cache
        b06b0fd43  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        e68bfa495  雁行  [Converter:Feature] Add UUID when model convert.
        a9cb935dc  xiaying  [MNN:Speed] Support c4nhwc for more fastblit
        019f40353  xiaying  [Converter:Refractor] Reduce memory used by MNNConvert(bert from 5G ->         1G)
        d2a6d3d05  xiaying  [MNN:Bugfix] Fix bug for identity output not find
        604d0801b  xiaying  [Converter:Bugfix] Fix bug for FuseGeLu
        4bada2367  xiaying  [MNN:Refractor] SegmentMean rewrite as segment
        82070e708  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary
        e8ea4266e  xiaying  Fix bug for ShapeTensorConvert compute for dim = 1 error
        1f1cf1991  xiaying  [Tools:Bugfix] Fix system compability for fastTestOnnx
        6f422efe2  xiaying  [Tools:Bugfix] Remove color for checkDir for easy to dump
        968f7ec88  xiaying  [MNN:Speed] Support turn broadcast binary to loop
        3e7aaf46f  xiaying  [MNN:Refractor] Set Convolution1x1Strassen support variable input/output ptr
        1f65ab163  xiaying  [MNN:Bugfix] Fix bug for mini mnn can't convert model
        d65953d47  xiaying  [MNN:Bugfix] Fix bug for armv7a - android-14 + ARM82
        8b68be45c  xiaying  [MNN:Feature] Add segment
        8a8f264f5  xiaying  [Vulkan:Bugfix] Remove unuseful print
        025bb0fda  xiaying  [Converter:Bugfix] Fix bug for oneof don't support
        43900251e  tianbu.xsw  enable setCacheFile python API
        ebfb05c74  tianbu.xsw  [Metal Feature] support metallib obtain from walle transfer task
        9665c0a79  弗人  add check for path in json file
        c66fef224  xiaying  [Converter:Bugfix] Fix bug for oneof don't support
        42f192852  xiaying  [MNN:Bugfix] Fix bug for not set output / saveTensor into origin Schedule's outputs
        1b95354ff  雁行  [Feature]: Support shape compute for SetDiff1D, and null input for Prod.
        83966d043  xiaying  [Test:Feature] Add test for static module
        42d1be933  xiaying  [Converter:Bugfix] Fix bug for mnn convert and static model add more outputs for origin model
        9067531c3  xiaying  [Converter:Refractor] formatLicence
        99558bed9  xiaying  [Converter:Bugfix] Count the op for unuseful and controlflow
        4f6da0fa7  allen.lk  [Feature:GRUMultiOutput] fix multi output dimension type
        c6b219bce  xiaying  [Converter:Feature] Turn torch converter to object
        dd4e68a37  xiaying  [Converter:Feature] Support dump supported ops
        80b6a60a3  xiaying  [Converter:Info] If has output name, print output name instead of computed
        015278fc3  xiaying  [MNN:Refractor] Revert IfModule's debug info
        23ac967c4  xiaying  Don't transform for multi-input convolution/deconvolution
        b02b0d4de  xiaying  Fix bug for multi-input for conv1d
        254d8b1d4  xiaying  Fix bug for Conv1dSqueezeMove for multi input convolution 1d
        d47d0b9ca  xiaying  Fix bug for CPURaster's fuse nc4hw4
        357c5bd33  xiaying  Fix ConvBiasAdd for conv's inputs op > 1
        55b1f0c9c  xiaying  [Converter:Bugfix] Don't transform for multi-input convolution/deconvolution
        1902a30f5  xiaying  [Converter:Bugfix] Fix bug for Conv1dSqueezeMove for multi input convolution 1d
        c23fe617b  xiaying  [MNN:Bugfix] Fix bug for multi-input for conv1d
        8ff018426  xiaying  [MNN:Bugfix] Fix bug for CPURaster's fuse nc4hw4
        d4e8cd602  xiaying  [Converter:Bugfix] Fix ConvBiasAdd for conv's inputs op > 1
        846266b42  tianbu.xsw  return when program and tune both nullptr
        fd67c76a9  xiaying  [Converter:Bugfix] DepthwiseConvWeightMerge only valid for tflite
        e77a242c4  xiaying  [Converter:Feature] Support tflite's half pixel
        be054c377  tianbu.xsw  [OpenCL Bugfix] do not rewrite cache when binary program is produced
        51e65aa35  xiaying  [Converter:Feature] Support tflite for fp16 and multi-input convolution
        1ccdfdeb5  tianbu.xsw  redefine svm macro name
        31234d372  tianbu.xsw  [OpenCL SVM] add macro for only use wrapper
        d739e35da  xiaying  [MNN:Bugfix] Fix compile bug for grid op
        24ab13c79  Joker  feat(arm82): add GridSample op support in arm82 backend, AVX(by xiaying)
        7b142978e  xiaying  [AVX512:Speed] Optimize for e <= 8
        5f6febe7b  tianbu.xsw  code refactor
        998d91b57  xiaying  [Express:Speed] Merge submodule for speed
        22c89146f  tianhang.yth  fix alpha div by zero bug and arm server compile bug
        8f829a170  tianbu.xsw  [OpenCL Pad] unify conv/deconv pad computing
        4a28f603e  xiaying  [Express:Speed] Shared Const for All Submodule
        c74cf28f3  xiaying  [MNN:Refractor] Seperate Const init and schedule
        2a1eebb7a  xiaying  [Tools:Bugfix] Fix bug for modelTest.py count size
        72f04008c  xiaying  [MNN:Refractor] Delete unuseful const op
        1e735d03c  xiaying  [Converter:Bugfix] Fix bug for static module gen
        4dfadbc6e  xiaying  [MNN:Refractor] Rewrite const init mode
        1fcf0417a  xiaying  [MNN:Bugfix] Fix bug for deconvolutin multi-input for multi-batch
        41d429cfd  xiaying  [Train:Bugfix] Revert convert NCHW for mnistTrain
        f947a5f01  xiaying  [Test:Feature] Add testTrain
        dad59b6f6  tianbu.xsw  move realize code from Backend.hpp to Tensor.cpp
        cf4473ad1  xiaying  [Train:Bugfix] Support pad for GeometryPoolGrad
        91ab13734  xiaying  [MNN:Bugfix] Fix compile bug for avx512
        742e80f47  xiaying  [MNN:Refractor] Opt the logic for checknan judge
        12543b841  xiaying  [ARM82:Bugfix] Fix compile bug for ios
        3a2b0a49f  xiaying  [ARM82:Speed] Opt Pack / Unpack for armv8
        c0f1995cd  xiaying  [ARM82:Speed] Opt MNNPackC8FP16 and MNNUnpackC8FP16 by asm
        e0fc77dcf  xiaying  [MNN:Speed] Fix bug for DeconvolutionWithStride for C4HW4, open it
        584bec578  xiaying  [MNN:Bugfix] Fix bug for format set error for onnx
        d5bd4148d  xiaying  [MNN:Bugfix] Fix bug for format set error for onnx
        b00265841  xiaying  [MNN:Bugfix] Fix bug for SparseConvolutionTiledExecutor
        bb09188ac  xiaying  [Test:Bugfix] Fix bug for run into sparse auto
        426d1babd  xiaying  [MNN:Refractor] Small bugfix for Group convolution and pack
        7d0ea1c46  tianbu.xsw  [testModel Feature] support testModel.out input resize
        4169c54ce  xiaying  [MNN:Bugfix] Fix bug for checkNAN for origin
        412a82222  xiaying  [Test:Bugfix] Fix bug for CheckNAN's error of matmul
        319b1d425  xiaying  [MNN:Bugfix] Fix bug for multi-batch for ConvInt8
        050b728a6  xiaying  [Test:Bugfix] Use NCHW for ConvInt8Test
        7db3423a1  xiaying  [OpenCL:Bugfix] Fix bug for opencl::image,opencl::buffer for C4HW4
        adcec6a7f  xiaying  [Vulkan:Bugfix] Fix bug for invalid tensor size limit
        d2a7cf4e9  xiaying  [Vulkan:Bugfix] Fix bug for onCopyBuffer of nc4hw4
        557bebdd3  xiaying  [MNN:Bugfix] Fix bug for BF16-ARM32
        bbe186649  tianbu.xsw  [Update AUTO mode]: fix MNN_FORWARD_AUTO choose priority
        6deb23439  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size
        b137590e4  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size
        7003558ea  xiaying  [Converter:Bugfix] Fix bug for onnx pad for serveral case
        b5f8cae5a  xiaying  [Converter:Bugfix] Fix bug for onnx pad for serveral case
        29b09e125  xiaying  [MNN:Bugfix] Fix bug for arm64-bf16
        42ce00770  xiaying  [MNN:Bugfix] Fix bug for ARM64 - float
        a2d89fc18  雁行  [Converter:Feature] Support Binary Unary for Torch.
        7f1c0deb1  xiaying  [MNN:Bugfix] Fix bug for Raster for Int8
        8335a6f18  tianbu.xsw  [OpenCL Shared Memory] modify data_format method
        b359e031b  xiaying  [ARM82:Bugfix] Fix bug for arm82 and speed up pack / unpack c8
        24bf3fc88  雁行  [Convert:Feature] Support LayerNormFuse without gamma beta.
        3e629624b  xiaying  [MNN:Bugfix] Fix bug for float - armv7a
        2b7908ec7  tianbu.xsw  modify workItemSize
        3cee0d413  xiaying  [MNN:Bugfix] test wrong clear
        9cbbfb998  xiaying  [MNN:Bugfix] fix compile bug for c++ < 14
        2d7a44484  xiaying  [MNN:Bugfix] fix compile bug for c++ < 14
        eb7d0cb53  xiaying  [Test:Bugfix] Don't test for NC4HW4 directly
        7b40ca8d1  xiaying  [MNN:Bugfix] Fix bug for ConvolutionGroup
        2694d8a91  xiaying  [MNN:Bugfix] Fix bug for CPUGridSample
        f89af60f6  xiaying  [MNN:Bugfix] Fix compile bug for arm
        a151abcdd  xiaying  [MNN:Bugfix] Fix bug for convert for int8 / int16
        b254dbe61  雁行  [MNN:Bugfix] Bugfix for Conv onClone.
        d08150631  xiaying  [MNN:Bugfix] Fix bug for fast rcnn
        e5568a0df  xiaying  [MNN:Bugfix] Fix bug for CPURaster treat NC4HW4 fast blit
        128318933  雁行  [Raster:Bugfix] bugfix for Raster merge onResize.
        03caacbea  xiaying  [MNN:Bugfix] fix bug for CPUDeconvolution and Convolution1x1Strassen for iw != ow
        e1e3c245c  xiaying  [MNN:Bugfix] Fix bug for ConvolutionWinograd
        2524cbc6d  xiaying  [MNN:Bugfix] Fix bug for CPUSoftmax
        44ec79b8f  xiaying  [MNN:Bugfix] Fix bug for CPUConvolutionDepthwise / Scale / DeconvolutionDW
        21ae956ce  xiaying  [MNN:Bugfix] Fix bug for Multi-Batch-TiledExecutor
        09a5069c7  xiaying  [MNN:Speed] Add offset for src and dst
        6776c6784  xiaying  [MNN:Bugfix] Fix bug for trainable model
        cc83ae30b  xiaying  [MNN:Bugfix] Fix bug for trainable model
											
										 
										
											2021-07-29 11:46:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// TODO: Find better way for debug
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//#define MNN_OP_SEPERATE
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-18 09:36:26 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//#define MNN_PIPELINE_DEBUG
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								namespace MNN {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-12-04 11:12:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// FIXME: Move in Backend
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static bool _supportQuant(const Op* op, const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs, MNNForwardType type) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto otype = op->type();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    switch (otype) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        case OpType_Convolution:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        case OpType_ConvolutionDepthwise:
							 | 
						
					
						
							
								
									
										
										
										
											2024-12-19 16:20:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//        case OpType_Deconvolution:
							 | 
						
					
						
							
								
									
										
										
										
											2024-11-18 14:37:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (inputs.size() > 1) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (op->main_as_Convolution2D() && op->main_as_Convolution2D()->weight() != nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        case OpType_ConvInt8:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        case OpType_DepthwiseConvInt8:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-04 11:53:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            // case OpType_Eltwise:
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        case OpType_Raster:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto input : inputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (TensorUtils::getDescribe(input)->quantAttr.get() != TensorUtils::getDescribe(outputs[0])->quantAttr.get()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        case OpType_ReLU:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (TensorUtils::getDescribe(inputs[0])->quantAttr.get() != TensorUtils::getDescribe(outputs[0])->quantAttr.get()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // now just relu without slope support quant
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if ((op->main_as_Relu() == nullptr) || op->main_as_Relu()->slope() == 0.f) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        case OpType_Pooling:
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-15 10:30:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (op->main_as_Pool() && op->main_as_Pool()->type() == PoolType_MAXPOOL ) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            } else if (op->main_as_Pool() && op->main_as_Pool()->type() == PoolType_AVEPOOL) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return true;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            } else {
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-15 10:30:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                return false;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-04 11:53:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        case OpType_BinaryOp:
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-31 14:24:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        case OpType_Softmax:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        case OpType_Scale:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        case OpType_Interp:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-04 10:42:11 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        case OpType_LayerNorm:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							
								
									
										
										
										
											2023-10-18 10:31:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        case OpType_UnaryOp:
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-04 11:53:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (op->main_as_UnaryOp()->tableInt8() || op->main_as_UnaryOp()->opType() == UnaryOpOperation_NEG || op->main_as_UnaryOp()->opType() == UnaryOpOperation_ABS || op->main_as_UnaryOp()->opType() == UnaryOpOperation_SIGN) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2023-10-18 10:31:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        case OpType_PReLU:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        default:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								OperatorInfo::OperatorInfo() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mContent = new Info;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    MNN_ASSERT(nullptr != mContent);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								OperatorInfo::~OperatorInfo() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    delete mContent;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const std::string& OperatorInfo::name() const {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return mContent->name;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const std::string& OperatorInfo::type() const {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return mContent->type;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								float OperatorInfo::flops() const {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return mContent->flops;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static Backend::StorageType _getTensorStorageType(const Tensor* tensor, bool outputStatic) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto des   = TensorUtils::getDescribe(tensor);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 13:33:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto usage = des->usage;
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (TensorUsage::OUTPUT == usage && outputStatic) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return Backend::STATIC;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (TensorUsage::CONSTANT == usage || TensorUsage::INPUT == usage || TensorUsage::TRAINABLE == usage) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return Backend::DYNAMIC_SEPERATE;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return Backend::DYNAMIC;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static bool _needRelease(const Tensor* tensor, bool inputOutside) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto des   = TensorUtils::getDescribe(tensor);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto desO   = TensorUtils::getDescribeOrigin(tensor);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-15 13:33:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto usage = des->usage;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (0 != des->useCount) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (des->memoryType == Tensor::InsideDescribe::MEMORY_HOST || des->memoryType == Tensor::InsideDescribe::MEMORY_OUTSIDE) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (nullptr == desO->getBackend()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (inputOutside) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return usage == Tensor::InsideDescribe::NORMAL;
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-15 14:12:35 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (tensor->buffer().type.code == halide_type_handle) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return false;
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (TensorUsage::CONSTANT == usage || TensorUsage::TRAINABLE == usage || TensorUsage::OUTPUT == usage) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return false;
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static void _releaseTensor(Tensor* origin, bool mAllocInput, int group) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto des = TensorUtils::getDescribe(origin);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (des->usage != Tensor::InsideDescribe::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        des->useCount -= 1;
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-04 10:42:11 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (des->group != group) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto needRelease = _needRelease(origin, !mAllocInput);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (needRelease) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        TensorUtils::getDescribeOrigin(origin)->mem = nullptr;
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-07 10:45:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static bool _allocTensor(Tensor* t, Backend* curBackend, bool outputStatic, int group) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto memoryType = _getTensorStorageType(t, outputStatic);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto bn         = TensorUtils::getDescribeOrigin(t)->getBackend();
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-07 10:45:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto des = TensorUtils::getDescribe(t);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (des->group != group) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (nullptr == TensorUtils::getDescribeOrigin(t)->mem.get()) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-07 10:45:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        TensorUtils::setLinearLayout(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto res     = curBackend->onAcquireBuffer(t, memoryType);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return res;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void Pipeline::UnitInfo::setUp(const Command& command, int index, const Op* originOp, int totalIndex) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (nullptr != command.op->name()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mContent->name = command.op->name()->str();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (nullptr != originOp && nullptr != originOp->name()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            char buffer[20];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            sprintf(buffer, "%d", index);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            mContent->name = originOp->name()->str() + "_raster_" + buffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            char buffer[20];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            sprintf(buffer, "_raster_%d", totalIndex);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            mContent->name = buffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
											 
										 
										
											
												[MNN:Sync] Sync internal github
Commits:
        8148ae75c  弗人  bugfix
        14cb8ec7f  弗人  [Converter:Bugfix] bugfix for onnx depthwise convtranspose
        476fbcd90  雁行  [MNN:Feature] Open AVX cast and bugfix for contentCFG.
        5e26b9fd3  雁行  [Test:Feature] Add android test.
        37e147b25  雁行  [MNN:Bugfix] Bugfix for floordiv.
        144c185f5  tianbu.xsw  hangxing fix hiai
        b4fd429d6  tianbu.xsw  updateCacheFile bugfix -- update cache size
        d4ba572a8  雁行  [MNN:Bugfix] Support int8 in AVX2 and some Bugfix.
        43061f07e  xiaying  [MNN:Bugfix] Fix bug for module mode run part of model
        398cc5ab6  tianhang.yth  refactor demo
        736380600  xiaying  [Express:Bugfix] Fix memory leak for copy branch
        b8dab0a27  tianhang.yth  MNNFloat2Int8 sizeQuad=0 crash fix
        94b95bfed  ghz  [BugFix]1.Better method for fast pack valid check
        6a921f85e  xiaying  [Converter:Bugfix] Fix bug for Fuseconsttosubgraph
        5f77ae889  tianhang.yth  numThread bugfix
        a807ef879  tianhang.yth  add createSession(configs, runtimeinfo) API, add pymnn demo, pymnn logcat bugfix
        ad05409d3  xiaying  [MNN:Bugfix] Fix bug for StaticModule's sizecompute overflow, add error print for module mode
        9d81b8299  xiaying  [MNN:Bugfix] Fix bug for Unique op for output size = 1
        03b15e9af  xiaying  [Test:Feature] Add MatMulBConst Test, Fix bug for single Convert
        c944a76ee  tianhang.yth  add auto backend and getSessionInfo @tianbu
        91fa7267b  ghz  [BugFix]1.fix the error in eP check
        bf0041f77  ghz  [BugFix]1.Fix the logic error in eP check. 2.Fix the sp align error
        693871672  雁行  [CPU:Bugfix] rm adrp instruction for clang compiler bug.
        1b8f6b3d8  ghz  1.Fix the wronly use of r13 in arm32 version. 2.Fix the missing callee register save and restore process.
        feb7ecc4c  弗人  modify log of python offline quant
        040c04811  ghz  [BufFix]1.replace platform-related regs. 2.fix the same problem in arm32 version
        609f37db8  弗人  add log for python quant, python convert
        5511dd30a  ghz  [BugFix]1.Add testcases in SparseConv to check all functional code branch. 2. Fix the bug in "MNNPackC4ForMatMul_A.S" in arm64, which is caused by the missing check of eReal parameter.
        a93ff9280  tianhang.yth  add tf.Unique op support
        9729ff773  allen.lk  [Bugfix] Fix one arm32 instruction syntax that clang works but gcc DOES NOT work. use index instruction instead.
        297c1ad14  雁行  [Expr:Bugfix] bugfix for tensor content used by shape compute.
        ef8c369e3  弗人  catch exception
        07c2dd670  弗人  add dependence to setup, base64 encode url, add time log
        177e590c1  弗人  [Python:Feature] add aliyun log for python quant tool
        40a7928cf  allen.lk  [Debug:Sparse] 1.Add group parameter in torchscript converter. 2. Stop split running to avoid memory corruption when check failed in TransformGroupConvolution 3. fix Op split issue in TransformGroupConvolution
        3bdea84a1  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        c3c6fbdbd  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        bc590eee4  雁行  [Converter:Bugfix] bugfix for onnx instancenormalization convert.
        d8918593f  tianhang.yth  add auto backend and getSessionInfo @tianbu
        83a198ed7  杭行  update
        d0dd3e09b  杭行  update
        99540202e  xiaying  [Converter:Optimize] Opt the tensor convert insert
        333d8db82  allen.lk  [Debug:Sparse] Fix All platform-register r9 / x18 issue on arm32 and arm64.
        db5994672  杭行  merge
        6293de7b8  tianbu.xsw  fix pymnn updateCacheFile
        5c2e11cb1  tianbu.xsw  do updateCache in createSession
        6e7641ff4  tianbu.xsw  do not limit cacheFile for a model
        5287a65e4  tianbu.xsw  bugfix
        52ba53a91  tianbu.xsw  revert pymnn api
        60284d830  tianbu.xsw  bugfix
        6d8077490  tianbu.xsw  rename updateCacheFile api params
        3cb172710  tianhang.yth  updateCacheFile API size default value is 0
        c5b69aabf  tianbu.xsw  updateCacheFile python api fix
        5d5da7aa5  tianbu.xsw  reflector code
        5707877a4  雁行  [MNN:Speed] Speedup for softmax in x86 and arm.
        2a211825c  tianbu.xsw  reflector code for updateCacheFile
        76db3a835  tianbu.xsw  [Cache Feature]: Add updateCacheFile API for increment cache
        b06b0fd43  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        e68bfa495  雁行  [Converter:Feature] Add UUID when model convert.
        a9cb935dc  xiaying  [MNN:Speed] Support c4nhwc for more fastblit
        019f40353  xiaying  [Converter:Refractor] Reduce memory used by MNNConvert(bert from 5G ->         1G)
        d2a6d3d05  xiaying  [MNN:Bugfix] Fix bug for identity output not find
        604d0801b  xiaying  [Converter:Bugfix] Fix bug for FuseGeLu
        4bada2367  xiaying  [MNN:Refractor] SegmentMean rewrite as segment
        82070e708  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary
        e8ea4266e  xiaying  Fix bug for ShapeTensorConvert compute for dim = 1 error
        1f1cf1991  xiaying  [Tools:Bugfix] Fix system compability for fastTestOnnx
        6f422efe2  xiaying  [Tools:Bugfix] Remove color for checkDir for easy to dump
        968f7ec88  xiaying  [MNN:Speed] Support turn broadcast binary to loop
        3e7aaf46f  xiaying  [MNN:Refractor] Set Convolution1x1Strassen support variable input/output ptr
        1f65ab163  xiaying  [MNN:Bugfix] Fix bug for mini mnn can't convert model
        d65953d47  xiaying  [MNN:Bugfix] Fix bug for armv7a - android-14 + ARM82
        8b68be45c  xiaying  [MNN:Feature] Add segment
        8a8f264f5  xiaying  [Vulkan:Bugfix] Remove unuseful print
        025bb0fda  xiaying  [Converter:Bugfix] Fix bug for oneof don't support
        43900251e  tianbu.xsw  enable setCacheFile python API
        ebfb05c74  tianbu.xsw  [Metal Feature] support metallib obtain from walle transfer task
        9665c0a79  弗人  add check for path in json file
        c66fef224  xiaying  [Converter:Bugfix] Fix bug for oneof don't support
        42f192852  xiaying  [MNN:Bugfix] Fix bug for not set output / saveTensor into origin Schedule's outputs
        1b95354ff  雁行  [Feature]: Support shape compute for SetDiff1D, and null input for Prod.
        83966d043  xiaying  [Test:Feature] Add test for static module
        42d1be933  xiaying  [Converter:Bugfix] Fix bug for mnn convert and static model add more outputs for origin model
        9067531c3  xiaying  [Converter:Refractor] formatLicence
        99558bed9  xiaying  [Converter:Bugfix] Count the op for unuseful and controlflow
        4f6da0fa7  allen.lk  [Feature:GRUMultiOutput] fix multi output dimension type
        c6b219bce  xiaying  [Converter:Feature] Turn torch converter to object
        dd4e68a37  xiaying  [Converter:Feature] Support dump supported ops
        80b6a60a3  xiaying  [Converter:Info] If has output name, print output name instead of computed
        015278fc3  xiaying  [MNN:Refractor] Revert IfModule's debug info
        23ac967c4  xiaying  Don't transform for multi-input convolution/deconvolution
        b02b0d4de  xiaying  Fix bug for multi-input for conv1d
        254d8b1d4  xiaying  Fix bug for Conv1dSqueezeMove for multi input convolution 1d
        d47d0b9ca  xiaying  Fix bug for CPURaster's fuse nc4hw4
        357c5bd33  xiaying  Fix ConvBiasAdd for conv's inputs op > 1
        55b1f0c9c  xiaying  [Converter:Bugfix] Don't transform for multi-input convolution/deconvolution
        1902a30f5  xiaying  [Converter:Bugfix] Fix bug for Conv1dSqueezeMove for multi input convolution 1d
        c23fe617b  xiaying  [MNN:Bugfix] Fix bug for multi-input for conv1d
        8ff018426  xiaying  [MNN:Bugfix] Fix bug for CPURaster's fuse nc4hw4
        d4e8cd602  xiaying  [Converter:Bugfix] Fix ConvBiasAdd for conv's inputs op > 1
        846266b42  tianbu.xsw  return when program and tune both nullptr
        fd67c76a9  xiaying  [Converter:Bugfix] DepthwiseConvWeightMerge only valid for tflite
        e77a242c4  xiaying  [Converter:Feature] Support tflite's half pixel
        be054c377  tianbu.xsw  [OpenCL Bugfix] do not rewrite cache when binary program is produced
        51e65aa35  xiaying  [Converter:Feature] Support tflite for fp16 and multi-input convolution
        1ccdfdeb5  tianbu.xsw  redefine svm macro name
        31234d372  tianbu.xsw  [OpenCL SVM] add macro for only use wrapper
        d739e35da  xiaying  [MNN:Bugfix] Fix compile bug for grid op
        24ab13c79  Joker  feat(arm82): add GridSample op support in arm82 backend, AVX(by xiaying)
        7b142978e  xiaying  [AVX512:Speed] Optimize for e <= 8
        5f6febe7b  tianbu.xsw  code refactor
        998d91b57  xiaying  [Express:Speed] Merge submodule for speed
        22c89146f  tianhang.yth  fix alpha div by zero bug and arm server compile bug
        8f829a170  tianbu.xsw  [OpenCL Pad] unify conv/deconv pad computing
        4a28f603e  xiaying  [Express:Speed] Shared Const for All Submodule
        c74cf28f3  xiaying  [MNN:Refractor] Seperate Const init and schedule
        2a1eebb7a  xiaying  [Tools:Bugfix] Fix bug for modelTest.py count size
        72f04008c  xiaying  [MNN:Refractor] Delete unuseful const op
        1e735d03c  xiaying  [Converter:Bugfix] Fix bug for static module gen
        4dfadbc6e  xiaying  [MNN:Refractor] Rewrite const init mode
        1fcf0417a  xiaying  [MNN:Bugfix] Fix bug for deconvolutin multi-input for multi-batch
        41d429cfd  xiaying  [Train:Bugfix] Revert convert NCHW for mnistTrain
        f947a5f01  xiaying  [Test:Feature] Add testTrain
        dad59b6f6  tianbu.xsw  move realize code from Backend.hpp to Tensor.cpp
        cf4473ad1  xiaying  [Train:Bugfix] Support pad for GeometryPoolGrad
        91ab13734  xiaying  [MNN:Bugfix] Fix compile bug for avx512
        742e80f47  xiaying  [MNN:Refractor] Opt the logic for checknan judge
        12543b841  xiaying  [ARM82:Bugfix] Fix compile bug for ios
        3a2b0a49f  xiaying  [ARM82:Speed] Opt Pack / Unpack for armv8
        c0f1995cd  xiaying  [ARM82:Speed] Opt MNNPackC8FP16 and MNNUnpackC8FP16 by asm
        e0fc77dcf  xiaying  [MNN:Speed] Fix bug for DeconvolutionWithStride for C4HW4, open it
        584bec578  xiaying  [MNN:Bugfix] Fix bug for format set error for onnx
        d5bd4148d  xiaying  [MNN:Bugfix] Fix bug for format set error for onnx
        b00265841  xiaying  [MNN:Bugfix] Fix bug for SparseConvolutionTiledExecutor
        bb09188ac  xiaying  [Test:Bugfix] Fix bug for run into sparse auto
        426d1babd  xiaying  [MNN:Refractor] Small bugfix for Group convolution and pack
        7d0ea1c46  tianbu.xsw  [testModel Feature] support testModel.out input resize
        4169c54ce  xiaying  [MNN:Bugfix] Fix bug for checkNAN for origin
        412a82222  xiaying  [Test:Bugfix] Fix bug for CheckNAN's error of matmul
        319b1d425  xiaying  [MNN:Bugfix] Fix bug for multi-batch for ConvInt8
        050b728a6  xiaying  [Test:Bugfix] Use NCHW for ConvInt8Test
        7db3423a1  xiaying  [OpenCL:Bugfix] Fix bug for opencl::image,opencl::buffer for C4HW4
        adcec6a7f  xiaying  [Vulkan:Bugfix] Fix bug for invalid tensor size limit
        d2a7cf4e9  xiaying  [Vulkan:Bugfix] Fix bug for onCopyBuffer of nc4hw4
        557bebdd3  xiaying  [MNN:Bugfix] Fix bug for BF16-ARM32
        bbe186649  tianbu.xsw  [Update AUTO mode]: fix MNN_FORWARD_AUTO choose priority
        6deb23439  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size
        b137590e4  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size
        7003558ea  xiaying  [Converter:Bugfix] Fix bug for onnx pad for serveral case
        b5f8cae5a  xiaying  [Converter:Bugfix] Fix bug for onnx pad for serveral case
        29b09e125  xiaying  [MNN:Bugfix] Fix bug for arm64-bf16
        42ce00770  xiaying  [MNN:Bugfix] Fix bug for ARM64 - float
        a2d89fc18  雁行  [Converter:Feature] Support Binary Unary for Torch.
        7f1c0deb1  xiaying  [MNN:Bugfix] Fix bug for Raster for Int8
        8335a6f18  tianbu.xsw  [OpenCL Shared Memory] modify data_format method
        b359e031b  xiaying  [ARM82:Bugfix] Fix bug for arm82 and speed up pack / unpack c8
        24bf3fc88  雁行  [Convert:Feature] Support LayerNormFuse without gamma beta.
        3e629624b  xiaying  [MNN:Bugfix] Fix bug for float - armv7a
        2b7908ec7  tianbu.xsw  modify workItemSize
        3cee0d413  xiaying  [MNN:Bugfix] test wrong clear
        9cbbfb998  xiaying  [MNN:Bugfix] fix compile bug for c++ < 14
        2d7a44484  xiaying  [MNN:Bugfix] fix compile bug for c++ < 14
        eb7d0cb53  xiaying  [Test:Bugfix] Don't test for NC4HW4 directly
        7b40ca8d1  xiaying  [MNN:Bugfix] Fix bug for ConvolutionGroup
        2694d8a91  xiaying  [MNN:Bugfix] Fix bug for CPUGridSample
        f89af60f6  xiaying  [MNN:Bugfix] Fix compile bug for arm
        a151abcdd  xiaying  [MNN:Bugfix] Fix bug for convert for int8 / int16
        b254dbe61  雁行  [MNN:Bugfix] Bugfix for Conv onClone.
        d08150631  xiaying  [MNN:Bugfix] Fix bug for fast rcnn
        e5568a0df  xiaying  [MNN:Bugfix] Fix bug for CPURaster treat NC4HW4 fast blit
        128318933  雁行  [Raster:Bugfix] bugfix for Raster merge onResize.
        03caacbea  xiaying  [MNN:Bugfix] fix bug for CPUDeconvolution and Convolution1x1Strassen for iw != ow
        e1e3c245c  xiaying  [MNN:Bugfix] Fix bug for ConvolutionWinograd
        2524cbc6d  xiaying  [MNN:Bugfix] Fix bug for CPUSoftmax
        44ec79b8f  xiaying  [MNN:Bugfix] Fix bug for CPUConvolutionDepthwise / Scale / DeconvolutionDW
        21ae956ce  xiaying  [MNN:Bugfix] Fix bug for Multi-Batch-TiledExecutor
        09a5069c7  xiaying  [MNN:Speed] Add offset for src and dst
        6776c6784  xiaying  [MNN:Bugfix] Fix bug for trainable model
        cc83ae30b  xiaying  [MNN:Bugfix] Fix bug for trainable model
											
										 
										
											2021-07-29 11:46:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_OP_SEPERATE
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (command.op->type() == OpType_UnaryOp) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mContent->type = EnumNameUnaryOpOperation(command.op->main_as_UnaryOp()->opType());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (command.op->type() == OpType_BinaryOp) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mContent->type = EnumNameBinaryOpOperation((BinaryOpOperation)(command.op->main_as_BinaryOp()->opType()));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (command.op->type() == OpType_Reduction) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mContent->type = EnumNameReductionType(command.op->main_as_ReductionParam()->operation());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mContent->type = EnumNameOpType(command.op->type());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#else
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mContent->type = EnumNameOpType(command.op->type());
							 | 
						
					
						
							
								
									
										
											 
										 
										
											
												[MNN:Sync] Sync internal github
Commits:
        8148ae75c  弗人  bugfix
        14cb8ec7f  弗人  [Converter:Bugfix] bugfix for onnx depthwise convtranspose
        476fbcd90  雁行  [MNN:Feature] Open AVX cast and bugfix for contentCFG.
        5e26b9fd3  雁行  [Test:Feature] Add android test.
        37e147b25  雁行  [MNN:Bugfix] Bugfix for floordiv.
        144c185f5  tianbu.xsw  hangxing fix hiai
        b4fd429d6  tianbu.xsw  updateCacheFile bugfix -- update cache size
        d4ba572a8  雁行  [MNN:Bugfix] Support int8 in AVX2 and some Bugfix.
        43061f07e  xiaying  [MNN:Bugfix] Fix bug for module mode run part of model
        398cc5ab6  tianhang.yth  refactor demo
        736380600  xiaying  [Express:Bugfix] Fix memory leak for copy branch
        b8dab0a27  tianhang.yth  MNNFloat2Int8 sizeQuad=0 crash fix
        94b95bfed  ghz  [BugFix]1.Better method for fast pack valid check
        6a921f85e  xiaying  [Converter:Bugfix] Fix bug for Fuseconsttosubgraph
        5f77ae889  tianhang.yth  numThread bugfix
        a807ef879  tianhang.yth  add createSession(configs, runtimeinfo) API, add pymnn demo, pymnn logcat bugfix
        ad05409d3  xiaying  [MNN:Bugfix] Fix bug for StaticModule's sizecompute overflow, add error print for module mode
        9d81b8299  xiaying  [MNN:Bugfix] Fix bug for Unique op for output size = 1
        03b15e9af  xiaying  [Test:Feature] Add MatMulBConst Test, Fix bug for single Convert
        c944a76ee  tianhang.yth  add auto backend and getSessionInfo @tianbu
        91fa7267b  ghz  [BugFix]1.fix the error in eP check
        bf0041f77  ghz  [BugFix]1.Fix the logic error in eP check. 2.Fix the sp align error
        693871672  雁行  [CPU:Bugfix] rm adrp instruction for clang compiler bug.
        1b8f6b3d8  ghz  1.Fix the wronly use of r13 in arm32 version. 2.Fix the missing callee register save and restore process.
        feb7ecc4c  弗人  modify log of python offline quant
        040c04811  ghz  [BufFix]1.replace platform-related regs. 2.fix the same problem in arm32 version
        609f37db8  弗人  add log for python quant, python convert
        5511dd30a  ghz  [BugFix]1.Add testcases in SparseConv to check all functional code branch. 2. Fix the bug in "MNNPackC4ForMatMul_A.S" in arm64, which is caused by the missing check of eReal parameter.
        a93ff9280  tianhang.yth  add tf.Unique op support
        9729ff773  allen.lk  [Bugfix] Fix one arm32 instruction syntax that clang works but gcc DOES NOT work. use index instruction instead.
        297c1ad14  雁行  [Expr:Bugfix] bugfix for tensor content used by shape compute.
        ef8c369e3  弗人  catch exception
        07c2dd670  弗人  add dependence to setup, base64 encode url, add time log
        177e590c1  弗人  [Python:Feature] add aliyun log for python quant tool
        40a7928cf  allen.lk  [Debug:Sparse] 1.Add group parameter in torchscript converter. 2. Stop split running to avoid memory corruption when check failed in TransformGroupConvolution 3. fix Op split issue in TransformGroupConvolution
        3bdea84a1  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        c3c6fbdbd  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        bc590eee4  雁行  [Converter:Bugfix] bugfix for onnx instancenormalization convert.
        d8918593f  tianhang.yth  add auto backend and getSessionInfo @tianbu
        83a198ed7  杭行  update
        d0dd3e09b  杭行  update
        99540202e  xiaying  [Converter:Optimize] Opt the tensor convert insert
        333d8db82  allen.lk  [Debug:Sparse] Fix All platform-register r9 / x18 issue on arm32 and arm64.
        db5994672  杭行  merge
        6293de7b8  tianbu.xsw  fix pymnn updateCacheFile
        5c2e11cb1  tianbu.xsw  do updateCache in createSession
        6e7641ff4  tianbu.xsw  do not limit cacheFile for a model
        5287a65e4  tianbu.xsw  bugfix
        52ba53a91  tianbu.xsw  revert pymnn api
        60284d830  tianbu.xsw  bugfix
        6d8077490  tianbu.xsw  rename updateCacheFile api params
        3cb172710  tianhang.yth  updateCacheFile API size default value is 0
        c5b69aabf  tianbu.xsw  updateCacheFile python api fix
        5d5da7aa5  tianbu.xsw  reflector code
        5707877a4  雁行  [MNN:Speed] Speedup for softmax in x86 and arm.
        2a211825c  tianbu.xsw  reflector code for updateCacheFile
        76db3a835  tianbu.xsw  [Cache Feature]: Add updateCacheFile API for increment cache
        b06b0fd43  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        e68bfa495  雁行  [Converter:Feature] Add UUID when model convert.
        a9cb935dc  xiaying  [MNN:Speed] Support c4nhwc for more fastblit
        019f40353  xiaying  [Converter:Refractor] Reduce memory used by MNNConvert(bert from 5G ->         1G)
        d2a6d3d05  xiaying  [MNN:Bugfix] Fix bug for identity output not find
        604d0801b  xiaying  [Converter:Bugfix] Fix bug for FuseGeLu
        4bada2367  xiaying  [MNN:Refractor] SegmentMean rewrite as segment
        82070e708  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary
        e8ea4266e  xiaying  Fix bug for ShapeTensorConvert compute for dim = 1 error
        1f1cf1991  xiaying  [Tools:Bugfix] Fix system compability for fastTestOnnx
        6f422efe2  xiaying  [Tools:Bugfix] Remove color for checkDir for easy to dump
        968f7ec88  xiaying  [MNN:Speed] Support turn broadcast binary to loop
        3e7aaf46f  xiaying  [MNN:Refractor] Set Convolution1x1Strassen support variable input/output ptr
        1f65ab163  xiaying  [MNN:Bugfix] Fix bug for mini mnn can't convert model
        d65953d47  xiaying  [MNN:Bugfix] Fix bug for armv7a - android-14 + ARM82
        8b68be45c  xiaying  [MNN:Feature] Add segment
        8a8f264f5  xiaying  [Vulkan:Bugfix] Remove unuseful print
        025bb0fda  xiaying  [Converter:Bugfix] Fix bug for oneof don't support
        43900251e  tianbu.xsw  enable setCacheFile python API
        ebfb05c74  tianbu.xsw  [Metal Feature] support metallib obtain from walle transfer task
        9665c0a79  弗人  add check for path in json file
        c66fef224  xiaying  [Converter:Bugfix] Fix bug for oneof don't support
        42f192852  xiaying  [MNN:Bugfix] Fix bug for not set output / saveTensor into origin Schedule's outputs
        1b95354ff  雁行  [Feature]: Support shape compute for SetDiff1D, and null input for Prod.
        83966d043  xiaying  [Test:Feature] Add test for static module
        42d1be933  xiaying  [Converter:Bugfix] Fix bug for mnn convert and static model add more outputs for origin model
        9067531c3  xiaying  [Converter:Refractor] formatLicence
        99558bed9  xiaying  [Converter:Bugfix] Count the op for unuseful and controlflow
        4f6da0fa7  allen.lk  [Feature:GRUMultiOutput] fix multi output dimension type
        c6b219bce  xiaying  [Converter:Feature] Turn torch converter to object
        dd4e68a37  xiaying  [Converter:Feature] Support dump supported ops
        80b6a60a3  xiaying  [Converter:Info] If has output name, print output name instead of computed
        015278fc3  xiaying  [MNN:Refractor] Revert IfModule's debug info
        23ac967c4  xiaying  Don't transform for multi-input convolution/deconvolution
        b02b0d4de  xiaying  Fix bug for multi-input for conv1d
        254d8b1d4  xiaying  Fix bug for Conv1dSqueezeMove for multi input convolution 1d
        d47d0b9ca  xiaying  Fix bug for CPURaster's fuse nc4hw4
        357c5bd33  xiaying  Fix ConvBiasAdd for conv's inputs op > 1
        55b1f0c9c  xiaying  [Converter:Bugfix] Don't transform for multi-input convolution/deconvolution
        1902a30f5  xiaying  [Converter:Bugfix] Fix bug for Conv1dSqueezeMove for multi input convolution 1d
        c23fe617b  xiaying  [MNN:Bugfix] Fix bug for multi-input for conv1d
        8ff018426  xiaying  [MNN:Bugfix] Fix bug for CPURaster's fuse nc4hw4
        d4e8cd602  xiaying  [Converter:Bugfix] Fix ConvBiasAdd for conv's inputs op > 1
        846266b42  tianbu.xsw  return when program and tune both nullptr
        fd67c76a9  xiaying  [Converter:Bugfix] DepthwiseConvWeightMerge only valid for tflite
        e77a242c4  xiaying  [Converter:Feature] Support tflite's half pixel
        be054c377  tianbu.xsw  [OpenCL Bugfix] do not rewrite cache when binary program is produced
        51e65aa35  xiaying  [Converter:Feature] Support tflite for fp16 and multi-input convolution
        1ccdfdeb5  tianbu.xsw  redefine svm macro name
        31234d372  tianbu.xsw  [OpenCL SVM] add macro for only use wrapper
        d739e35da  xiaying  [MNN:Bugfix] Fix compile bug for grid op
        24ab13c79  Joker  feat(arm82): add GridSample op support in arm82 backend, AVX(by xiaying)
        7b142978e  xiaying  [AVX512:Speed] Optimize for e <= 8
        5f6febe7b  tianbu.xsw  code refactor
        998d91b57  xiaying  [Express:Speed] Merge submodule for speed
        22c89146f  tianhang.yth  fix alpha div by zero bug and arm server compile bug
        8f829a170  tianbu.xsw  [OpenCL Pad] unify conv/deconv pad computing
        4a28f603e  xiaying  [Express:Speed] Shared Const for All Submodule
        c74cf28f3  xiaying  [MNN:Refractor] Seperate Const init and schedule
        2a1eebb7a  xiaying  [Tools:Bugfix] Fix bug for modelTest.py count size
        72f04008c  xiaying  [MNN:Refractor] Delete unuseful const op
        1e735d03c  xiaying  [Converter:Bugfix] Fix bug for static module gen
        4dfadbc6e  xiaying  [MNN:Refractor] Rewrite const init mode
        1fcf0417a  xiaying  [MNN:Bugfix] Fix bug for deconvolutin multi-input for multi-batch
        41d429cfd  xiaying  [Train:Bugfix] Revert convert NCHW for mnistTrain
        f947a5f01  xiaying  [Test:Feature] Add testTrain
        dad59b6f6  tianbu.xsw  move realize code from Backend.hpp to Tensor.cpp
        cf4473ad1  xiaying  [Train:Bugfix] Support pad for GeometryPoolGrad
        91ab13734  xiaying  [MNN:Bugfix] Fix compile bug for avx512
        742e80f47  xiaying  [MNN:Refractor] Opt the logic for checknan judge
        12543b841  xiaying  [ARM82:Bugfix] Fix compile bug for ios
        3a2b0a49f  xiaying  [ARM82:Speed] Opt Pack / Unpack for armv8
        c0f1995cd  xiaying  [ARM82:Speed] Opt MNNPackC8FP16 and MNNUnpackC8FP16 by asm
        e0fc77dcf  xiaying  [MNN:Speed] Fix bug for DeconvolutionWithStride for C4HW4, open it
        584bec578  xiaying  [MNN:Bugfix] Fix bug for format set error for onnx
        d5bd4148d  xiaying  [MNN:Bugfix] Fix bug for format set error for onnx
        b00265841  xiaying  [MNN:Bugfix] Fix bug for SparseConvolutionTiledExecutor
        bb09188ac  xiaying  [Test:Bugfix] Fix bug for run into sparse auto
        426d1babd  xiaying  [MNN:Refractor] Small bugfix for Group convolution and pack
        7d0ea1c46  tianbu.xsw  [testModel Feature] support testModel.out input resize
        4169c54ce  xiaying  [MNN:Bugfix] Fix bug for checkNAN for origin
        412a82222  xiaying  [Test:Bugfix] Fix bug for CheckNAN's error of matmul
        319b1d425  xiaying  [MNN:Bugfix] Fix bug for multi-batch for ConvInt8
        050b728a6  xiaying  [Test:Bugfix] Use NCHW for ConvInt8Test
        7db3423a1  xiaying  [OpenCL:Bugfix] Fix bug for opencl::image,opencl::buffer for C4HW4
        adcec6a7f  xiaying  [Vulkan:Bugfix] Fix bug for invalid tensor size limit
        d2a7cf4e9  xiaying  [Vulkan:Bugfix] Fix bug for onCopyBuffer of nc4hw4
        557bebdd3  xiaying  [MNN:Bugfix] Fix bug for BF16-ARM32
        bbe186649  tianbu.xsw  [Update AUTO mode]: fix MNN_FORWARD_AUTO choose priority
        6deb23439  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size
        b137590e4  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size
        7003558ea  xiaying  [Converter:Bugfix] Fix bug for onnx pad for serveral case
        b5f8cae5a  xiaying  [Converter:Bugfix] Fix bug for onnx pad for serveral case
        29b09e125  xiaying  [MNN:Bugfix] Fix bug for arm64-bf16
        42ce00770  xiaying  [MNN:Bugfix] Fix bug for ARM64 - float
        a2d89fc18  雁行  [Converter:Feature] Support Binary Unary for Torch.
        7f1c0deb1  xiaying  [MNN:Bugfix] Fix bug for Raster for Int8
        8335a6f18  tianbu.xsw  [OpenCL Shared Memory] modify data_format method
        b359e031b  xiaying  [ARM82:Bugfix] Fix bug for arm82 and speed up pack / unpack c8
        24bf3fc88  雁行  [Convert:Feature] Support LayerNormFuse without gamma beta.
        3e629624b  xiaying  [MNN:Bugfix] Fix bug for float - armv7a
        2b7908ec7  tianbu.xsw  modify workItemSize
        3cee0d413  xiaying  [MNN:Bugfix] test wrong clear
        9cbbfb998  xiaying  [MNN:Bugfix] fix compile bug for c++ < 14
        2d7a44484  xiaying  [MNN:Bugfix] fix compile bug for c++ < 14
        eb7d0cb53  xiaying  [Test:Bugfix] Don't test for NC4HW4 directly
        7b40ca8d1  xiaying  [MNN:Bugfix] Fix bug for ConvolutionGroup
        2694d8a91  xiaying  [MNN:Bugfix] Fix bug for CPUGridSample
        f89af60f6  xiaying  [MNN:Bugfix] Fix compile bug for arm
        a151abcdd  xiaying  [MNN:Bugfix] Fix bug for convert for int8 / int16
        b254dbe61  雁行  [MNN:Bugfix] Bugfix for Conv onClone.
        d08150631  xiaying  [MNN:Bugfix] Fix bug for fast rcnn
        e5568a0df  xiaying  [MNN:Bugfix] Fix bug for CPURaster treat NC4HW4 fast blit
        128318933  雁行  [Raster:Bugfix] bugfix for Raster merge onResize.
        03caacbea  xiaying  [MNN:Bugfix] fix bug for CPUDeconvolution and Convolution1x1Strassen for iw != ow
        e1e3c245c  xiaying  [MNN:Bugfix] Fix bug for ConvolutionWinograd
        2524cbc6d  xiaying  [MNN:Bugfix] Fix bug for CPUSoftmax
        44ec79b8f  xiaying  [MNN:Bugfix] Fix bug for CPUConvolutionDepthwise / Scale / DeconvolutionDW
        21ae956ce  xiaying  [MNN:Bugfix] Fix bug for Multi-Batch-TiledExecutor
        09a5069c7  xiaying  [MNN:Speed] Add offset for src and dst
        6776c6784  xiaying  [MNN:Bugfix] Fix bug for trainable model
        cc83ae30b  xiaying  [MNN:Bugfix] Fix bug for trainable model
											
										 
										
											2021-07-29 11:46:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifndef MNN_BUILD_MINI
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mContent->flops = SizeComputer::computeFlops(command.op, command.inputs, command.outputs);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-06-15 15:39:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Pipeline::Pipeline(const std::string& externalFile, Schedule::PipelineInfo&& info, bool allocInput, bool outputStatic, const TuningAttr& tune, const Runtime* rt, const Runtime* cpuRt, int geometryMask)
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifndef MNN_BUILD_MINI
							 | 
						
					
						
							
								
									
										
										
										
											2024-06-15 15:39:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    : mContext(geometryMask, info.first.cache.second, info.first.cache.first->type(), info.first.info.user ? info.first.info.user->precision :  BackendConfig::Precision_Normal), mUseGeometry(rt->onGetCompilerType()) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mExternalFile = externalFile;
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-18 19:11:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    rt->onCheckInfo(info.first.info);
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mRuntime = rt;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mCpuRuntime = cpuRt;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mTuneAttr = tune;
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mAllocInput    = allocInput;
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mOutputStatic  = outputStatic;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mInfo          = std::move(info);
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mIsQuantModel = false;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto& iter : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (auto t : iter.outputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (TensorUtils::getDescribe(t)->quantAttr.get() != nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                mIsQuantModel = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
											 
										 
										
											
												[MNN:Sync] Sync internal github
Commits:
        8148ae75c  弗人  bugfix
        14cb8ec7f  弗人  [Converter:Bugfix] bugfix for onnx depthwise convtranspose
        476fbcd90  雁行  [MNN:Feature] Open AVX cast and bugfix for contentCFG.
        5e26b9fd3  雁行  [Test:Feature] Add android test.
        37e147b25  雁行  [MNN:Bugfix] Bugfix for floordiv.
        144c185f5  tianbu.xsw  hangxing fix hiai
        b4fd429d6  tianbu.xsw  updateCacheFile bugfix -- update cache size
        d4ba572a8  雁行  [MNN:Bugfix] Support int8 in AVX2 and some Bugfix.
        43061f07e  xiaying  [MNN:Bugfix] Fix bug for module mode run part of model
        398cc5ab6  tianhang.yth  refactor demo
        736380600  xiaying  [Express:Bugfix] Fix memory leak for copy branch
        b8dab0a27  tianhang.yth  MNNFloat2Int8 sizeQuad=0 crash fix
        94b95bfed  ghz  [BugFix]1.Better method for fast pack valid check
        6a921f85e  xiaying  [Converter:Bugfix] Fix bug for Fuseconsttosubgraph
        5f77ae889  tianhang.yth  numThread bugfix
        a807ef879  tianhang.yth  add createSession(configs, runtimeinfo) API, add pymnn demo, pymnn logcat bugfix
        ad05409d3  xiaying  [MNN:Bugfix] Fix bug for StaticModule's sizecompute overflow, add error print for module mode
        9d81b8299  xiaying  [MNN:Bugfix] Fix bug for Unique op for output size = 1
        03b15e9af  xiaying  [Test:Feature] Add MatMulBConst Test, Fix bug for single Convert
        c944a76ee  tianhang.yth  add auto backend and getSessionInfo @tianbu
        91fa7267b  ghz  [BugFix]1.fix the error in eP check
        bf0041f77  ghz  [BugFix]1.Fix the logic error in eP check. 2.Fix the sp align error
        693871672  雁行  [CPU:Bugfix] rm adrp instruction for clang compiler bug.
        1b8f6b3d8  ghz  1.Fix the wronly use of r13 in arm32 version. 2.Fix the missing callee register save and restore process.
        feb7ecc4c  弗人  modify log of python offline quant
        040c04811  ghz  [BufFix]1.replace platform-related regs. 2.fix the same problem in arm32 version
        609f37db8  弗人  add log for python quant, python convert
        5511dd30a  ghz  [BugFix]1.Add testcases in SparseConv to check all functional code branch. 2. Fix the bug in "MNNPackC4ForMatMul_A.S" in arm64, which is caused by the missing check of eReal parameter.
        a93ff9280  tianhang.yth  add tf.Unique op support
        9729ff773  allen.lk  [Bugfix] Fix one arm32 instruction syntax that clang works but gcc DOES NOT work. use index instruction instead.
        297c1ad14  雁行  [Expr:Bugfix] bugfix for tensor content used by shape compute.
        ef8c369e3  弗人  catch exception
        07c2dd670  弗人  add dependence to setup, base64 encode url, add time log
        177e590c1  弗人  [Python:Feature] add aliyun log for python quant tool
        40a7928cf  allen.lk  [Debug:Sparse] 1.Add group parameter in torchscript converter. 2. Stop split running to avoid memory corruption when check failed in TransformGroupConvolution 3. fix Op split issue in TransformGroupConvolution
        3bdea84a1  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        c3c6fbdbd  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        bc590eee4  雁行  [Converter:Bugfix] bugfix for onnx instancenormalization convert.
        d8918593f  tianhang.yth  add auto backend and getSessionInfo @tianbu
        83a198ed7  杭行  update
        d0dd3e09b  杭行  update
        99540202e  xiaying  [Converter:Optimize] Opt the tensor convert insert
        333d8db82  allen.lk  [Debug:Sparse] Fix All platform-register r9 / x18 issue on arm32 and arm64.
        db5994672  杭行  merge
        6293de7b8  tianbu.xsw  fix pymnn updateCacheFile
        5c2e11cb1  tianbu.xsw  do updateCache in createSession
        6e7641ff4  tianbu.xsw  do not limit cacheFile for a model
        5287a65e4  tianbu.xsw  bugfix
        52ba53a91  tianbu.xsw  revert pymnn api
        60284d830  tianbu.xsw  bugfix
        6d8077490  tianbu.xsw  rename updateCacheFile api params
        3cb172710  tianhang.yth  updateCacheFile API size default value is 0
        c5b69aabf  tianbu.xsw  updateCacheFile python api fix
        5d5da7aa5  tianbu.xsw  reflector code
        5707877a4  雁行  [MNN:Speed] Speedup for softmax in x86 and arm.
        2a211825c  tianbu.xsw  reflector code for updateCacheFile
        76db3a835  tianbu.xsw  [Cache Feature]: Add updateCacheFile API for increment cache
        b06b0fd43  allen.lk  [Debug:Sparse] Fix and warning one kind of segmentfault cause by memory corruption when resize ConvolutionWinograd.  Avoid to use some registers as arm restriction.
        e68bfa495  雁行  [Converter:Feature] Add UUID when model convert.
        a9cb935dc  xiaying  [MNN:Speed] Support c4nhwc for more fastblit
        019f40353  xiaying  [Converter:Refractor] Reduce memory used by MNNConvert(bert from 5G ->         1G)
        d2a6d3d05  xiaying  [MNN:Bugfix] Fix bug for identity output not find
        604d0801b  xiaying  [Converter:Bugfix] Fix bug for FuseGeLu
        4bada2367  xiaying  [MNN:Refractor] SegmentMean rewrite as segment
        82070e708  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary
        e8ea4266e  xiaying  Fix bug for ShapeTensorConvert compute for dim = 1 error
        1f1cf1991  xiaying  [Tools:Bugfix] Fix system compability for fastTestOnnx
        6f422efe2  xiaying  [Tools:Bugfix] Remove color for checkDir for easy to dump
        968f7ec88  xiaying  [MNN:Speed] Support turn broadcast binary to loop
        3e7aaf46f  xiaying  [MNN:Refractor] Set Convolution1x1Strassen support variable input/output ptr
        1f65ab163  xiaying  [MNN:Bugfix] Fix bug for mini mnn can't convert model
        d65953d47  xiaying  [MNN:Bugfix] Fix bug for armv7a - android-14 + ARM82
        8b68be45c  xiaying  [MNN:Feature] Add segment
        8a8f264f5  xiaying  [Vulkan:Bugfix] Remove unuseful print
        025bb0fda  xiaying  [Converter:Bugfix] Fix bug for oneof don't support
        43900251e  tianbu.xsw  enable setCacheFile python API
        ebfb05c74  tianbu.xsw  [Metal Feature] support metallib obtain from walle transfer task
        9665c0a79  弗人  add check for path in json file
        c66fef224  xiaying  [Converter:Bugfix] Fix bug for oneof don't support
        42f192852  xiaying  [MNN:Bugfix] Fix bug for not set output / saveTensor into origin Schedule's outputs
        1b95354ff  雁行  [Feature]: Support shape compute for SetDiff1D, and null input for Prod.
        83966d043  xiaying  [Test:Feature] Add test for static module
        42d1be933  xiaying  [Converter:Bugfix] Fix bug for mnn convert and static model add more outputs for origin model
        9067531c3  xiaying  [Converter:Refractor] formatLicence
        99558bed9  xiaying  [Converter:Bugfix] Count the op for unuseful and controlflow
        4f6da0fa7  allen.lk  [Feature:GRUMultiOutput] fix multi output dimension type
        c6b219bce  xiaying  [Converter:Feature] Turn torch converter to object
        dd4e68a37  xiaying  [Converter:Feature] Support dump supported ops
        80b6a60a3  xiaying  [Converter:Info] If has output name, print output name instead of computed
        015278fc3  xiaying  [MNN:Refractor] Revert IfModule's debug info
        23ac967c4  xiaying  Don't transform for multi-input convolution/deconvolution
        b02b0d4de  xiaying  Fix bug for multi-input for conv1d
        254d8b1d4  xiaying  Fix bug for Conv1dSqueezeMove for multi input convolution 1d
        d47d0b9ca  xiaying  Fix bug for CPURaster's fuse nc4hw4
        357c5bd33  xiaying  Fix ConvBiasAdd for conv's inputs op > 1
        55b1f0c9c  xiaying  [Converter:Bugfix] Don't transform for multi-input convolution/deconvolution
        1902a30f5  xiaying  [Converter:Bugfix] Fix bug for Conv1dSqueezeMove for multi input convolution 1d
        c23fe617b  xiaying  [MNN:Bugfix] Fix bug for multi-input for conv1d
        8ff018426  xiaying  [MNN:Bugfix] Fix bug for CPURaster's fuse nc4hw4
        d4e8cd602  xiaying  [Converter:Bugfix] Fix ConvBiasAdd for conv's inputs op > 1
        846266b42  tianbu.xsw  return when program and tune both nullptr
        fd67c76a9  xiaying  [Converter:Bugfix] DepthwiseConvWeightMerge only valid for tflite
        e77a242c4  xiaying  [Converter:Feature] Support tflite's half pixel
        be054c377  tianbu.xsw  [OpenCL Bugfix] do not rewrite cache when binary program is produced
        51e65aa35  xiaying  [Converter:Feature] Support tflite for fp16 and multi-input convolution
        1ccdfdeb5  tianbu.xsw  redefine svm macro name
        31234d372  tianbu.xsw  [OpenCL SVM] add macro for only use wrapper
        d739e35da  xiaying  [MNN:Bugfix] Fix compile bug for grid op
        24ab13c79  Joker  feat(arm82): add GridSample op support in arm82 backend, AVX(by xiaying)
        7b142978e  xiaying  [AVX512:Speed] Optimize for e <= 8
        5f6febe7b  tianbu.xsw  code refactor
        998d91b57  xiaying  [Express:Speed] Merge submodule for speed
        22c89146f  tianhang.yth  fix alpha div by zero bug and arm server compile bug
        8f829a170  tianbu.xsw  [OpenCL Pad] unify conv/deconv pad computing
        4a28f603e  xiaying  [Express:Speed] Shared Const for All Submodule
        c74cf28f3  xiaying  [MNN:Refractor] Seperate Const init and schedule
        2a1eebb7a  xiaying  [Tools:Bugfix] Fix bug for modelTest.py count size
        72f04008c  xiaying  [MNN:Refractor] Delete unuseful const op
        1e735d03c  xiaying  [Converter:Bugfix] Fix bug for static module gen
        4dfadbc6e  xiaying  [MNN:Refractor] Rewrite const init mode
        1fcf0417a  xiaying  [MNN:Bugfix] Fix bug for deconvolutin multi-input for multi-batch
        41d429cfd  xiaying  [Train:Bugfix] Revert convert NCHW for mnistTrain
        f947a5f01  xiaying  [Test:Feature] Add testTrain
        dad59b6f6  tianbu.xsw  move realize code from Backend.hpp to Tensor.cpp
        cf4473ad1  xiaying  [Train:Bugfix] Support pad for GeometryPoolGrad
        91ab13734  xiaying  [MNN:Bugfix] Fix compile bug for avx512
        742e80f47  xiaying  [MNN:Refractor] Opt the logic for checknan judge
        12543b841  xiaying  [ARM82:Bugfix] Fix compile bug for ios
        3a2b0a49f  xiaying  [ARM82:Speed] Opt Pack / Unpack for armv8
        c0f1995cd  xiaying  [ARM82:Speed] Opt MNNPackC8FP16 and MNNUnpackC8FP16 by asm
        e0fc77dcf  xiaying  [MNN:Speed] Fix bug for DeconvolutionWithStride for C4HW4, open it
        584bec578  xiaying  [MNN:Bugfix] Fix bug for format set error for onnx
        d5bd4148d  xiaying  [MNN:Bugfix] Fix bug for format set error for onnx
        b00265841  xiaying  [MNN:Bugfix] Fix bug for SparseConvolutionTiledExecutor
        bb09188ac  xiaying  [Test:Bugfix] Fix bug for run into sparse auto
        426d1babd  xiaying  [MNN:Refractor] Small bugfix for Group convolution and pack
        7d0ea1c46  tianbu.xsw  [testModel Feature] support testModel.out input resize
        4169c54ce  xiaying  [MNN:Bugfix] Fix bug for checkNAN for origin
        412a82222  xiaying  [Test:Bugfix] Fix bug for CheckNAN's error of matmul
        319b1d425  xiaying  [MNN:Bugfix] Fix bug for multi-batch for ConvInt8
        050b728a6  xiaying  [Test:Bugfix] Use NCHW for ConvInt8Test
        7db3423a1  xiaying  [OpenCL:Bugfix] Fix bug for opencl::image,opencl::buffer for C4HW4
        adcec6a7f  xiaying  [Vulkan:Bugfix] Fix bug for invalid tensor size limit
        d2a7cf4e9  xiaying  [Vulkan:Bugfix] Fix bug for onCopyBuffer of nc4hw4
        557bebdd3  xiaying  [MNN:Bugfix] Fix bug for BF16-ARM32
        bbe186649  tianbu.xsw  [Update AUTO mode]: fix MNN_FORWARD_AUTO choose priority
        6deb23439  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size
        b137590e4  xiaying  [MNN:Bugfix] Fix bug for GeometryBinary don't care about NC4HW4 same size
        7003558ea  xiaying  [Converter:Bugfix] Fix bug for onnx pad for serveral case
        b5f8cae5a  xiaying  [Converter:Bugfix] Fix bug for onnx pad for serveral case
        29b09e125  xiaying  [MNN:Bugfix] Fix bug for arm64-bf16
        42ce00770  xiaying  [MNN:Bugfix] Fix bug for ARM64 - float
        a2d89fc18  雁行  [Converter:Feature] Support Binary Unary for Torch.
        7f1c0deb1  xiaying  [MNN:Bugfix] Fix bug for Raster for Int8
        8335a6f18  tianbu.xsw  [OpenCL Shared Memory] modify data_format method
        b359e031b  xiaying  [ARM82:Bugfix] Fix bug for arm82 and speed up pack / unpack c8
        24bf3fc88  雁行  [Convert:Feature] Support LayerNormFuse without gamma beta.
        3e629624b  xiaying  [MNN:Bugfix] Fix bug for float - armv7a
        2b7908ec7  tianbu.xsw  modify workItemSize
        3cee0d413  xiaying  [MNN:Bugfix] test wrong clear
        9cbbfb998  xiaying  [MNN:Bugfix] fix compile bug for c++ < 14
        2d7a44484  xiaying  [MNN:Bugfix] fix compile bug for c++ < 14
        eb7d0cb53  xiaying  [Test:Bugfix] Don't test for NC4HW4 directly
        7b40ca8d1  xiaying  [MNN:Bugfix] Fix bug for ConvolutionGroup
        2694d8a91  xiaying  [MNN:Bugfix] Fix bug for CPUGridSample
        f89af60f6  xiaying  [MNN:Bugfix] Fix compile bug for arm
        a151abcdd  xiaying  [MNN:Bugfix] Fix bug for convert for int8 / int16
        b254dbe61  雁行  [MNN:Bugfix] Bugfix for Conv onClone.
        d08150631  xiaying  [MNN:Bugfix] Fix bug for fast rcnn
        e5568a0df  xiaying  [MNN:Bugfix] Fix bug for CPURaster treat NC4HW4 fast blit
        128318933  雁行  [Raster:Bugfix] bugfix for Raster merge onResize.
        03caacbea  xiaying  [MNN:Bugfix] fix bug for CPUDeconvolution and Convolution1x1Strassen for iw != ow
        e1e3c245c  xiaying  [MNN:Bugfix] Fix bug for ConvolutionWinograd
        2524cbc6d  xiaying  [MNN:Bugfix] Fix bug for CPUSoftmax
        44ec79b8f  xiaying  [MNN:Bugfix] Fix bug for CPUConvolutionDepthwise / Scale / DeconvolutionDW
        21ae956ce  xiaying  [MNN:Bugfix] Fix bug for Multi-Batch-TiledExecutor
        09a5069c7  xiaying  [MNN:Speed] Add offset for src and dst
        6776c6784  xiaying  [MNN:Bugfix] Fix bug for trainable model
        cc83ae30b  xiaying  [MNN:Bugfix] Fix bug for trainable model
											
										 
										
											2021-07-29 11:46:59 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (auto t : iter.inputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (TensorUtils::getDescribe(t)->quantAttr.get() != nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                mIsQuantModel = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (mIsQuantModel) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-06 16:29:37 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-18 09:36:26 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ErrorCode Pipeline::encode(bool supportDebug, bool permitCodegen) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Static Model just copy info to command buffer
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (!mInfo.first.needComputeGeometry) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (int i=0; i<mInfo.second.size(); ++i) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& info = mInfo.second[i];
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            std::shared_ptr<Command> cmd(new Command);
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            cmd->op      = info.op;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (cmd->op->type() == OpType_Raster) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                // Compability for Origin Static Model
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                cmd->outputs  = info.outputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (TensorUtils::getDescribe(info.outputs[0])->regions.empty() && info.inputs.size() > 0 && TensorUtils::getDescribe(info.inputs[0])->regions.size() > 0) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    TensorUtils::getDescribe(info.outputs[0])->regions = std::move(TensorUtils::getDescribe(info.inputs[0])->regions);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    TensorUtils::setRasterInputs(cmd.get());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    cmd->inputs  = info.inputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                cmd->inputs  = info.inputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                cmd->outputs = info.outputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            info.executeBuffer.command = {cmd};
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#ifndef MNN_BUILD_MINI
							 | 
						
					
						
							
								
									
										
										
										
											2024-09-12 12:57:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        mBackend->onClearBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mBackupBackend->onClearBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        mContext.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-24 15:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        mContext.mNeedRelease = mGeometryNeedRelease;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        FileLoader l(mExternalFile.c_str());
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        /** Size Compute and compute Const Begin */
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto res = GeometryComputerUtils::shapeComputeAndGeometryTransform(mCpuRuntime, &l, mInfo.second, mContext, mInfo.first.cache.second, mUseGeometry, false, permitCodegen);
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (res != NO_ERROR) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return res;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Propagate Scale and insert new command
							 | 
						
					
						
							
								
									
										
										
										
											2023-10-18 10:31:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (mIsQuantModel && (mBackend->type() == MNN_FORWARD_CPU || mBackend->type() == MNN_FORWARD_CPU_EXTENSION || mBackend->type() == MNN_FORWARD_CUDA || mBackend->type() == MNN_FORWARD_NN || mBackend->type() == MNN_FORWARD_OPENCL)) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // get propagate map
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        using PropagateMap = std::map<const MNN::Tensor*, std::set<const MNN::Tensor*>>;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        PropagateMap forwardMap, backwardMap;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto insertPropagateMap = [](PropagateMap& propagateMap, const Tensor* s, const Tensor* t) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (propagateMap.find(s) == propagateMap.end()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                propagateMap[s] = std::set<const Tensor*>({t});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                propagateMap[s].insert(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        };
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-15 10:30:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        std::set<OpType> propagateOpTypes = { OpType_Raster, OpType_ReLU, OpType_ReLU6, OpType_Pooling,
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                                              OpType_Interp, OpType_CropAndResize, OpType_ROIPooling, OpType_Gather,
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                                              OpType_GatherV2, OpType_GatherV2, OpType_ScatterNd};
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (const auto& cmdP : buffer.command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto& cmd = *cmdP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                const auto type = cmd.op->type();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                const auto output = cmd.outputs[0];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (propagateOpTypes.find(type) != propagateOpTypes.end()) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    for (auto t : cmd.inputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        insertPropagateMap(forwardMap, t, output);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        insertPropagateMap(backwardMap, output, t);
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto getStart = [&forwardMap, &backwardMap](bool forward) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& propagateMap = forward ? forwardMap : backwardMap;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& antiMap = forward ? backwardMap : forwardMap;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // delete N->1 Map of Op
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (const auto& iter : antiMap) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (iter.second.size() > 1) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    for (auto t : iter.second) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        auto res = propagateMap.find(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        if (res != propagateMap.end()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            propagateMap.erase(res);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            std::set<const Tensor*> root, leaf, start;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (const auto& iter : propagateMap) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                root.insert(iter.first);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto t : iter.second) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    leaf.insert(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            std::set_difference(root.begin(), root.end(), leaf.begin(), leaf.end(), std::inserter(start, start.begin()));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return start;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto forwardStart = getStart(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto backwardStart = getStart(false);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // propagate scale
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto propagateScale = [](PropagateMap& propagateMap, std::set<const Tensor*>& start) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            std::function<bool(const Tensor*)> scalePropagate = [&propagateMap, &scalePropagate](const Tensor* t) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (TensorUtils::getDescribe(t)->quantAttr.get() == nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (propagateMap.find(t) == propagateMap.end()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                bool change = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto x : propagateMap[t]) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (TensorUtils::getDescribe(x)->quantAttr != TensorUtils::getDescribe(t)->quantAttr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        TensorUtils::getDescribe(x)->quantAttr = TensorUtils::getDescribe(t)->quantAttr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        change = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    change |= scalePropagate(x);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return change;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            bool change = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto t : start) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                change |= scalePropagate(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return change;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (int i = 0; i < 3 && (propagateScale(forwardMap, forwardStart) || propagateScale(backwardMap, backwardStart)); i++);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // Insert cast
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        std::map<const Tensor*, Tensor*> cachedCastTensor;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (auto& info : mInfo.second) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto bufferCommand = std::move(info.executeBuffer.command);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            bool hasConvert = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto cmdP : bufferCommand) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto& cmd = *cmdP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto& outputs = cmd.outputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto& inputs = cmd.inputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto opType = cmd.op->type();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                // Check if need use quant op
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                DataType runType = DataType_DT_FLOAT;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                bool useQuant = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (outputs.size() == 1) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    // Quant: output and all input has quantAttr and op support
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (TensorUtils::getDescribe(outputs[0])->quantAttr != nullptr) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        useQuant = _supportQuant(cmd.op, inputs, outputs, mBackend->type());
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (useQuant) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        for (auto t : inputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            if (TensorUtils::getDescribe(t)->quantAttr == nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                useQuant = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (useQuant) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    runType = DataType_DT_INT8;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto o : outputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    auto quan = TensorUtils::getDescribe(o)->quantAttr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (nullptr != quan) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        TensorUtils::getDescribe(o)->type = runType;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto makeCommand = [&cachedCastTensor, &info](CommandBuffer& cmdBuffer, Tensor* input, DataType runType) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (cachedCastTensor.find(input) != cachedCastTensor.end()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        return cachedCastTensor[input];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    std::shared_ptr<Tensor> wrapTensor(new Tensor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    TensorUtils::copyShape(input, wrapTensor.get(), true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    TensorUtils::setLinearLayout(wrapTensor.get());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    auto des = TensorUtils::getDescribe(wrapTensor.get());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    auto originDes = TensorUtils::getDescribe(input);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (originDes->quantAttr != nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        des->quantAttr.reset(new QuantAttr);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        *des->quantAttr = *originDes->quantAttr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        des->type = runType;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    cmdBuffer.extras.emplace_back(wrapTensor);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    std::shared_ptr<Command> command(new Command);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    command->inputs = {input};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    command->outputs = {wrapTensor.get()};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    info.cacheBuffer.hasWrap = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    flatbuffers::FlatBufferBuilder builder;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    OpBuilder opB(builder);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (runType == DataType_DT_INT8) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        opB.add_type(OpType_FloatToInt8);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        opB.add_type(OpType_Int8ToFloat);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    builder.Finish(opB.Finish());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    command->buffer.reset(new BufferStorage);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    command->buffer->storage = builder.ReleaseRaw(command->buffer->allocated_size, command->buffer->offset);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    command->op = flatbuffers::GetRoot<Op>(command->buffer->buffer());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    info.executeBuffer.command.emplace_back(std::move(command));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    return wrapTensor.get();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                // judge is it need CastWrap
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (OpType_Raster == opType) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    for (int v=0; v<cmd.inputs.size(); ++v) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        auto input = cmd.inputs[v];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        bool needCast = CPUBackend::getDataType(input) != runType;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        if (needCast) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            cmd.inputs[v] = makeCommand(info.executeBuffer, input, runType);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    for (int i = 0; i < cmd.inputs.size(); i++) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-12-27 17:26:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        if (OpCommonUtils::opNeedContent(cmd.op, i) && inputs[i]->getType() != halide_type_of<int>()) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            bool needCast = CPUBackend::getDataType(inputs[i]) != runType;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            if (needCast) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                cmd.inputs[i] = makeCommand(info.executeBuffer, inputs[i], runType);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                info.executeBuffer.command.emplace_back(cmdP);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /** Prepare DebugInfo*/
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (supportDebug) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-11 17:17:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        mFlops = 0.0f;
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int totalIndex = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            int index = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto& cmdP : buffer.command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto& cmd = *cmdP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                cmd.info.reset(new UnitInfo);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                static_cast<UnitInfo*>(cmd.info.get())->setUp(cmd, index++, info.op, totalIndex++);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                mFlops += cmd.info->flops();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return NO_ERROR;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void Pipeline::_pushTuningTask(std::vector<Schedule::OpCacheInfo>&& initInfos) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Dup Tensors for initInfos;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    std::map<Tensor*, std::shared_ptr<Tensor>> holdTensors;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : initInfos) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (int v=0; v<buffer.command.size(); ++v) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto iterP = buffer.command[v];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iter = *iterP;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            buffer.command[v].reset(new Command);
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            iterP = buffer.command[v];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            iterP->inputs = iter.inputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            iterP->outputs = iter.outputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            iterP->op = iter.op;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            iterP->buffer = iter.buffer;
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-30 14:40:51 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifndef MNN_BUILD_MINI
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (iter.op->type() == OpType_Raster) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                iterP->buffer = mContext.mRasterOp;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-30 14:40:51 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto copyTensor = [&](std::vector<Tensor*>& tensors) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (int v=0; v<tensors.size(); ++v) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    auto t = tensors[v];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    auto findIter = holdTensors.find(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (findIter != holdTensors.end()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        tensors[v] = findIter->second.get();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    std::shared_ptr<Tensor> newTensor(new Tensor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    newTensor->buffer().type = t->getType();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    TensorUtils::copyShape(t, newTensor.get(), true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    TensorUtils::getDescribe(newTensor.get())->regions = TensorUtils::getDescribe(t)->regions;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    tensors[v] = newTensor.get();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    holdTensors.insert(std::make_pair(t, newTensor));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    holdTensors.insert(std::make_pair(newTensor.get(), newTensor));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            copyTensor(iterP->inputs);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            copyTensor(iterP->outputs);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Make async task for tuning
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-11 15:08:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const_cast<Runtime*>(mRuntime)->mCancelled = false;
							 | 
						
					
						
							
								
									
										
										
										
											2024-03-28 21:19:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto future = std::async(std::launch::async, [&, this](std::vector<Schedule::OpCacheInfo>&& infos, std::map<Tensor*, std::shared_ptr<Tensor>>&& tensors, std::shared_ptr<Backend> backend, const std::atomic_bool& cancelled) -> int {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        FileLoader loader(mExternalFile.c_str());
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-11 15:08:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        backend->onClearBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        backend->onResizeBegin();
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        std::vector<std::shared_ptr<BufferStorage>> tmpStorage;
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (auto& info : infos) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto& iterP : buffer.command) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-11 15:08:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if(cancelled) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    return -1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                // FIXME: Remove onMaskOpReady in future
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                const_cast<Runtime*>(mRuntime)->onMaskOpReady(iter.inputs, iter.outputs, iter.op);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                std::shared_ptr<BufferStorage> tmp;
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                // If create op failed, we can also mask the op is ready for runtime
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                auto exePtr = OpCommonUtils::createExecutionWithExternal(backend.get(), iter.inputs, iter.outputs, iter.op, &loader, tmp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                std::shared_ptr<Execution> exe(exePtr);
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (nullptr == exe) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (nullptr != tmp) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    tmpStorage.emplace_back(tmp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                std::vector<Tensor*> forRelease;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                std::shared_ptr<void> _defer(nullptr, [&forRelease](void*) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    for (auto t : forRelease) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        TensorUtils::getDescribeOrigin(t)->mem = nullptr;
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                // Alloc inputs and outputs
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto t : iter.inputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    auto des = TensorUtils::getDescribe(t);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    bool allocRes = backend->onAcquireBuffer(t, Backend::DYNAMIC);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (!allocRes) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        return -1;
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    forRelease.emplace_back(t);
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto t : iter.outputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    bool allocRes = backend->onAcquireBuffer(t, Backend::DYNAMIC);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (!allocRes) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        return -1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    forRelease.emplace_back(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto code = exe->onResize(iter.inputs, iter.outputs);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (NO_ERROR != code) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    return -1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        backend->onResizeEnd();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return 0;
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-11 15:08:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }, std::move(initInfos), std::move(holdTensors), mBackend, std::ref(const_cast<Runtime*>(mRuntime)->mCancelled));
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const_cast<Runtime*>(mRuntime)->setAsyncWork(std::move(future));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static ErrorCode _createExecutions(Schedule::PipelineInfo& mInfo, const std::string& externalFile, std::vector<std::shared_ptr<BufferStorage>>& extraStorage) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    FileLoader loader(externalFile.c_str());
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!info.computeCache.needComputeShape) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // MNN_PRINT("before resize, mInfo.second size:%lu, command size:%lu,op type:%s, op name:%s\n", mInfo.second.size(), buffer.command.size(), EnumNameOpType(info.op->type()), info.op->name()->c_str());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (auto& iterP : buffer.command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // Create exe
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // Find Cache
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            bool cached    = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (nullptr == iter.execution) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                /** Cache origin execution for fast resize*/
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto exeIter = info.executionCache.find(iter.op);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (exeIter != info.executionCache.end()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    iter.execution = exeIter->second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    cached         = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            std::shared_ptr<BufferStorage> tmpStorage;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (nullptr == iter.execution) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                iter.execution.reset(OpCommonUtils::createExecutionWithExternal(mBackend.get(), iter.inputs, iter.outputs, iter.op, &loader, tmpStorage));
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (nullptr == iter.execution) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                // Try Backup
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                iter.execution.reset(OpCommonUtils::createExecutionWithExternal(mBackupBackend.get(), iter.inputs, iter.outputs, iter.op, &loader, tmpStorage));
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (nullptr == iter.execution) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-08-21 14:51:54 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    if (mInfo.first.reportError) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        MNN_ERROR("Create execution error : %d\n", iter.op->type());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    return NOT_SUPPORT;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (nullptr != tmpStorage.get()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                extraStorage.emplace_back(tmpStorage);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            // invalid means memory alloc failed
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (!iter.execution->valid()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                iter.execution = nullptr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                iter.execution = nullptr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return OUT_OF_MEMORY;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if ((!cached) && iter.buffer == nullptr && (iter.op->type() != OpType_Raster) && (iter.op->type() != OpType_BinaryOp)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                info.executionCache.insert(std::make_pair(iter.op, iter.execution));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return NO_ERROR;
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static void _SetTensorBackend(Schedule::PipelineInfo& mInfo, bool ownInputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Clear Valid Tensor's Backend
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (int infoIndex=0; infoIndex < mInfo.second.size(); ++infoIndex) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto& info = mInfo.second[infoIndex];
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // MNN_PRINT("before resize, mInfo.second size:%lu, command size:%lu,op type:%s, op name:%s\n", mInfo.second.size(), buffer.command.size(), EnumNameOpType(info.op->type()), info.op->name()->c_str());
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (int iterIndex=0; iterIndex<buffer.command.size(); ++iterIndex) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iterP = buffer.command[iterIndex];
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (iter.op->type() == OpType_Copy) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-30 10:02:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto curBackend = iter.execution->backend();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (ownInputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto t : iter.inputs) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    auto des = TensorUtils::getDescribeOrigin(t);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    if (nullptr == des->mem.get()) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        des->setBackend(nullptr);
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-30 10:02:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            for (auto t : iter.outputs) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                auto des = TensorUtils::getDescribeOrigin(t);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (nullptr == des->mem.get()) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    des->setBackend(nullptr);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-30 10:02:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Set Tensor's Backend
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // MNN_PRINT("before resize, mInfo.second size:%lu, command size:%lu,op type:%s, op name:%s\n", mInfo.second.size(), buffer.command.size(), EnumNameOpType(info.op->type()), info.op->name()->c_str());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (auto& iterP : buffer.command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (iter.op->type() == OpType_Copy) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto curBackend = iter.execution->backend();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (ownInputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto t : iter.inputs) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    auto des = TensorUtils::getDescribeOrigin(t);
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    if (nullptr == des->mem.get() && nullptr == des->getBackend()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        des->setBackend(curBackend);
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-30 10:02:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            for (auto t : iter.outputs) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                auto des = TensorUtils::getDescribeOrigin(t);
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (nullptr == des->mem.get() && nullptr == des->getBackend()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    des->setBackend(curBackend);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-30 10:02:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static void _makeCopyOp(std::shared_ptr<BufferStorage>& copyOp) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (copyOp.get() == nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        flatbuffers::FlatBufferBuilder builder(32);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        OpBuilder builder_(builder);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        builder_.add_type(OpType_Copy);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        builder.Finish(builder_.Finish());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        copyOp.reset(new BufferStorage);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        copyOp->storage = builder.ReleaseRaw(copyOp->allocated_size, copyOp->offset);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-23 13:54:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static ErrorCode _InsertCopy(Schedule::PipelineInfo& mInfo, std::map<Tensor*, std::shared_ptr<Tensor>>& mCacheConstTensors, Pipeline::WrapTensorCache& shapeFixConstCache, bool ownInput, bool permitCodegen) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    std::shared_ptr<BufferStorage> copyOp;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-23 13:54:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto iterP = shapeFixConstCache.begin(); iterP != shapeFixConstCache.end();) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (iter.second.first.lock() == nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // Has released, remove cache
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            iterP = shapeFixConstCache.erase(iterP);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-23 13:54:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto des = iter.first.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bool needReset = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (des->usage == Tensor::InsideDescribe::CONSTANT && ((des->stageMask & Tensor::InsideDescribe::CONTENT_NOT_CHANGE) != 0)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // If the tensor is not compute in shape-geometry stage, needn't recopy it
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            needReset = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (needReset) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            TensorUtils::getDescribeOrigin(iter.second.second.get())->setBackend(nullptr);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            TensorUtils::getDescribeOrigin(iter.second.second.get())->mem = nullptr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        iterP++;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (buffer.command.empty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto commands = std::move(buffer.command);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (auto& iterP : commands) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (iter.op->type() == OpType_Copy) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // Check If need wrap
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto curBackend = iter.execution->backend();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_PIPELINE_DEBUG
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (nullptr != iter.op->name()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                MNN_PRINT("%s Run on %d\n", iter.op->name()->c_str(), curBackend->type());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            iter.workInputs = iter.inputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (int v=0; v<iter.inputs.size(); ++v) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto t = iter.inputs[v];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto des = TensorUtils::getDescribe(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (WrapExecution::needWrap(t, curBackend)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    do {
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        Tensor* newTensor = nullptr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        if (!des->isMutable) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-18 09:36:26 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            newTensor = WrapExecution::copyConstCache(t, curBackend, mCacheConstTensors, permitCodegen);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            if (nullptr != newTensor) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                iter.workInputs[v] = newTensor;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        if (!ownInput) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            if (TensorUtils::getDescribe(t)->usage == Tensor::InsideDescribe::INPUT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                auto inputCacheIter = mInfo.first.inputTensorCopyCache.find(t);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                if (inputCacheIter != mInfo.first.inputTensorCopyCache.end()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                    auto& tensorCache = inputCacheIter->second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                    if (nullptr == std::get<0>(tensorCache) || WrapExecution::needWrap(std::get<0>(tensorCache), curBackend)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        std::shared_ptr<Tensor> wrapTensor = WrapExecution::makeCopyTensor(t, curBackend);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        TensorUtils::getDescribe(wrapTensor.get())->usage = Tensor::InsideDescribe::CONSTANT;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        std::get<0>(tensorCache) = wrapTensor.get();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        std::get<1>(tensorCache) = wrapTensor;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        std::get<2>(tensorCache) = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        std::get<3>(tensorCache) = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                    iter.workInputs[v] = std::get<0>(tensorCache);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                    if (std::get<2>(tensorCache)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        auto allocRes = curBackend->onAcquireBuffer(std::get<1>(tensorCache).get(), Backend::STATIC);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        if (!allocRes) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                            return OUT_OF_MEMORY;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        std::get<2>(tensorCache) = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                    break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-23 13:54:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            auto titer = shapeFixConstCache.find(std::make_pair(des, curBackend));
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            if (titer != shapeFixConstCache.end()) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-23 13:54:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                                newTensor = titer->second.second.get();
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                std::shared_ptr<MNN::Tensor> tensor(new Tensor);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-23 13:54:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                                shapeFixConstCache.insert(std::make_pair(std::make_pair(des, curBackend), std::make_pair(std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent), tensor)));
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                                newTensor = tensor.get();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            iter.workInputs[v] = newTensor;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        auto newMemory = TensorUtils::getDescribeOrigin(newTensor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        if (newMemory->getBackend() != nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            // The memory has been init, skip it
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        TensorUtils::copyShape(t, newTensor, true, true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        if (des->usage == Tensor::InsideDescribe::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            TensorUtils::getDescribe(newTensor)->usage = des->usage;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            auto tempRes = WrapExecution::allocAndCopy(curBackend, t, newTensor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            if (!tempRes) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                return OUT_OF_MEMORY;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        newMemory->setBackend(curBackend);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        auto copyWrap = WrapExecution::makeCopyExecution(curBackend, mInfo.first.cache.second.get());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        _makeCopyOp(copyOp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        std::shared_ptr<Command> cmdP(new Command);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        auto& cmd = *cmdP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        cmd.buffer = copyOp;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        cmd.workInputs  = {t};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        cmd.workOutputs = {newTensor};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        cmd.op      = flatbuffers::GetRoot<Op>(cmd.buffer->buffer());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        cmd.execution.reset(copyWrap);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        buffer.command.emplace_back(cmdP);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    } while(false);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            buffer.command.emplace_back(iterP);
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            iter.workOutputs = iter.outputs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (int v=0; v<iter.workOutputs.size(); ++v) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto t = iter.workOutputs[v];
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (WrapExecution::needWrap(t, curBackend)) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    auto copyWrap = WrapExecution::makeCopyExecution(curBackend, mInfo.first.cache.second.get());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    std::shared_ptr<Tensor> newTensor(new Tensor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    TensorUtils::copyShape(t, newTensor.get(), true, true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    iterP->workOutputs[v] = newTensor.get();
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    _makeCopyOp(copyOp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    std::shared_ptr<Command> cmdP(new Command);
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    auto& cmd = *cmdP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    cmd.buffer = copyOp;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    cmd.workInputs  = {newTensor.get()};
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    cmd.workOutputs = {t};
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    cmd.op      = flatbuffers::GetRoot<Op>(cmd.buffer->buffer());
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    buffer.extras.emplace_back(newTensor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    cmd.execution.reset(copyWrap);
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    buffer.command.emplace_back(cmdP);
							 | 
						
					
						
							
								
									
										
										
										
											2023-10-18 10:31:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    for(int i = 0; i < iter.inputs.size(); ++i){
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        if(t == iter.inputs[i]){
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            iterP->workOutputs[v] = iter.workInputs[i];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            cmd.workInputs = {iter.workInputs[i]};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return NO_ERROR;
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-30 10:02:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void Pipeline::_recycleDynamicMemory(Command* command) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto& t : command->workOutputs) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto memoryType = _getTensorStorageType(t, mOutputStatic);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (Backend::DYNAMIC == memoryType) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            TensorUtils::getDescribeOrigin(t)->mem = nullptr;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& t : command->workInputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto memoryType = _getTensorStorageType(t, mOutputStatic);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (Backend::DYNAMIC == memoryType) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            TensorUtils::getDescribeOrigin(t)->mem = nullptr;
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void Pipeline::openResizeCheck() {
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-24 15:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifndef MNN_BUILD_MINI
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mGeometryNeedRelease = false;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        info.computeCache.open();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-24 15:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-30 10:02:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ErrorCode Pipeline::fixResizeCache() {
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-24 15:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifndef MNN_BUILD_MINI
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // TODO: Recompute release mask and set mGeometryNeedRelease = true
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT && (!info.computeCache.needExecuteConst)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            info.executeBuffer.command.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            info.executeBuffer.extras.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            info.cacheBuffer.command.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            info.cacheBuffer.extras.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 15:34:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-09-12 12:57:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mInfo.first.cache.first->onResizeBegin();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mInfo.first.cache.first->onResizeEnd();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mInfo.first.cache.second->onResizeBegin();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mInfo.first.cache.second->onResizeEnd();
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto res = mInfo.first.cache.first->onSelectDynamicAllocator(1, 2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    res = res && mInfo.first.cache.second->onSelectDynamicAllocator(1, 2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (!res) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        MNN_PRINT("%d backend don't support resize fix optimize\n", mInfo.first.cache.first->type());
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-24 15:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        mGeometryNeedRelease = true;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return NOT_SUPPORT;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    size_t totalNumber = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    size_t fixNumber = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Mask begin
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (info.type != Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            totalNumber += buffer.command.size();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-11 19:17:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if ((!info.computeCache.canCache()) && info.computeCache.needComputeShape) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // If the session has been resized and the op is checked will change shape, set as shape mutable
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            info.computeCache.close(false);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        info.computeCache.close(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // TODO: OCL and Vulkan don't support input vary
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bool notSupportInputVarying = !OpCommonUtils::supportDynamicInputMemory(mInfo.first.cache.first->type());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (int cmdIndex=0; cmdIndex<buffer.command.size(); ++cmdIndex) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& cmd = *buffer.command[cmdIndex];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            cmd.group = 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (notSupportInputVarying) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto t : cmd.workInputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (TensorUtils::getDescribe(t)->group < 0 || TensorUtils::getDescribe(t)->usage != Tensor::InsideDescribe::NORMAL) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        cmd.group = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-27 14:38:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (mOutputStatic) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    for (auto t : cmd.workOutputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        if (TensorUtils::getDescribe(t)->usage != Tensor::InsideDescribe::NORMAL) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            cmd.group = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (1 == cmd.group) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                fixNumber++;
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            for (auto t : cmd.workInputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (TensorUtils::getDescribe(t)->group == 0) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    TensorUtils::getDescribe(t)->group = 1;
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            for (auto t : cmd.workOutputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                TensorUtils::getDescribe(t)->group = 1;
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Mask End
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    _allocForTensor(1, true);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mInfo.first.cache.first->onSelectDynamicAllocator(0, 2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    res && mInfo.first.cache.second->onSelectDynamicAllocator(0, 2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    MNN_PRINT("Fix: %d - Total: %d, rate = %f\n", fixNumber, totalNumber, (float)fixNumber / (float)totalNumber);
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-24 15:46:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return NO_ERROR;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								ErrorCode Pipeline::_allocForTensor(int index, bool allocInput) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_PIPELINE_DEBUG
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int resizeNumber = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Compute RefCount Begin
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // MNN_PRINT("before resize, mInfo.second size:%lu, command size:%lu,op type:%s, op name:%s\n", mInfo.second.size(), buffer.command.size(), EnumNameOpType(info.op->type()), info.op->name()->c_str());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (auto& iterP : buffer.command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto t : iter.workInputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto des = TensorUtils::getDescribe(t);
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-04 10:42:11 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (des->usage != Tensor::InsideDescribe::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    des->useCount = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (auto& iterP : buffer.command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto t : iter.workInputs) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto des = TensorUtils::getDescribe(t);
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-04 10:42:11 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (des->usage != Tensor::InsideDescribe::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    des->useCount += 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Compute RefCount End
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mBackend->onResizeBegin();
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-04 10:42:11 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mBackupBackend->onResizeBegin();
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-18 09:36:26 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (int cmdIndex=0; cmdIndex < buffer.command.size(); ++cmdIndex) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iterP = buffer.command[cmdIndex];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& iter = *iterP;
							 | 
						
					
						
							
								
									
										
										
										
											2022-11-18 22:35:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_PIPELINE_DEBUG
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto memory = const_cast<Runtime*>(mRuntime)->onGetMemoryInMB();
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-18 09:36:26 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (nullptr != info.op->name()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                MNN_PRINT("%f, before Resize: %s - %d\n", memory, info.op->name()->c_str(), cmdIndex);
							 | 
						
					
						
							
								
									
										
										
										
											2022-11-18 22:35:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            // Alloc for Tensors
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto curBackend = iter.execution->backend();
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (allocInput) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                for (auto t : iter.workInputs) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    auto allocRes = _allocTensor(t, curBackend, mOutputStatic, index);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    if (!allocRes) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        return OUT_OF_MEMORY;
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            {
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                for (auto t : iter.workOutputs) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    auto res = _allocTensor(t, curBackend, mOutputStatic, index);
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    if (!res) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        return OUT_OF_MEMORY;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-15 14:12:35 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2023-07-18 09:36:26 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_PIPELINE_DEBUG
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (iter.info != nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                MNN_PRINT("before Resize 2, calling: %s - %d \n", iter.info->name().c_str(), cmdIndex);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (iter.group == index) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_PIPELINE_DEBUG
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                resizeNumber++;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto code = iter.execution->onResize(iter.workInputs, iter.workOutputs);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (NO_ERROR != code) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-12-04 11:12:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_PIPELINE_DEBUG
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    MNN_ERROR("Pipeline Resize error: %d\n", code);
							 | 
						
					
						
							
								
									
										
										
										
											2023-12-04 11:12:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    if (iter.info.get()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        MNN_ERROR("Resize error for type = %s, name = %s \n", iter.info->type().c_str(), iter.info->name().c_str());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    return code;
							 | 
						
					
						
							
								
									
										
										
										
											2023-12-04 11:12:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            // Free mid tensor
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            for (auto t : iter.workInputs) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                _releaseTensor(t, allocInput, index);
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Recycle All Dynamic Tensor
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (auto& c : buffer.command) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (c->group != index) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            _recycleDynamicMemory(c.get());
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-20 20:16:25 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto code = mBackend->onResizeEnd();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (code != NO_ERROR) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return code;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_PIPELINE_DEBUG
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    MNN_PRINT("Resize %d op for index: %d\n", resizeNumber, index);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-20 20:16:25 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    code = mBackupBackend->onResizeEnd();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return code;
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ErrorCode Pipeline::allocMemory(bool firstMalloc, bool forbidReplace) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // MNN_PRINT("allocMemory mtype:%d, cpubackendType:%d, cpuBackend runtime:%p\n", mBackend->type(), mBackupBackend->type(), mBackupBackend->getRuntime());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (!firstMalloc) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-06-03 20:09:34 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (OpCommonUtils::supportDynamicInputMemory(mInfo.first.cache.first->type()) && (!mInfo.first.inputBackendChange)) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            return NO_ERROR;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /* Create Execution Begin */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Check If we need a lone time for init
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (mBackend->type() != MNN_FORWARD_CPU && mBackend->type() != MNN_FORWARD_CPU_EXTENSION && mTuneAttr.autoSetOpType) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Runtime::OpInfo dstInfo;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int currentInitCount = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        std::vector<Schedule::OpCacheInfo> initInfos;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (auto& info : mInfo.second) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& buffer = info.executeBuffer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto& iterP : buffer.command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                auto& iter = *iterP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                dstInfo.initCostLong = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                mRuntime->onMeasure(iter.inputs, iter.outputs, iter.op, dstInfo);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (dstInfo.initCostLong) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    initInfos.emplace_back(info);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    currentInitCount++;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (currentInitCount >= mTuneAttr.maxTuningNumber) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (currentInitCount > 0) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            MNN_PRINT("Turn back to cpu\n");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // Reset execution
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (auto& info : mInfo.second) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                info.executionCache.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (auto& iterP : info.executeBuffer.command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    iterP->execution = nullptr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    iterP->execution = nullptr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    _recycleDynamicMemory(iterP.get());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (!mRuntime->hasAsyncWork()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                _pushTuningTask(std::move(initInfos));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2024-11-18 14:37:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            mBackend.reset(mCpuRuntime->onCreate(nullptr, mBackupBackend.get()));
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto code = _createExecutions(mInfo, mExternalFile, mExternalStorage);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (NO_ERROR != code) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return code;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /* Create Execution End */
							 | 
						
					
						
							
								
									
										
										
										
											2024-09-12 12:57:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mBackend->onClearBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mBackupBackend->onClearBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    _SetTensorBackend(mInfo, mAllocInput);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Insert Wrap If needed
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2024-09-12 12:57:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // Reset memory allocator for backend
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto insertCode = _InsertCopy(mInfo, mCacheConstTensors, mWrapTensors, mAllocInput, forbidReplace);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (NO_ERROR != insertCode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return insertCode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    /* Insert Wrap End*/
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return _allocForTensor(0, mAllocInput);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void Pipeline::_copyInputs() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& iter : mInfo.first.inputTensorCopyCache) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        auto& tensorCache = iter.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (std::get<0>(tensorCache) == nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (!std::get<3>(tensorCache)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-28 11:38:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        std::get<0>(tensorCache)->copyFromHostTensor(iter.first);
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        std::get<3>(tensorCache) = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								ErrorCode Pipeline::execute() {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    _copyInputs();
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto enterCode = _enterExecute();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (NO_ERROR != enterCode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return enterCode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (int cmdIndex=0; cmdIndex<buffer.command.size(); ++cmdIndex) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto& cmd = *buffer.command[cmdIndex];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#ifdef MNN_PIPELINE_DEBUG
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (info.op->name() != nullptr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                std::string groupOfInput = "input group: [";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (int v=0; v<cmd.workInputs.size(); ++v) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    groupOfInput = groupOfInput + " " + std::to_string(TensorUtils::getDescribe(cmd.workInputs[v])->group) + " ";
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                groupOfInput += "]";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                std::string deviceOfInput = "input: [";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (int v=0; v<cmd.workInputs.size(); ++v) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    deviceOfInput = deviceOfInput + " " + std::to_string(cmd.workInputs[v]->deviceId()) + " ";
							 | 
						
					
						
							
								
									
										
										
										
											2023-09-20 20:16:25 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                deviceOfInput += "]";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                std::string deviceOfOutput = "output: [";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                for (int v=0; v<cmd.workOutputs.size(); ++v) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    deviceOfOutput = deviceOfOutput + " " + std::to_string(cmd.workOutputs[v]->deviceId()) + " ";
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                deviceOfOutput += "]";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                MNN_PRINT("Group: %d, %s - %d, type=%s, inputs: %s, devices: %s - %s\n", info.group, info.op->name()->c_str(), cmdIndex, EnumNameOpType(cmd.op->type()), groupOfInput.c_str(), deviceOfInput.c_str(), deviceOfOutput.c_str());
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-16 09:42:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto code = cmd.execution->onExecute(cmd.workInputs, cmd.workOutputs);
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (NO_ERROR != code) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                _exitExecute();
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                return code;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    _exitExecute();
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return NO_ERROR;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ErrorCode Pipeline::_enterExecute() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mBackend->onExecuteBegin();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mBackupBackend->onExecuteBegin();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (mRuntime->pCurrentStatus != NO_ERROR) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return (ErrorCode)mRuntime->pCurrentStatus;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (mCpuRuntime->pCurrentStatus != NO_ERROR) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return (ErrorCode)mCpuRuntime->pCurrentStatus;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return NO_ERROR;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void Pipeline::_exitExecute() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mBackupBackend->onExecuteEnd();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mBackend->onExecuteEnd();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								ErrorCode Pipeline::executeCallBack(const TensorCallBackWithInfo& before, const TensorCallBackWithInfo& after) {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    _copyInputs();
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto enterCode = _enterExecute();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (NO_ERROR != enterCode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return enterCode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto& mBackend = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& mBackupBackend = mInfo.first.cache.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (auto& info : mInfo.second) {
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (info.type == Schedule::CONSTANT) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        auto& buffer = info.executeBuffer;
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-11 11:12:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (int cmdIndex=0; cmdIndex < buffer.command.size(); ++cmdIndex) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            auto cmdP = buffer.command[cmdIndex];
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto& cmd = *cmdP;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (nullptr == cmd.info.get()) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                auto code = cmd.execution->onExecute(cmd.workInputs, cmd.workOutputs);
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (NO_ERROR != code) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    _exitExecute();
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    return code;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                continue;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto run = before(cmd.workInputs, cmd.info.get());
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (run) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                auto code = cmd.execution->onExecute(cmd.workInputs, cmd.workOutputs);
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (NO_ERROR != code) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    _exitExecute();
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    return code;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2023-04-18 18:54:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            auto stop = !(after(cmd.workOutputs, cmd.info.get()));
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (stop) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                _exitExecute();
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                return CALL_BACK_STOP;
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-22 14:47:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    _exitExecute();
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return NO_ERROR;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Pipeline::~Pipeline() {
							 | 
						
					
						
							
								
									
										
										
										
											2022-12-30 15:18:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    auto& bn = mInfo.first.cache.first;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    auto& backupbn = mInfo.first.cache.second;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bn->onClearBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    backupbn->onClearBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    mInfo.second.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2021-11-30 10:10:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mCacheConstTensors.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-19 11:58:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    mWrapTensors.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								} // namespace MNN
							 |