| 832 | } |
| 833 | |
| 834 | static int _compileWholeModule(std::vector<std::string> inputNames, std::vector<std::string> outputNames, |
| 835 | std::vector<std::vector<MNN::Express::VARP>> inputs, const std::set<int>& inputIndexes, |
| 836 | const std::set<int>& outputIndexes, const void* buffer, size_t bufferSize, |
| 837 | std::string srcpath, std::string dstMNNPath) { |
| 838 | int npuIndex = 0; |
| 839 | std::vector<std::vector<MNN::Express::Variable::Info>> outputInfos; |
| 840 | std::vector<MNN::Express::Variable::Info> outputInfo; |
| 841 | std::map<std::string, std::vector<std::string>> merges; |
| 842 | std::vector<std::string> graphicNames; |
| 843 | auto path = gCacheDir + "/" + gGraphName + std::to_string(npuIndex); |
| 844 | if (!gOfflieDst.empty()) { |
| 845 | path += ("." + gOfflieDst); |
| 846 | } |
| 847 | std::vector<int> allInputShape; |
| 848 | for (int inputIndex = 0; inputIndex < inputs.size(); ++inputIndex) { |
| 849 | std::vector<MNN::Express::Variable::Info> inputInfos(inputs[inputIndex].size()); |
| 850 | for (int i = 0; i < inputInfos.size(); ++i) { |
| 851 | inputInfos[i] = *inputs[inputIndex][i]->getInfo(); |
| 852 | } |
| 853 | std::vector<int> currInputShape; |
| 854 | for (int i = 0; i < inputInfos.size(); i++) { |
| 855 | for (int j = 0; j < inputInfos[i].dim.size(); j++) { |
| 856 | currInputShape.emplace_back(inputInfos[i].dim[j]); |
| 857 | } |
| 858 | } |
| 859 | allInputShape.insert(allInputShape.end(), currInputShape.begin(), currInputShape.end()); |
| 860 | |
| 861 | std::string srcPath; |
| 862 | std::string graphicName; |
| 863 | if (inputIndex == 0) { |
| 864 | srcPath = gCacheDir + "/" + gGraphName + std::to_string(npuIndex); |
| 865 | graphicName = gGraphName + std::to_string(npuIndex); |
| 866 | } else { |
| 867 | srcPath = gCacheDir + "/" + gGraphName + std::to_string(inputIndex) + "_" + std::to_string(npuIndex); |
| 868 | graphicName = gGraphName + std::to_string(inputIndex) + "_" + std::to_string(npuIndex); |
| 869 | } |
| 870 | if (!gOfflieSrc.empty()) { |
| 871 | srcPath += ("." + gOfflieSrc); |
| 872 | } |
| 873 | if (merges.find(path) != merges.end()) { |
| 874 | merges[path].emplace_back(srcPath); |
| 875 | } else { |
| 876 | merges.insert(std::make_pair(path, std::vector<std::string>{srcPath})); |
| 877 | } |
| 878 | graphicNames.push_back(graphicName); |
| 879 | MNN::ScheduleConfig config; |
| 880 | config.type = gNPUType; |
| 881 | std::shared_ptr<MNN::Express::Executor::RuntimeManager> rtmgr( |
| 882 | MNN::Express::Executor::RuntimeManager::createRuntimeManager(config)); |
| 883 | rtmgr->setExternalFile((srcpath + ".weight").c_str()); |
| 884 | rtmgr->setCache(srcPath.c_str()); |
| 885 | rtmgr->setHint(MNN::Interpreter::KVCACHE_SIZE_LIMIT, gMaxKVSize); |
| 886 | MNN::Express::Module::Config mdconfig; |
| 887 | mdconfig.shapeMutable = false; |
| 888 | std::shared_ptr<MNN::Express::Module> m( |
| 889 | MNN::Express::Module::load(inputNames, outputNames, (const uint8_t*)buffer, bufferSize, rtmgr, &mdconfig), |
| 890 | MNN::Express::Module::destroy); |
| 891 | auto outputs = m->onForward(inputs[inputIndex]); |
no test coverage detected