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

Method onForward

express/module/StaticModule.cpp:596–674  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

594}
595
596std::vector<Express::VARP> StaticModule::onForward(const std::vector<Express::VARP>& inputs) {
597
598 AUTOTIME;
599 // Apply before resize/clone may construct new Backends (e.g. onClone path).
600 if (mRuntimeManager) {
601 mRuntimeManager->applyMetaToRuntime();
602 }
603 std::vector<Express::VARP> outputs;
604 bool runResize = (!mShapeInferSeperate) || inputs.size() > 0;
605 bool runCompute = (!mShapeInferSeperate) || inputs.size() == 0;
606 if (runResize) {
607 outputs.resize(mResource->mOutputNumbers);
608 for (auto& iter : mResource->mOutputFromInput) {
609 outputs[iter.first] = inputs[iter.second];
610 }
611 }
612 if (mResource->mOutputFromTensor.empty()) {
613 return outputs;
614 }
615 Variable::compute(inputs);
616#ifdef MNN_DUMP_MEMORY
617 auto rt = Executor::getRuntime();
618 auto mem = rt.second->onGetMemoryInMB();
619 for (auto iter : rt.first) {
620 if (iter.second.get() != rt.second.get()) {
621 mem += iter.second->onGetMemoryInMB();
622 }
623 }
624 FUNC_PRINT_ALL(mem, f);
625#endif
626
627 ErrorCode code = NO_ERROR;
628 if (runResize) {
629 code = _resize(inputs);
630 }
631 if (NO_ERROR == code && runCompute) {
632 code = _execute();
633 }
634 if (NO_ERROR != code) {
635 FUNC_PRINT(code);
636 return {};
637 }
638 if (!runResize) {
639 for (auto& var : mOutputVars) {
640 // Check if needed recopy
641 auto inside = var->expr().first->inside();
642 if (nullptr != inside->mHostTensor) {
643 inside->mOutputTensors[0]->copyToHostTensor(inside->mHostTensor);
644 }
645 }
646 return {};
647 }
648 auto& pipelineInfo = mSession->getPipelineInfo(0);
649 for (int i = 0; i < mOutputTensors.size(); ++i) {
650 auto tensor = Tensor::clone(mOutputTensors[i]);
651 outputs[mResource->mOutputFromTensor[i]] = Express::Variable::create(Express::Expr::create(tensor, true));
652 auto backend = TensorUtils::getDescribeOrigin(tensor)->getBackend();
653 if (backend == pipelineInfo.first.cache.first.get()) {

Callers

nothing calls this directly

Calls 11

applyMetaToRuntimeMethod · 0.80
copyToHostTensorMethod · 0.80
cloneFunction · 0.50
createFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45
emptyMethod · 0.45
onGetMemoryInMBMethod · 0.45
getMethod · 0.45
getBackendMethod · 0.45
getInfoMethod · 0.45

Tested by

no test coverage detected