Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,10 @@ static const char* const kOrtSessionOptionsDisableModelCompile = "session.disabl
// Note: UNSUPPORTED models always fail regardless of this setting.
static const char* const kOrtSessionOptionsFailOnSuboptimalCompiledModel =
"session.fail_on_suboptimal_compiled_model";

// THIS OPTION IS NOT A REGULAR SESSION OPTION SINCE IT CAN BE MODIFIED AT ANY TIME
// Meant to be used with SetEpDynamicOptions
// options for HTP performance mode: "burst", "balanced", "default", "high_performance",
// "high_power_saver", "low_balanced", "extreme_power_saver", "low_power_saver", "power_saver",
// "sustained_high_performance". Default to "default".
static const char* const kOrtEpDynamicOptionsHtpPerformanceMode = "ep.dynamic.htp_performance_mode";
11 changes: 11 additions & 0 deletions onnxruntime/core/providers/qnn/qnn_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,17 @@ Status QNNExecutionProvider::SetEpDynamicOptions(gsl::span<const char* const> ke
LOGS_DEFAULT(ERROR) << "Invalid EP Workload Type: " << value;
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Invalid EP Workload Type.");
}
} else if (key == kOrtEpDynamicOptionsHtpPerformanceMode) {
auto backend_type = qnn_backend_manager_->GetQnnBackendType();
if (qnn::QnnBackendType::HTP != backend_type && qnn::QnnBackendType::DSP != backend_type) {
return Status::OK();
}
qnn::HtpPerformanceMode htp_performance_mode = qnn::HtpPerformanceMode::kHtpDefault;
ParseHtpPerformanceMode(value, htp_performance_mode);
if (GetPerThreadContext().IsHtpPowerConfigIdValid()) {
ORT_RETURN_IF_ERROR(qnn_backend_manager_->SetHtpPowerConfig(GetPerThreadContext().GetHtpPowerConfigId(),
htp_performance_mode));
}
} else {
LOGS_DEFAULT(ERROR) << "EP Dynamic Option \"" << key << "\" is not currently supported.";
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Unsupported EP Dynamic Option");
Expand Down
15 changes: 15 additions & 0 deletions onnxruntime/test/providers/qnn/qnn_ep_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,21 @@ TEST_F(QnnHTPBackendTests, QnnEpDynamicOptions) {
} catch (const std::exception& e) {
EXPECT_STREQ("Unsupported EP Dynamic Option", e.what());
}

const char* const htp_perf_mode_type[] = {"ep.dynamic.htp_performance_mode"};
const char* const eps_type[] = {"extreme_power_saver"};
const char* const shp_type[] = {"sustained_high_performance"};
session.SetEpDynamicOptions(htp_perf_mode_type, shp_type, 1);
ort_output = session.Run(Ort::RunOptions{}, input_names_c.data(), ort_inputs.data(), ort_inputs.size(),
output_names_c.data(), 1);

session.SetEpDynamicOptions(htp_perf_mode_type, eps_type, 1);
ort_output = session.Run(Ort::RunOptions{}, input_names_c.data(), ort_inputs.data(), ort_inputs.size(),
output_names_c.data(), 1);

session.SetEpDynamicOptions(htp_perf_mode_type, shp_type, 1);
ort_output = session.Run(Ort::RunOptions{}, input_names_c.data(), ort_inputs.data(), ort_inputs.size(),
output_names_c.data(), 1);
}

// Implementation of OrtOutStreamWriteFunc that writes the compiled model to a file.
Expand Down
Loading