@@ -1649,7 +1649,6 @@ static void DumpModelWithSharedCtx(ProviderOptions provider_options,
1649
1649
Ort::Session session2 (*ort_env, ToPathString (onnx_model_path2).c_str (), so);
1650
1650
}
1651
1651
1652
- #if defined(__aarch64__) || defined(_M_ARM64)
1653
1652
static void GetModelInputNames (const std::string& model_path,
1654
1653
std::vector<std::string>& input_names,
1655
1654
std::vector<std::string>& output_names,
@@ -1669,7 +1668,6 @@ static void GetModelInputNames(const std::string& model_path,
1669
1668
output_names.push_back (output->Name ());
1670
1669
}
1671
1670
}
1672
- #endif
1673
1671
1674
1672
// 1. Create 2 QDQ models
1675
1673
// 2. Initialize 2 Ort sessions which share the same QNN EP from these 2 QDQ models
@@ -1994,6 +1992,73 @@ TEST_F(QnnHTPBackendTests, LoadFromArrayWithQnnEpContextGenPathValidation) {
1994
1992
});
1995
1993
}
1996
1994
}
1995
+
1996
+ TEST_F (QnnHTPBackendTests, QnnEpDynamicOptions) {
1997
+ ProviderOptions provider_options;
1998
+ provider_options[" backend_type" ] = " htp" ;
1999
+ provider_options[" offload_graph_io_quantization" ] = " 0" ;
2000
+
2001
+ Ort::SessionOptions so;
2002
+ so.AppendExecutionProvider (" QNN" , provider_options);
2003
+ so.SetLogSeverityLevel (ORT_LOGGING_LEVEL_VERBOSE);
2004
+
2005
+ Ort::Session session (*ort_env, ORT_TSTR (" testdata/qnn_ctx/qnn_multi_ctx_embed.onnx" ), so);
2006
+
2007
+ std::vector<std::string> input_names;
2008
+ std::vector<std::string> output_names;
2009
+ GetModelInputNames (" testdata/qnn_ctx/qnn_multi_ctx_embed.onnx" , input_names, output_names,
2010
+ DefaultLoggingManager ().DefaultLogger ());
2011
+
2012
+ // Run sessions
2013
+ // prepare input
2014
+ std::vector<int64_t > input_dim{3 , 4 };
2015
+ std::vector<float > input_value (3 * 4 , 0 .0f );
2016
+ Ort::MemoryInfo info (" Cpu" , OrtDeviceAllocator, 0 , OrtMemTypeDefault);
2017
+ std::vector<Ort::Value> ort_inputs;
2018
+ std::vector<const char *> input_names_c;
2019
+ for (size_t i = 0 ; i < input_names.size (); ++i) {
2020
+ auto input_tensor = Ort::Value::CreateTensor (info, input_value.data (), input_value.size (),
2021
+ input_dim.data (), input_dim.size ());
2022
+ ort_inputs.push_back (std::move (input_tensor));
2023
+ input_names_c.push_back (input_names[i].c_str ());
2024
+ }
2025
+ std::vector<const char *> output_names_c;
2026
+ for (size_t i = 0 ; i < output_names.size (); ++i) {
2027
+ output_names_c.push_back (output_names[i].c_str ());
2028
+ }
2029
+
2030
+ auto ort_output = session.Run (Ort::RunOptions{}, input_names_c.data (), ort_inputs.data (), ort_inputs.size (),
2031
+ output_names_c.data (), 1 );
2032
+
2033
+ const char * const workload_type[] = {" ep.dynamic.workload_type" };
2034
+ const char * const efficient_type[] = {" Efficient" };
2035
+ const char * const default_type[] = {" Default" };
2036
+
2037
+ // Test Efficient & Default options
2038
+ session.SetEpDynamicOptions (workload_type, efficient_type, 1 );
2039
+ ort_output = session.Run (Ort::RunOptions{}, input_names_c.data (), ort_inputs.data (), ort_inputs.size (),
2040
+ output_names_c.data (), 1 );
2041
+
2042
+ session.SetEpDynamicOptions (workload_type, default_type, 1 );
2043
+ ort_output = session.Run (Ort::RunOptions{}, input_names_c.data (), ort_inputs.data (), ort_inputs.size (),
2044
+ output_names_c.data (), 1 );
2045
+
2046
+ // Test invalid EP dynamic option and invalid workload type
2047
+ const char * const dne[] = {" DNE" };
2048
+ try {
2049
+ session.SetEpDynamicOptions (workload_type, dne, 1 );
2050
+ FAIL () << " Expected exception to be thrown for workload type DNE but was set successfully" ;
2051
+ } catch (const std::exception& e) {
2052
+ EXPECT_STREQ (" Invalid EP Workload Type." , e.what ());
2053
+ }
2054
+
2055
+ try {
2056
+ session.SetEpDynamicOptions (dne, efficient_type, 1 );
2057
+ FAIL () << " Expected exception to be thrown for dynamic option DNE but was set successfully" ;
2058
+ } catch (const std::exception& e) {
2059
+ EXPECT_STREQ (" Unsupported EP Dynamic Option" , e.what ());
2060
+ }
2061
+ }
1997
2062
#endif // defined(__aarch64__) || defined(_M_ARM64) || defined(__linux__)
1998
2063
1999
2064
} // namespace test
0 commit comments