@@ -39,7 +39,7 @@ std::vector<std::string> JstringArrayToStdStrings(JNIEnv& env, jobjectArray jobj
39
39
for (jsize i = 0 ; i < length; ++i) {
40
40
const auto jobj = env.GetObjectArrayElement (jobjs, i);
41
41
if (!env.IsInstanceOf (jobj, java_string_class)) {
42
- throw std::runtime_error (" jobjectArray element is not a string" );
42
+ throw std::runtime_error (" jobjectArray element is not a string. " );
43
43
}
44
44
const auto jstr = static_cast <jstring>(jobj);
45
45
strs.emplace_back (JstringToStdString (env, jstr));
@@ -69,9 +69,9 @@ extern "C" JNIEXPORT jstring JNICALL
69
69
Java_com_onnxruntime_example_modeltester_MainActivity_run (JNIEnv* env, jobject thiz,
70
70
jbyteArray java_model_bytes,
71
71
jint num_iterations,
72
- jstring execution_provider_type ,
73
- jobjectArray execution_provider_option_names ,
74
- jobjectArray execution_provider_option_values ) {
72
+ jstring java_execution_provider_type ,
73
+ jobjectArray java_execution_provider_option_names ,
74
+ jobjectArray java_execution_provider_option_values ) {
75
75
try {
76
76
auto model_bytes = util::MakeUniqueJbyteArrayElementsPtr (*env, java_model_bytes);
77
77
const size_t model_bytes_length = env->GetArrayLength (java_model_bytes);
@@ -82,7 +82,22 @@ Java_com_onnxruntime_example_modeltester_MainActivity_run(JNIEnv* env, jobject t
82
82
config.model_path_or_bytes = model_bytes_span;
83
83
config.num_iterations = num_iterations;
84
84
85
- // TODO handle EP type and EP options
85
+ if (java_execution_provider_type != nullptr ) {
86
+ config.ep .emplace ();
87
+ config.ep ->provider_name = util::JstringToStdString (*env, java_execution_provider_type);
88
+
89
+ if (java_execution_provider_option_names != nullptr &&
90
+ java_execution_provider_option_values != nullptr ) {
91
+ const auto option_names = util::JstringArrayToStdStrings (*env, java_execution_provider_option_names);
92
+ const auto option_values = util::JstringArrayToStdStrings (*env, java_execution_provider_option_values);
93
+ if (option_names.size () != option_values.size ()) {
94
+ throw std::runtime_error (" Execution provider option names and values must have the same size." );
95
+ }
96
+ for (size_t i = 0 ; i < option_names.size (); ++i) {
97
+ config.ep ->provider_options .emplace (option_names[i], option_values[i]);
98
+ }
99
+ }
100
+ }
86
101
87
102
auto result = model_runner::Run (config);
88
103
0 commit comments