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

Method createExecutionWithExternal

source/core/OpCommonUtils.cpp:665–724  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

663 return true;
664}
665Execution* OpCommonUtils::createExecutionWithExternal(Backend* backend, const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
666 const MNN::Op* op, FileLoader* externalFile, std::shared_ptr<BufferStorage>& tmpstore) {
667#ifdef MNN_SKIPBUILD_GEOMETRY
668 return backend->onCreate(inputs, outputs, op);
669#else
670 bool hasExternal = false;
671 switch (op->main_type()) {
672 case OpParameter_Convolution2D:
673 hasExternal = USE_EXTERNAL_DATA(op->main_as_Convolution2D());
674 break;
675 case OpParameter_Scale:
676 hasExternal = USE_EXTERNAL_DATA(op->main_as_Scale());
677 break;
678 case OpParameter_LayerNorm:
679 hasExternal = USE_EXTERNAL_DATA(op->main_as_LayerNorm());
680 break;
681 default:
682 break;
683 }
684 if (!hasExternal) {
685 return backend->onCreate(inputs, outputs, op);
686 }
687 flatbuffers::FlatBufferBuilder builder;
688 bool usemmap = false;
689 if (backend && backend->getRuntime()) {
690 usemmap = (backend->getRuntime()->hint().useCachedMmap > 1);
691 }
692 Execution* execution;
693 if ((!usemmap)) {
694 bool res = _RebuildExternalOp(externalFile, op, builder);
695 if (!res) {
696 MNN_ERROR("Rebuild External Op failed\n");
697 return nullptr;
698 }
699 auto newOp = flatbuffers::GetRoot<MNN::Op>(builder.GetBufferPointer());
700 execution = backend->onCreate(inputs, outputs, newOp);
701 } else {
702 execution = backend->onCreate(inputs, outputs, op);
703 }
704 if (nullptr == execution) {
705 return execution;
706 }
707 if (op->main_type() == OpParameter_Convolution2D) {
708 // For convolution / deconvolution, execution will need op info after created, try clone it and remove newOp
709 Execution* copyExe = nullptr;
710 execution->onClone(backend, op, &copyExe);
711 if (nullptr != copyExe) {
712 delete execution;
713 return copyExe;
714 } else {
715#ifdef DEBUG
716 MNN_ERROR("Clone error for convolution/deconvolution, will Increase memory\n");
717#endif
718 tmpstore.reset(new BufferStorage);
719 tmpstore->storage = builder.ReleaseRaw(tmpstore->allocated_size, tmpstore->offset);
720 }
721 }
722 return execution;

Callers

nothing calls this directly

Calls 6

ReleaseRawMethod · 0.80
_RebuildExternalOpFunction · 0.70
onCreateMethod · 0.45
getRuntimeMethod · 0.45
onCloneMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected