diff --git a/onnxruntime/test/providers/qnn/qnn_test_utils.cc b/onnxruntime/test/providers/qnn/qnn_test_utils.cc index 9f6b3fb559..4daa5b8c04 100644 --- a/onnxruntime/test/providers/qnn/qnn_test_utils.cc +++ b/onnxruntime/test/providers/qnn/qnn_test_utils.cc @@ -303,6 +303,14 @@ void RunQnnModelTest(const GetTestModelFn& build_test_case, ProviderOptions prov std::string model_data; helper.model_.SerializeToString(&model_data); + if (QNNTestEnvironment::GetInstance().dump_onnx()) { + // TODO: Use public logger + // LOGS(logging_manager.DefaultLogger(), VERBOSE) << "Save onnx model at: " << dump_path; + auto dump_path = output_dir / "dumped_f32_model.onnx"; + std::ofstream ofs(dump_path, std::ios::binary); + ofs.write(model_data.data(), static_cast(model_data.size())); + } + if (QNNTestEnvironment::GetInstance().dump_dlc()) { provider_options["dump_qnn_ir_dlc"] = "1"; provider_options["dump_qnn_ir_dlc_dir"] = output_dir.string(); @@ -322,8 +330,11 @@ void RunQnnModelTest(const GetTestModelFn& build_test_case, ProviderOptions prov const std::string& registration_name = "QNNExecutionProvider"; Ort::SessionOptions session_options; - session_options.SetLogSeverityLevel(log_severity); session_options.AddConfigEntry(kOrtSessionOptionsRecordEpGraphAssignmentInfo, "1"); + session_options.SetLogSeverityLevel(log_severity); + if (QNNTestEnvironment::GetInstance().verbose()) { + session_options.SetLogSeverityLevel(OrtLoggingLevel::ORT_LOGGING_LEVEL_VERBOSE); + } TryEnableQNNSaver(provider_options); RegisterQnnEpLibrary(registered_ep_device, session_options, registration_name, provider_options); @@ -391,6 +402,7 @@ void InferenceModel(const std::string& model_data, ExpectedEPNodeAssignment expected_ep_assignment, std::unordered_map& feeds, std::vector& output_vals, + OrtLoggingLevel log_severity, const std::unordered_map& session_option_pairs, std::optional graph_optimization_level, std::function* graph_checker [[maybe_unused]]) { @@ -403,9 +415,10 @@ void InferenceModel(const std::string& model_data, RegisterQnnEpLibrary(registered_ep_device, session_options, registration_name, provider_options); session_options.SetLogId(log_id); - - // Uncomment to dump verbose output to stdout. - // session_options.SetLogSeverityLevel(ORT_LOGGING_LEVEL_VERBOSE); + session_options.SetLogSeverityLevel(log_severity); + if (QNNTestEnvironment::GetInstance().verbose()) { + session_options.SetLogSeverityLevel(OrtLoggingLevel::ORT_LOGGING_LEVEL_VERBOSE); + } for (auto key_value : session_option_pairs) { session_options.AddConfigEntry(key_value.first.c_str(), key_value.second.c_str()); diff --git a/onnxruntime/test/providers/qnn/qnn_test_utils.h b/onnxruntime/test/providers/qnn/qnn_test_utils.h index 748c724377..b421364c81 100644 --- a/onnxruntime/test/providers/qnn/qnn_test_utils.h +++ b/onnxruntime/test/providers/qnn/qnn_test_utils.h @@ -587,6 +587,7 @@ void InferenceModel(const std::string& model_data, ExpectedEPNodeAssignment expected_ep_assignment, std::unordered_map& feeds, std::vector& output_vals, + OrtLoggingLevel log_severity = OrtLoggingLevel::ORT_LOGGING_LEVEL_ERROR, const std::unordered_map& session_option_pairs = {}, std::optional graph_optimization_level = std::nullopt, std::function* graph_checker = nullptr); @@ -834,7 +835,7 @@ inline void TestQDQModelAccuracy(const GetTestModelFn& f32_model_fn, ProviderOptions qnn_options, int opset_version, ExpectedEPNodeAssignment expected_ep_assignment, QDQTolerance tolerance = QDQTolerance(), - OrtLoggingLevel log_severity [[maybe_unused]] = OrtLoggingLevel::ORT_LOGGING_LEVEL_ERROR, + OrtLoggingLevel log_severity = OrtLoggingLevel::ORT_LOGGING_LEVEL_ERROR, const std::string& qnn_ctx_model_path = "", const std::unordered_map& session_option_pairs = {}, std::optional graph_optimization_level = std::nullopt, @@ -936,8 +937,6 @@ inline void TestQDQModelAccuracy(const GetTestModelFn& f32_model_fn, qnn_options["json_qnn_graph_dir"] = output_dir.string(); } - // TODO: Enable QNN_VERBOSE to SetLogSeverityLevel - TryEnableQNNSaver(qnn_options); // Run with QNN. @@ -954,6 +953,7 @@ inline void TestQDQModelAccuracy(const GetTestModelFn& f32_model_fn, expected_ep_assignment, qdq_helper.feeds_, qnn_qdq_outputs, + log_severity, session_option_pairs, graph_optimization_level); } else { @@ -963,6 +963,7 @@ inline void TestQDQModelAccuracy(const GetTestModelFn& f32_model_fn, expected_ep_assignment, qdq_helper.feeds_, qnn_qdq_outputs, + log_severity, session_option_pairs, graph_optimization_level, qnn_ep_graph_checker); @@ -1087,7 +1088,7 @@ inline void TestFp16ModelAccuracy(const GetTestModelFn& f32_model_fn, int opset_version, ExpectedEPNodeAssignment expected_ep_assignment, float tolerance = 0.004, - OrtLoggingLevel log_severity [[maybe_unused]] = OrtLoggingLevel::ORT_LOGGING_LEVEL_ERROR, + OrtLoggingLevel log_severity = OrtLoggingLevel::ORT_LOGGING_LEVEL_ERROR, const std::string& qnn_ctx_model_path = "", const std::unordered_map& session_option_pairs = {}) { std::filesystem::path output_dir; @@ -1179,8 +1180,6 @@ inline void TestFp16ModelAccuracy(const GetTestModelFn& f32_model_fn, qnn_options["json_qnn_graph_dir"] = output_dir.string(); } - // TODO: Enable QNN_VERBOSE to SetLogSeverityLevel - TryEnableQNNSaver(qnn_options); // Run with QNN. @@ -1197,6 +1196,7 @@ inline void TestFp16ModelAccuracy(const GetTestModelFn& f32_model_fn, expected_ep_assignment, f16_helper.feeds_, qnn_f16_outputs, + log_severity, session_option_pairs); } else { InferenceModel(f16_model_data, @@ -1205,6 +1205,7 @@ inline void TestFp16ModelAccuracy(const GetTestModelFn& f32_model_fn, expected_ep_assignment, f16_helper.feeds_, qnn_f16_outputs, + log_severity, session_option_pairs); }