From afbee6eb0c169d34972744d95ae3c2abcfc62fa7 Mon Sep 17 00:00:00 2001 From: Hector Li Date: Thu, 16 Jan 2025 09:07:54 -0800 Subject: [PATCH] Fix the power mode issue for the case that run from context model (#23330) ### Description Set power config id and the default power mode from provider option (if there is) for main thread, otherwise it will mess up the power mode if user just create session without run it. The issue fixed by this PR is: Process 1 just creates the session without run it. Then, start process 2 which creates the session and run it with power saver mode. The result is with burst power mode. --- onnxruntime/core/providers/qnn/qnn_execution_provider.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/qnn/qnn_execution_provider.cc b/onnxruntime/core/providers/qnn/qnn_execution_provider.cc index 04e7d15d62..e9d6884b8c 100644 --- a/onnxruntime/core/providers/qnn/qnn_execution_provider.cc +++ b/onnxruntime/core/providers/qnn/qnn_execution_provider.cc @@ -707,6 +707,12 @@ QNNExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_viewer return result; } + if (IsNpuBackend(qnn_backend_manager_->GetQnnBackendType())) { + // Set the power config id and the default power mode from provider option for main thread, + // otherwise it will mess up the power mode if user just create session without run it. + GetPerThreadContext(); + } + // Report error if QNN CPU backend is loaded while CPU fallback is disabled if (disable_cpu_ep_fallback_ && qnn_backend_manager_->GetQnnBackendType() == qnn::QnnBackendType::CPU) { LOGS(logger, ERROR) << "Qnn CPU backend is loaded while CPU fallback is disabled."; @@ -905,7 +911,6 @@ Status QNNExecutionProvider::CompileFromOrtGraph(const std::vector& fused_nodes_and_graphs, std::vector& node_compute_funcs) { const auto& logger = *GetLogger(); - bool is_qnn_ctx_model = qnn::IsFusedGraphHasCtxNode(fused_nodes_and_graphs); onnxruntime::PathString context_cache_path;