| 21 | using namespace MNN; |
| 22 | |
| 23 | static bool generateConfigFile(const std::string & qnnSDKPath, int socID, int dspArch, const std::vector<std::string> & graphNameVec, const std::string & outputDir, std::string & configPath, std::string & subConfigPath) { |
| 24 | configPath = MNNFilePathConcat(outputDir, "context_config.json"); |
| 25 | subConfigPath = MNNFilePathConcat(outputDir, "htp_backend_extensions.json"); |
| 26 | |
| 27 | // Write context_config.json |
| 28 | rapidjson::Document contextConfigDoc; |
| 29 | contextConfigDoc.SetObject(); |
| 30 | rapidjson::Document::AllocatorType& contextAllocator = contextConfigDoc.GetAllocator(); |
| 31 | rapidjson::Value backendExtensions(rapidjson::kObjectType); |
| 32 | std::string htpBackendExtPath = MNNFilePathConcat(qnnSDKPath, "lib/x86_64-linux-clang/libQnnHtpNetRunExtensions.so"); |
| 33 | backendExtensions.AddMember("shared_library_path", rapidjson::Value(htpBackendExtPath.c_str(), contextAllocator).Move(), contextAllocator); |
| 34 | backendExtensions.AddMember("config_file_path", rapidjson::Value(subConfigPath.c_str(), contextAllocator).Move(), contextAllocator); |
| 35 | contextConfigDoc.AddMember("backend_extensions", backendExtensions, contextAllocator); |
| 36 | rapidjson::StringBuffer contextBuffer; |
| 37 | rapidjson::PrettyWriter<rapidjson::StringBuffer> contextWriter(contextBuffer); |
| 38 | contextConfigDoc.Accept(contextWriter); |
| 39 | std::ofstream contextConfigOut(configPath); |
| 40 | contextConfigOut << contextBuffer.GetString(); |
| 41 | contextConfigOut.close(); |
| 42 | |
| 43 | // Write htp_backend_extensions.json |
| 44 | rapidjson::Document htpConfigDoc; |
| 45 | htpConfigDoc.SetObject(); |
| 46 | rapidjson::Document::AllocatorType& htpConfigAllocator = htpConfigDoc.GetAllocator(); |
| 47 | |
| 48 | // "graphs" section |
| 49 | rapidjson::Value graphs(rapidjson::kArrayType); |
| 50 | rapidjson::Value graphObj(rapidjson::kObjectType); |
| 51 | graphObj.AddMember("vtcm_mb", 8, htpConfigAllocator); |
| 52 | rapidjson::Value names(rapidjson::kArrayType); |
| 53 | for (const auto& name : graphNameVec) { |
| 54 | names.PushBack(rapidjson::Value(name.c_str(), contextAllocator).Move(), htpConfigAllocator); |
| 55 | } |
| 56 | graphObj.AddMember("graph_names", names, htpConfigAllocator); |
| 57 | graphObj.AddMember("O", 3.0, htpConfigAllocator); |
| 58 | graphObj.AddMember("fp16_relaxed_precision", 1, htpConfigAllocator); |
| 59 | graphObj.AddMember("weights_packing", true, htpConfigAllocator); |
| 60 | graphObj.AddMember("hvx_threads", 4, htpConfigAllocator); |
| 61 | graphs.PushBack(graphObj, htpConfigAllocator); |
| 62 | htpConfigDoc.AddMember("graphs", graphs, htpConfigAllocator); |
| 63 | |
| 64 | // "devices" section |
| 65 | rapidjson::Value devices(rapidjson::kArrayType); |
| 66 | rapidjson::Value deviceObj(rapidjson::kObjectType); |
| 67 | deviceObj.AddMember("soc_id", socID, htpConfigAllocator); |
| 68 | std::string hexagonArchStr = "v" + std::to_string(dspArch); |
| 69 | deviceObj.AddMember("dsp_arch", rapidjson::Value(hexagonArchStr.c_str(), contextAllocator).Move(), htpConfigAllocator); |
| 70 | rapidjson::Value cores(rapidjson::kArrayType); |
| 71 | rapidjson::Value coreObj(rapidjson::kObjectType); |
| 72 | coreObj.AddMember("core_id", 0, htpConfigAllocator); |
| 73 | coreObj.AddMember("perf_profile", "burst", htpConfigAllocator); |
| 74 | coreObj.AddMember("rpc_control_latency", 100, htpConfigAllocator); |
| 75 | cores.PushBack(coreObj, htpConfigAllocator); |
| 76 | deviceObj.AddMember("cores", cores, htpConfigAllocator); |
| 77 | devices.PushBack(deviceObj, htpConfigAllocator); |
| 78 | htpConfigDoc.AddMember("devices", devices, htpConfigAllocator); |
| 79 | |
| 80 | // "context" section |