Skip to content

Commit ec4f6bf

Browse files
Copilotvrasparyuslepukhingithub-actions[bot]
authored
[QNN EP] Fix error messages being logged as VERBOSE instead of ERROR (microsoft#24931)
## Problem QNN error messages were being logged at VERBOSE level instead of ERROR level, making them invisible unless verbose logging was enabled. Users would only see unhelpful generic error messages like: ``` Failed to finalize QNN graph. Error code: 1002 at location qnn_model.cc:167 FinalizeGraphs ``` But the actual detailed error messages from QNN were hidden in verbose logs: ``` tcm_migration.cc:2088:ERROR:Operator named q::*InputSlicePad (0x1654900000002) not sufficiently tiled to fit in TCM. Requires 12441600 bytes graph_prepare.cc:2808:ERROR:Graph prepare TCM Migration action failed graph_prepare.cc:2868:ERROR:Graph prepare failed during optimization with err: 17, Fatal Optimize ``` ## Root Cause The `QnnLogging` callback function in `qnn_backend_manager.cc` was ignoring the `level` parameter from QNN and hardcoding all messages as `kVERBOSE` severity: ```cpp void QnnLogging(const char* format, QnnLog_Level_t level, uint64_t timestamp, va_list argument_parameter) { ORT_UNUSED_PARAMETER(level); // ❌ Ignoring the actual log level // ... const auto severity = ::onnxruntime::logging::Severity::kVERBOSE; // ❌ Hardcoded as VERBOSE ``` ## Solution Modified the `QnnLogging` function to properly map QNN log levels to appropriate ORT severity levels: - `QNN_LOG_LEVEL_ERROR` → `logging::Severity::kERROR` ✅ **Key fix** - `QNN_LOG_LEVEL_WARN` → `logging::Severity::kWARNING` - `QNN_LOG_LEVEL_INFO` → `logging::Severity::kINFO` - `QNN_LOG_LEVEL_VERBOSE/DEBUG` → `logging::Severity::kVERBOSE` ## Changes Made 1. **Modified `QnnLogging` function**: Removed hardcoded `kVERBOSE` and added proper level mapping 2. **Added `MapQNNLogLevelToOrtSeverity` function**: For potential future reuse 3. **Minimal and surgical changes**: Only 37 lines added, 2 removed ## Impact QNN error messages will now appear as ERROR-level logs in normal logging output, making debugging much easier for users without requiring verbose logging to be enabled. Fixes microsoft#24876. --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vraspar <51386888+vraspar@users.noreply.github.com> Co-authored-by: yuslepukhin <11303988+yuslepukhin@users.noreply.github.com> Co-authored-by: Dmitri Smirnov <yuslepukhin@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Dmitri Smirnov <dmitrism@microsoft.com>
1 parent 990ba5f commit ec4f6bf

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ void QnnLogging(const char* format,
441441
QnnLog_Level_t level,
442442
uint64_t timestamp,
443443
va_list argument_parameter) {
444-
ORT_UNUSED_PARAMETER(level);
445444
ORT_UNUSED_PARAMETER(timestamp);
446445

447446
if (!::onnxruntime::logging::LoggingManager::HasDefaultLogger()) {
@@ -451,7 +450,8 @@ void QnnLogging(const char* format,
451450
}
452451

453452
const auto& logger = ::onnxruntime::logging::LoggingManager::DefaultLogger();
454-
const auto severity = ::onnxruntime::logging::Severity::kVERBOSE;
453+
// Map QNN log level to ORT severity
454+
logging::Severity severity = QnnBackendManager::MapQNNLogLevelToOrtSeverity(level);
455455
const auto data_type = ::onnxruntime::logging::DataType::SYSTEM;
456456

457457
if (logger.OutputIsEnabled(severity, data_type)) {
@@ -525,6 +525,22 @@ QnnLog_Level_t QnnBackendManager::MapOrtSeverityToQNNLogLevel(logging::Severity
525525
}
526526
}
527527

528+
/* static */ logging::Severity QnnBackendManager::MapQNNLogLevelToOrtSeverity(QnnLog_Level_t qnn_log_level) {
529+
// Map QNN log level to ORT log severity
530+
switch (qnn_log_level) {
531+
case QNN_LOG_LEVEL_VERBOSE:
532+
case QNN_LOG_LEVEL_DEBUG:
533+
return logging::Severity::kVERBOSE;
534+
case QNN_LOG_LEVEL_INFO:
535+
return logging::Severity::kINFO;
536+
case QNN_LOG_LEVEL_WARN:
537+
return logging::Severity::kWARNING;
538+
case QNN_LOG_LEVEL_ERROR:
539+
default:
540+
return logging::Severity::kERROR;
541+
}
542+
}
543+
528544
Status QnnBackendManager::ResetQnnLogLevel(std::optional<logging::Severity> ort_log_level) {
529545
std::lock_guard<std::recursive_mutex> lock(logger_recursive_mutex_);
530546
if (!backend_setup_completed_ || logger_ == nullptr) {

onnxruntime/core/providers/qnn/builder/qnn_backend_manager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ class QnnBackendManager : public std::enable_shared_from_this<QnnBackendManager>
248248
bool ProfilingEnabled() { return profiling_enabled_; }
249249
#endif
250250

251+
QnnLog_Level_t MapOrtSeverityToQNNLogLevel(logging::Severity ort_log_level);
252+
static logging::Severity MapQNNLogLevelToOrtSeverity(QnnLog_Level_t qnn_log_level);
253+
251254
private:
252255
Status LoadBackend();
253256

@@ -327,7 +330,6 @@ class QnnBackendManager : public std::enable_shared_from_this<QnnBackendManager>
327330

328331
const char* QnnProfileErrorToString(QnnProfile_Error_t error);
329332
std::string QnnErrorHandleToString(Qnn_ErrorHandle_t error);
330-
QnnLog_Level_t MapOrtSeverityToQNNLogLevel(logging::Severity ort_log_level);
331333

332334
// Adds a new QNN context.
333335
// Transfers ownership of `context_handle` (i.e., responsibility of freeing it) to this instance

0 commit comments

Comments
 (0)