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

Method load

express/module/PipelineModule.cpp:677–714  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

675}
676
677Module* PipelineModule::load(const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, const uint8_t* buffer, size_t length, const std::shared_ptr<MNN::Express::Executor::RuntimeManager> rtMgr, const Module::Config* config) {
678 // Create Subgraph
679 auto net = GetNet(buffer);
680 if (nullptr == net->oplists() || nullptr == net->tensorName()) {
681 MNN_ERROR("Invalid net, for null oplist or tensorName\n");
682 return nullptr;
683 }
684 Module::Config defaultConfig;
685 if (nullptr == config) {
686 config = &defaultConfig;
687 }
688 auto subGraphs = net->subgraphs();
689 if (config->dynamic) {
690 // TODO: Support subgraph
691 if (nullptr == subGraphs) {
692 auto varMap = MNN::Express::Variable::loadMap(buffer, length);
693 std::vector<MNN::Express::VARP> inputsVar(inputs.size());
694 for (int i=0; i<inputs.size(); ++i) {
695 inputsVar[i] = varMap[inputs[i]];
696 }
697 std::vector<MNN::Express::VARP> outputsVar(outputs.size());
698 for (int i=0; i<outputs.size(); ++i) {
699 outputsVar[i] = varMap[outputs[i]];
700 }
701 return extract(inputsVar, outputsVar, false);
702 } else {
703 MNN_ERROR("Don't support subgraph for dynamic load, turn back to static load\n");
704 }
705 }
706 std::map<std::string, SubGraph> subGraphMap;
707 _createSubGraph(net, rtMgr, config, subGraphMap);
708 std::shared_ptr<BufferStorage> bufferStorage(new BufferStorage);
709 bufferStorage->storage = new uint8_t[length];
710 ::memcpy(bufferStorage->storage, buffer, length);
711 bufferStorage->offset = 0;
712 bufferStorage->allocated_size = length;
713 return load(inputs, outputs, bufferStorage, rtMgr, config, subGraphMap);
714}
715
716Module* PipelineModule::load(const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, std::shared_ptr<BufferStorage> bufferStorage, std::shared_ptr<MNN::Express::Executor::RuntimeManager> rtMgr, const Module::Config* config, std::map<std::string, SubGraph>& subGraphMap) {
717 MNN_ASSERT(nullptr != rtMgr);

Callers

nothing calls this directly

Calls 15

GetNetFunction · 0.85
extractFunction · 0.85
initConstTensorsFunction · 0.85
_createSubModuleFunction · 0.85
applyMetaToRuntimeMethod · 0.80
GetAsStringMethod · 0.80
registerModelMethod · 0.80
_createSubModuleInfoFunction · 0.70
loadFunction · 0.50
cloneFunction · 0.50
createFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected