MCPcopy Create free account
hub / github.com/alibaba/MNN / _resize

Method _resize

express/module/StaticModule.cpp:439–578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

437 }
438}
439ErrorCode StaticModule::_resize(const std::vector<Express::VARP>& inputs) {
440 ErrorCode code = NO_ERROR;
441 auto& pipelineInfo = mSession->getPipelineInfo(0);
442 auto rtmInside = mRuntimeManager->getInside();
443 int curStatus = 0;
444 if (mResource->mModes.inputMode == Interpreter::Session_Input_User) {
445 pipelineInfo.first.inputBackendChange = false;
446 bool needResize = mResource->mUseContentInputs;
447 for (int i = 0; i < inputs.size(); ++i) {
448 if (nullptr == mInputTensors[i]) {
449 continue;
450 }
451 auto inputTensor = Utils::getTensor(inputs[i]);
452 Schedule::TENSORCACHE* cacheTensor = nullptr;
453 if (mPrevInputTensor[i].first != inputTensor) {
454 auto newBackend = TensorUtils::getDescribeOrigin(inputTensor)->getBackend();
455 auto newType = MNN_FORWARD_CPU;
456 if (nullptr != newBackend) {
457 newType = newBackend->type();
458 }
459 if (mPrevInputTensor[i].second != newType) {
460 pipelineInfo.first.inputBackendChange = true;
461 }
462 auto cacheIter = pipelineInfo.first.inputTensorCopyCache.find(mInputTensors[i]);
463 cacheTensor = &cacheIter->second;
464 MNN_ASSERT(cacheIter != pipelineInfo.first.inputTensorCopyCache.end());
465 std::get<3>(cacheIter->second) = true;
466 mPrevInputTensor[i] = std::make_pair(inputTensor, newType);
467 if (std::get<1>(*cacheTensor) != nullptr) {
468 if (!WrapExecution::needWrap(inputTensor, TensorUtils::getDescribeOrigin(std::get<0>(*cacheTensor))->getBackend())) {
469 // No need copy now, reset it
470 cacheIter->second = std::make_tuple(nullptr, nullptr, true, true);
471 }
472 }
473 }
474 auto srcDes = TensorUtils::getDescribe(inputTensor);
475 auto des = TensorUtils::getDescribe(mInputTensors[i]);
476 bool needCopy = false;
477 if (nullptr != srcDes->quantAttr.get()) {
478 if (nullptr == des->quantAttr.get()) {
479 needCopy = true;
480 }
481 }
482 if (mResource->mInputNeedCPU[i]) {
483 if (0 != inputTensor->buffer().device) {
484 needCopy = true;
485 }
486 }
487 if (srcDes->tensorArrayAttr.get() != nullptr) {
488 // For tensorArray, don't need content
489 needCopy = false;
490 mSession->setNeedResize();
491 }
492 bool needMalloc;
493 if (needCopy) {
494 auto srcPtr = (uint8_t*)inputs[i]->readMap<uint8_t>();
495 needMalloc = mInputTensors[i]->buffer().host != srcPtr;
496 mInputTensors[i]->buffer().host = srcPtr;

Callers

nothing calls this directly

Calls 14

getTensorFunction · 0.85
_resizeTensorFunction · 0.85
setBackendMethod · 0.80
onAcquireBufferMethod · 0.80
copyFromHostTensorMethod · 0.80
sizeMethod · 0.45
getBackendMethod · 0.45
typeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
getMethod · 0.45
bufferMethod · 0.45

Tested by

no test coverage detected