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

Function main

tools/cpp/compilefornpu.cpp:1450–1857  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1448}
1449
1450int main(int argc, const char* argv[]) {
1451 if (argc < 3) {
1452 MNN_PRINT("Usage: ./compilefornpu src.mnn dst.mnn npu.json\n");
1453 return 0;
1454 }
1455 const char* srcMNN = argv[1];
1456 const char* dstMNN = argv[2];
1457 std::vector<std::string> inputNames;
1458 std::vector<std::string> outputNames;
1459 std::vector<std::vector<MNN::Express::VARP>> inputs;
1460 std::set<std::string> skipOps;
1461
1462 if (argc >= 4) {
1463 rapidjson::Document document;
1464 std::ifstream fileNames(argv[3]);
1465 std::ostringstream output;
1466 output << fileNames.rdbuf();
1467 auto outputStr = output.str();
1468 document.Parse(outputStr.c_str());
1469 if (document.HasParseError()) {
1470 MNN_ERROR("Invalid json\n");
1471 return 0;
1472 }
1473 gNPUName = document["type"].GetString();
1474 if (gNPUName == "QNN") {
1475 MNN_PRINT("Convert for QNN, QualComn's NPU\n");
1476 gNPUType = MNN_CONVERT_QNN;
1477 gNeedOffline = true;
1478 gOfflieSrc = "";
1479 gOfflieDst = "bin";
1480 } else if (gNPUName == "MLDA") {
1481 MNN_PRINT("Convert for MLDA, MTK's NPU\n");
1482 gNPUType = MNN_CONVERT_NEUROPILOT;
1483 gNeedOffline = true;
1484 gOfflieSrc = "tflite";
1485 gOfflieDst = "dla";
1486 } else if (gNPUName == "CoreML") {
1487 MNN_PRINT("Convert for CoreML, Apple's framework\n");
1488 gNPUType = MNN_CONVERT_COREML;
1489 gNeedOffline = true;
1490 gOfflieSrc = "";
1491 gOfflieDst = "";
1492 } else {
1493 MNN_PRINT("Use Native NPU compute\n");
1494 }
1495 if (document.HasMember("cache")) {
1496 gCacheDir = document["cache"].GetString();
1497 FUNC_PRINT_ALL(gCacheDir.c_str(), s);
1498 MNNCreateDir(gCacheDir.c_str());
1499 }
1500 if (document.HasMember("graph_name")) {
1501 gGraphName = document["graph_name"].GetString();
1502 }
1503 if (document.HasMember("skips")) {
1504 auto skips = document["skips"].GetArray();
1505 for (auto iter = skips.Begin(); iter != skips.End(); iter++) {
1506 skipOps.insert(iter->GetString());
1507 }

Callers

nothing calls this directly

Calls 15

MNNCreateDirFunction · 0.85
_InputFunction · 0.85
GetNetFunction · 0.85
initConstTensorsNoAllocFunction · 0.85
_findMaskToAttentionOpsFunction · 0.85
_needSplitNetFunction · 0.85
_compileWholeModuleFunction · 0.85
_findAllConstTensorIndexFunction · 0.85
_getConstDataFunction · 0.85
_replaceConstOpFunction · 0.85
_getSubModuleIOFunction · 0.85
_compileSubModuleFunction · 0.85

Tested by

no test coverage detected