Skip to content

Commit

Permalink
move the option from provider option to session option
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorSVC committed Jul 25, 2024
1 parent 3f9d550 commit 1896559
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ static const char* const kOrtSessionOptionEpContextFilePath = "ep.context_file_p
// "1": dump the EP context into the Onnx model. (default).
static const char* const kOrtSessionOptionEpContextEmbedMode = "ep.context_embed_mode";

// Specify the EPContext node name prefix to make it unique
// in case user need to merge/connect multiple EPContext nodes in one model
static const char* const kOrtSessionOptionEpContextNodeNamePrefix = "ep.context_node_name_prefix";

// Gemm fastmath mode provides fp32 gemm acceleration with bfloat16 based matmul.
// Option values:
// - "0": Gemm FastMath mode is not enabled. [DEFAULT]
Expand Down
18 changes: 7 additions & 11 deletions onnxruntime/core/providers/qnn/qnn_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ QNNExecutionProvider::QNNExecutionProvider(const ProviderOptions& provider_optio

context_cache_path_cfg_ = session_options->config_options.GetConfigOrDefault(kOrtSessionOptionEpContextFilePath, "");
LOGS_DEFAULT(VERBOSE) << "User specified context cache path: " << context_cache_path_cfg_;

// For the case that workaround QNN context PD memory limit, user need split the model into pieces and
// generate the QNN context model separately.
// It could happen that the generated EPContext node in separate graph has same node name.
// User can set this context_node_name_prefix for each split pieces to avoid that happens.
context_node_name_prefix_ = session_options->config_options.GetConfigOrDefault(kOrtSessionOptionEpContextNodeNamePrefix, "");

Check warning on line 207 in onnxruntime/core/providers/qnn/qnn_execution_provider.cc

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Lines should be <= 120 characters long [whitespace/line_length] [2] Raw Output: onnxruntime/core/providers/qnn/qnn_execution_provider.cc:207: Lines should be <= 120 characters long [whitespace/line_length] [2]
LOGS_DEFAULT(VERBOSE) << "User specified QNN context node name prefix: " << context_node_name_prefix_;
}

static const std::string BACKEND_PATH = "backend_path";
Expand Down Expand Up @@ -378,17 +385,6 @@ QNNExecutionProvider::QNNExecutionProvider(const ProviderOptions& provider_optio
LOGS_DEFAULT(VERBOSE) << "User specified enable_htp_fp16_precision: " << enable_HTP_FP16_precision_;
}

// For the case that workaround QNN context PD memory limit, user need split the model into pieces and
// generate the QNN context model separately.
// It could happen that the generated EPContext node in separate graph has same node name.
// User can set this context_node_name_prefix for each split pieces to avoid that happens.
static const std::string QNN_CONTEXT_NODE_NAME_PREFIX = "context_node_name_prefix";
auto context_node_name_prefix_pos = provider_options_map.find(QNN_CONTEXT_NODE_NAME_PREFIX);
if (context_node_name_prefix_pos != provider_options_map.end()) {
context_node_name_prefix_ = context_node_name_prefix_pos->second;
LOGS_DEFAULT(VERBOSE) << "User specified QNN context node name prefix: " << context_node_name_prefix_;
}

qnn_backend_manager_ = std::make_unique<qnn::QnnBackendManager>(
std::move(backend_path),
profiling_level_etw,
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/test/providers/qnn/qnn_ep_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ TEST_F(QnnHTPBackendTests, QnnContextGenerationNodeNamePrefix) {
provider_options["backend_path"] = "libQnnHtp.so";
#endif
std::string node_name_prefix = "node_name_prefix_test";
provider_options["context_node_name_prefix"] = node_name_prefix;

// Add kMSDomain to cover contrib op like Gelu
const std::unordered_map<std::string, int> domain_to_version = {{"", 13}, {kMSDomain, 1}};
Expand All @@ -299,6 +298,7 @@ TEST_F(QnnHTPBackendTests, QnnContextGenerationNodeNamePrefix) {
Ort::SessionOptions so;
so.AddConfigEntry(kOrtSessionOptionEpContextEnable, "1");
so.AddConfigEntry(kOrtSessionOptionEpContextFilePath, context_binary_file.c_str());
so.AddConfigEntry(kOrtSessionOptionEpContextNodeNamePrefix, node_name_prefix.c_str());
so.AppendExecutionProvider("QNN", provider_options);

Ort::Session session(*ort_env, ORT_TSTR("testdata/qnn_ctx_2_inputs_order_test.onnx"), so);
Expand Down

0 comments on commit 1896559

Please sign in to comment.