From a8bc6eb6741d08459272230298264fa59c367de6 Mon Sep 17 00:00:00 2001 From: Hector Li Date: Fri, 10 Jan 2025 20:03:11 -0800 Subject: [PATCH 1/2] 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. --- onnxruntime/core/providers/qnn/qnn_execution_provider.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/qnn/qnn_execution_provider.cc b/onnxruntime/core/providers/qnn/qnn_execution_provider.cc index 1d9242f8a5939..5cc5dac11dce5 100644 --- a/onnxruntime/core/providers/qnn/qnn_execution_provider.cc +++ b/onnxruntime/core/providers/qnn/qnn_execution_provider.cc @@ -894,8 +894,10 @@ Status QNNExecutionProvider::CompileFromOrtGraph(const std::vector& fused_nodes_and_graphs, std::vector& node_compute_funcs) { + // 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(); const auto& logger = *GetLogger(); - bool is_qnn_ctx_model = qnn::IsFusedGraphHasCtxNode(fused_nodes_and_graphs); onnxruntime::PathString context_cache_path; From aec29f1c8e479c5ebe7e33919c40e4030b2b9a7e Mon Sep 17 00:00:00 2001 From: Hector Li Date: Fri, 10 Jan 2025 21:36:31 -0800 Subject: [PATCH 2/2] move the change to earlier stage in GetCapability --- onnxruntime/core/providers/qnn/qnn_execution_provider.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/onnxruntime/core/providers/qnn/qnn_execution_provider.cc b/onnxruntime/core/providers/qnn/qnn_execution_provider.cc index 5cc5dac11dce5..483ae03a362c0 100644 --- a/onnxruntime/core/providers/qnn/qnn_execution_provider.cc +++ b/onnxruntime/core/providers/qnn/qnn_execution_provider.cc @@ -697,6 +697,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."; @@ -894,9 +900,6 @@ Status QNNExecutionProvider::CompileFromOrtGraph(const std::vector& fused_nodes_and_graphs, std::vector& node_compute_funcs) { - // 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(); const auto& logger = *GetLogger(); bool is_qnn_ctx_model = qnn::IsFusedGraphHasCtxNode(fused_nodes_and_graphs);