diff --git a/.clang-format b/.clang-format
index bea088ea3..c166bab33 100644
--- a/.clang-format
+++ b/.clang-format
@@ -2,6 +2,10 @@
# Defaults for all languages.
BasedOnStyle: Google
-ColumnLimit: 120
+# Setting ColumnLimit to 0 so developer choices about where to break lines are maintained.
+# Developers are responsible for adhering to the 120 character maximum.
+ColumnLimit: 0
+SortIncludes: false
+DerivePointerAlignment: false
...
diff --git a/mobile/examples/model_tester/android/.gitignore b/mobile/examples/model_tester/android/.gitignore
new file mode 100644
index 000000000..aa724b770
--- /dev/null
+++ b/mobile/examples/model_tester/android/.gitignore
@@ -0,0 +1,15 @@
+*.iml
+.gradle
+/local.properties
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
+.cxx
+local.properties
diff --git a/mobile/examples/model_tester/android/app/.gitignore b/mobile/examples/model_tester/android/app/.gitignore
new file mode 100644
index 000000000..42afabfd2
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/build.gradle.kts b/mobile/examples/model_tester/android/app/build.gradle.kts
new file mode 100644
index 000000000..c2dc95cc1
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/build.gradle.kts
@@ -0,0 +1,56 @@
+plugins {
+ id("com.android.application")
+ id("org.jetbrains.kotlin.android")
+}
+
+android {
+ namespace = "com.onnxruntime.example.modeltester"
+ compileSdk = 34
+
+ defaultConfig {
+ applicationId = "com.onnxruntime.example.modeltester"
+ minSdk = 24
+ targetSdk = 34
+ versionCode = 1
+ versionName = "1.0"
+
+ testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
+ }
+
+ buildTypes {
+ release {
+ isMinifyEnabled = false
+ proguardFiles(
+ getDefaultProguardFile("proguard-android-optimize.txt"),
+ "proguard-rules.pro"
+ )
+ }
+ }
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+ externalNativeBuild {
+ cmake {
+ path = file("src/main/cpp/CMakeLists.txt")
+ version = "3.22.1"
+ }
+ }
+ buildFeatures {
+ viewBinding = true
+ }
+ ndkVersion = "28.1.13356709"
+}
+
+dependencies {
+ implementation("androidx.core:core-ktx:1.9.0")
+ implementation("androidx.appcompat:appcompat:1.7.0")
+ implementation("com.google.android.material:material:1.12.0")
+ implementation("androidx.constraintlayout:constraintlayout:2.1.4")
+ testImplementation("junit:junit:4.13.2")
+ androidTestImplementation("androidx.test.ext:junit:1.2.1")
+ androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
+}
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/proguard-rules.pro b/mobile/examples/model_tester/android/app/proguard-rules.pro
new file mode 100644
index 000000000..481bb4348
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/androidTest/java/com/onnxruntime/example/modeltester/ExampleInstrumentedTest.kt b/mobile/examples/model_tester/android/app/src/androidTest/java/com/onnxruntime/example/modeltester/ExampleInstrumentedTest.kt
new file mode 100644
index 000000000..372586fc6
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/androidTest/java/com/onnxruntime/example/modeltester/ExampleInstrumentedTest.kt
@@ -0,0 +1,24 @@
+package com.onnxruntime.example.modeltester
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+ @Test
+ fun useAppContext() {
+ // Context of the app under test.
+ val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+ assertEquals("com.onnxruntime.example.modeltester", appContext.packageName)
+ }
+}
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/AndroidManifest.xml b/mobile/examples/model_tester/android/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..c7ee022ea
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/AndroidManifest.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/cpp/CMakeLists.txt b/mobile/examples/model_tester/android/app/src/main/cpp/CMakeLists.txt
new file mode 100644
index 000000000..45249c17c
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/cpp/CMakeLists.txt
@@ -0,0 +1,51 @@
+# For more information about using CMake with Android Studio, read the
+# documentation: https://d.android.com/studio/projects/add-native-code.html.
+# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
+
+# Sets the minimum CMake version required for this project.
+cmake_minimum_required(VERSION 3.22.1)
+
+# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
+# Since this is the top level CMakeLists.txt, the project name is also accessible
+# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
+# build script scope).
+project("modeltester")
+
+set(CMAKE_CXX_STANDARD 20)
+
+# Creates and names a library, sets it as either STATIC
+# or SHARED, and provides the relative paths to its source code.
+# You can define multiple libraries, and CMake builds them for you.
+# Gradle automatically packages shared libraries with your APK.
+#
+# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
+# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
+# is preferred for the same purpose.
+#
+# In order to load a library into your app from Java/Kotlin, you must call
+# System.loadLibrary() and pass the name of the library defined here;
+# for GameActivity/NativeActivity derived applications, the same library name must be
+# used in the AndroidManifest.xml file.
+add_library(onnxruntime SHARED IMPORTED)
+set_target_properties(onnxruntime PROPERTIES
+ IMPORTED_LOCATION
+ ${CMAKE_SOURCE_DIR}/lib/${ANDROID_ABI}/libonnxruntime.so
+ INTERFACE_INCLUDE_DIRECTORIES
+ ${CMAKE_SOURCE_DIR}/include)
+
+add_library(${CMAKE_PROJECT_NAME} SHARED
+ ${CMAKE_CURRENT_SOURCE_DIR}/native-lib.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../common/include/model_runner.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../common/model_runner.cpp)
+
+target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../common/include)
+
+# Specifies libraries CMake should link to your target library. You
+# can link libraries from various origins, such as libraries defined in this
+# build script, prebuilt third-party libraries, or Android system libraries.
+target_link_libraries(${CMAKE_PROJECT_NAME}
+ # List libraries link to the target library
+ android
+ log
+ onnxruntime)
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/cpp/native-lib.cpp b/mobile/examples/model_tester/android/app/src/main/cpp/native-lib.cpp
new file mode 100644
index 000000000..a592ad486
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/cpp/native-lib.cpp
@@ -0,0 +1,116 @@
+#include
+
+#include
+
+#include
+#include
+#include
+#include
+
+#include "model_runner.h"
+
+namespace util {
+struct JstringUtfCharDeleter {
+ JstringUtfCharDeleter(JNIEnv& env, jstring jstr) : env{env}, jstr{jstr} {}
+
+ void operator()(const char* p) {
+ env.ReleaseStringUTFChars(jstr, p);
+ }
+
+ JNIEnv& env;
+ jstring jstr;
+};
+
+auto MakeUniqueJstringUtfCharPtr(JNIEnv& env, jstring jstr) {
+ const auto* raw_utf_chars = env.GetStringUTFChars(jstr, nullptr);
+ return std::unique_ptr{
+ raw_utf_chars, JstringUtfCharDeleter{env, jstr}};
+}
+
+std::string JstringToStdString(JNIEnv& env, jstring jstr) {
+ auto utf_chars = MakeUniqueJstringUtfCharPtr(env, jstr);
+ return std::string{utf_chars.get()};
+}
+
+std::vector JstringArrayToStdStrings(JNIEnv& env, jobjectArray jobjs) {
+ std::vector strs;
+ const auto java_string_class = env.FindClass("java/lang/String");
+ const auto length = env.GetArrayLength(jobjs);
+ for (jsize i = 0; i < length; ++i) {
+ const auto jobj = env.GetObjectArrayElement(jobjs, i);
+ if (!env.IsInstanceOf(jobj, java_string_class)) {
+ throw std::runtime_error("jobjectArray element is not a string.");
+ }
+ const auto jstr = static_cast(jobj);
+ strs.emplace_back(JstringToStdString(env, jstr));
+ }
+ return strs;
+}
+
+struct JbyteArrayElementsDeleter {
+ JbyteArrayElementsDeleter(JNIEnv& env, jbyteArray array) : env{env}, array{array} {}
+
+ void operator()(jbyte* p) {
+ env.ReleaseByteArrayElements(array, p, 0);
+ }
+
+ JNIEnv& env;
+ jbyteArray array;
+};
+
+auto MakeUniqueJbyteArrayElementsPtr(JNIEnv& env, jbyteArray array) {
+ auto* jbytes_raw = env.GetByteArrayElements(array, nullptr);
+ return std::unique_ptr{
+ jbytes_raw, JbyteArrayElementsDeleter{env, array}};
+}
+} // namespace util
+
+extern "C" JNIEXPORT jstring JNICALL
+Java_com_onnxruntime_example_modeltester_MainActivity_run(JNIEnv* env, jobject thiz,
+ jbyteArray java_model_bytes,
+ jint num_iterations,
+ jstring java_execution_provider_type,
+ jobjectArray java_execution_provider_option_names,
+ jobjectArray java_execution_provider_option_values) {
+ try {
+ auto model_bytes = util::MakeUniqueJbyteArrayElementsPtr(*env, java_model_bytes);
+ const size_t model_bytes_length = env->GetArrayLength(java_model_bytes);
+ auto model_bytes_span = std::span{reinterpret_cast(model_bytes.get()),
+ model_bytes_length};
+
+ auto config = model_runner::RunConfig{};
+ config.model_path_or_bytes = model_bytes_span;
+ config.num_iterations = num_iterations;
+
+ if (java_execution_provider_type != nullptr) {
+ config.ep.emplace();
+ config.ep->provider_name = util::JstringToStdString(*env, java_execution_provider_type);
+
+ if (java_execution_provider_option_names != nullptr &&
+ java_execution_provider_option_values != nullptr) {
+ const auto option_names = util::JstringArrayToStdStrings(*env, java_execution_provider_option_names);
+ const auto option_values = util::JstringArrayToStdStrings(*env, java_execution_provider_option_values);
+ if (option_names.size() != option_values.size()) {
+ throw std::runtime_error("Execution provider option names and values must have the same size.");
+ }
+ for (size_t i = 0; i < option_names.size(); ++i) {
+ config.ep->provider_options.emplace(option_names[i], option_values[i]);
+ }
+ }
+ }
+
+ auto result = model_runner::Run(config);
+
+ auto summary = model_runner::GetRunSummary(config, result);
+
+ return env->NewStringUTF(summary.c_str());
+ } catch (const std::exception& e) {
+ const auto java_exception_class = env->FindClass("java/lang/RuntimeException");
+ env->ThrowNew(java_exception_class, e.what());
+
+ __android_log_print(ANDROID_LOG_ERROR, "com.onnxruntime.example.modeltester",
+ "Error: %s", e.what());
+
+ return nullptr;
+ }
+}
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/java/com/onnxruntime/example/modeltester/MainActivity.kt b/mobile/examples/model_tester/android/app/src/main/java/com/onnxruntime/example/modeltester/MainActivity.kt
new file mode 100644
index 000000000..1f0f64e10
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/java/com/onnxruntime/example/modeltester/MainActivity.kt
@@ -0,0 +1,42 @@
+package com.onnxruntime.example.modeltester
+
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import com.onnxruntime.example.modeltester.databinding.ActivityMainBinding
+
+class MainActivity : AppCompatActivity() {
+
+ private lateinit var binding: ActivityMainBinding
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ binding = ActivityMainBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+
+ val modelResourceId = R.raw.model
+ val modelBytes = resources.openRawResource(modelResourceId).readBytes()
+
+ val summary = run(modelBytes, 10, null, null, null)
+
+ binding.sampleText.text = summary
+ }
+
+ /**
+ * A native method that is implemented by the 'modeltester' native library,
+ * which is packaged with this application.
+ */
+ external fun run(modelBytes: ByteArray,
+ numIterations: Int,
+ executionProviderType: String?,
+ executionProviderOptionNames: Array?,
+ executionProviderOptionValues: Array?,
+ ): String
+
+ companion object {
+ // Used to load the 'modeltester' library on application startup.
+ init {
+ System.loadLibrary("modeltester")
+ }
+ }
+}
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/drawable/ic_launcher_background.xml b/mobile/examples/model_tester/android/app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 000000000..07d5da9cb
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mobile/examples/model_tester/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/mobile/examples/model_tester/android/app/src/main/res/drawable/ic_launcher_foreground.xml
new file mode 100644
index 000000000..2b068d114
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/drawable/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/layout/activity_main.xml b/mobile/examples/model_tester/android/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 000000000..0fdf98529
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/mobile/examples/model_tester/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 000000000..6f3b755bf
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/mobile/examples/model_tester/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 000000000..6f3b755bf
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp
new file mode 100644
index 000000000..c209e78ec
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
new file mode 100644
index 000000000..b2dfe3d1b
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp
new file mode 100644
index 000000000..4f0f1d64e
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
new file mode 100644
index 000000000..62b611da0
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
new file mode 100644
index 000000000..948a3070f
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
new file mode 100644
index 000000000..1b9a6956b
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
new file mode 100644
index 000000000..28d4b77f9
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
new file mode 100644
index 000000000..9287f5083
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
new file mode 100644
index 000000000..aa7d6427e
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
new file mode 100644
index 000000000..9126ae37c
Binary files /dev/null and b/mobile/examples/model_tester/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ
diff --git a/mobile/examples/model_tester/android/app/src/main/res/values-night/themes.xml b/mobile/examples/model_tester/android/app/src/main/res/values-night/themes.xml
new file mode 100644
index 000000000..ae920c975
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/values-night/themes.xml
@@ -0,0 +1,16 @@
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/values/colors.xml b/mobile/examples/model_tester/android/app/src/main/res/values/colors.xml
new file mode 100644
index 000000000..f8c6127d3
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/values/colors.xml
@@ -0,0 +1,10 @@
+
+
+ #FFBB86FC
+ #FF6200EE
+ #FF3700B3
+ #FF03DAC5
+ #FF018786
+ #FF000000
+ #FFFFFFFF
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/values/strings.xml b/mobile/examples/model_tester/android/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..e2bb1c392
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ ModelTester
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/values/themes.xml b/mobile/examples/model_tester/android/app/src/main/res/values/themes.xml
new file mode 100644
index 000000000..d0a5ae978
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/values/themes.xml
@@ -0,0 +1,16 @@
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/xml/backup_rules.xml b/mobile/examples/model_tester/android/app/src/main/res/xml/backup_rules.xml
new file mode 100644
index 000000000..fa0f996d2
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/xml/backup_rules.xml
@@ -0,0 +1,13 @@
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/main/res/xml/data_extraction_rules.xml b/mobile/examples/model_tester/android/app/src/main/res/xml/data_extraction_rules.xml
new file mode 100644
index 000000000..9ee9997b0
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/main/res/xml/data_extraction_rules.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/app/src/test/java/com/onnxruntime/example/modeltester/ExampleUnitTest.kt b/mobile/examples/model_tester/android/app/src/test/java/com/onnxruntime/example/modeltester/ExampleUnitTest.kt
new file mode 100644
index 000000000..f991d87f9
--- /dev/null
+++ b/mobile/examples/model_tester/android/app/src/test/java/com/onnxruntime/example/modeltester/ExampleUnitTest.kt
@@ -0,0 +1,17 @@
+package com.onnxruntime.example.modeltester
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+ @Test
+ fun addition_isCorrect() {
+ assertEquals(4, 2 + 2)
+ }
+}
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/build.gradle.kts b/mobile/examples/model_tester/android/build.gradle.kts
new file mode 100644
index 000000000..6d9d338d9
--- /dev/null
+++ b/mobile/examples/model_tester/android/build.gradle.kts
@@ -0,0 +1,5 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+plugins {
+ id("com.android.application") version "8.1.1" apply false
+ id("org.jetbrains.kotlin.android") version "1.9.0" apply false
+}
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/gradle.properties b/mobile/examples/model_tester/android/gradle.properties
new file mode 100644
index 000000000..3c5031eb7
--- /dev/null
+++ b/mobile/examples/model_tester/android/gradle.properties
@@ -0,0 +1,23 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app's APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Kotlin code style for this project: "official" or "obsolete":
+kotlin.code.style=official
+# Enables namespacing of each library's R class so that its R class includes only the
+# resources declared in the library itself and none from the library's dependencies,
+# thereby reducing the size of the R class for that library
+android.nonTransitiveRClass=true
\ No newline at end of file
diff --git a/mobile/examples/model_tester/android/gradle/wrapper/gradle-wrapper.jar b/mobile/examples/model_tester/android/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..e708b1c02
Binary files /dev/null and b/mobile/examples/model_tester/android/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/mobile/examples/model_tester/android/gradle/wrapper/gradle-wrapper.properties b/mobile/examples/model_tester/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..0eed236f1
--- /dev/null
+++ b/mobile/examples/model_tester/android/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue May 20 11:59:27 PDT 2025
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/mobile/examples/model_tester/android/gradlew b/mobile/examples/model_tester/android/gradlew
new file mode 100755
index 000000000..4f906e0c8
--- /dev/null
+++ b/mobile/examples/model_tester/android/gradlew
@@ -0,0 +1,185 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=`expr $i + 1`
+ done
+ case $i in
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+exec "$JAVACMD" "$@"
diff --git a/mobile/examples/model_tester/android/gradlew.bat b/mobile/examples/model_tester/android/gradlew.bat
new file mode 100644
index 000000000..ac1b06f93
--- /dev/null
+++ b/mobile/examples/model_tester/android/gradlew.bat
@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/mobile/examples/model_tester/android/readme.md b/mobile/examples/model_tester/android/readme.md
new file mode 100644
index 000000000..b0acaba5e
--- /dev/null
+++ b/mobile/examples/model_tester/android/readme.md
@@ -0,0 +1,20 @@
+setup instructions:
+
+1. manually set up native onnxruntime libraries. unzip onnxruntime-android.aar, then put shared libraries and headers into these directories:
+
+under mobile/examples/model_tester/android/app/src/main/cpp:
+include/onnxruntime_session_options_config_keys.h
+include/nnapi_provider_factory.h
+include/cpu_provider_factory.h
+include/onnxruntime_lite_custom_op.h
+include/onnxruntime_run_options_config_keys.h
+include/onnxruntime_float16.h
+include/onnxruntime_cxx_inline.h
+include/onnxruntime_cxx_api.h
+include/onnxruntime_c_api.h
+lib/armeabi-v7a/libonnxruntime.so
+lib/x86/libonnxruntime.so
+lib/arm64-v8a/libonnxruntime.so
+lib/x86_64/libonnxruntime.so
+
+2. copy an onnx model file to mobile/examples/model_tester/android/app/src/main/res/raw/model.onnx
diff --git a/mobile/examples/model_tester/android/settings.gradle.kts b/mobile/examples/model_tester/android/settings.gradle.kts
new file mode 100644
index 000000000..132179e88
--- /dev/null
+++ b/mobile/examples/model_tester/android/settings.gradle.kts
@@ -0,0 +1,17 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+
+rootProject.name = "ModelTester"
+include(":app")
diff --git a/mobile/examples/model_tester/common/include/model_runner.h b/mobile/examples/model_tester/common/include/model_runner.h
new file mode 100644
index 000000000..151519198
--- /dev/null
+++ b/mobile/examples/model_tester/common/include/model_runner.h
@@ -0,0 +1,56 @@
+#pragma once
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace model_runner {
+
+using Clock = std::chrono::steady_clock;
+using Duration = Clock::duration;
+
+struct RunConfig {
+ using ModelPathOrBytes = std::variant>;
+
+ // Path or bytes of the model to run.
+ ModelPathOrBytes model_path_or_bytes{};
+
+ // Whether to run a warmup iteration before running the measured (timed) iterations.
+ bool run_warmup_iteration{true};
+
+ // Number of iterations to run.
+ size_t num_iterations{10};
+
+ // Configuration for an Execution Provider (EP).
+ struct EpConfig {
+ std::string provider_name{};
+ std::unordered_map provider_options{};
+ };
+
+ // Specifies the EP to use in the session.
+ std::optional ep{};
+
+ // Specifies the onnxruntime log level.
+ std::optional log_level{};
+};
+
+struct RunResult {
+ // Time taken to load the model.
+ Duration load_duration;
+
+ // Times taken to run the model.
+ std::vector run_durations;
+};
+
+RunResult Run(const RunConfig& run_config);
+
+std::string GetRunSummary(const RunConfig& run_config, const RunResult& run_result);
+
+} // namespace model_runner
diff --git a/mobile/examples/model_tester/common/model_runner.cpp b/mobile/examples/model_tester/common/model_runner.cpp
new file mode 100644
index 000000000..e15387ea2
--- /dev/null
+++ b/mobile/examples/model_tester/common/model_runner.cpp
@@ -0,0 +1,261 @@
+#include "model_runner.h"
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "onnxruntime_cxx_api.h"
+
+namespace model_runner {
+
+namespace {
+
+size_t GetDataTypeSizeInBytes(ONNXTensorElementDataType data_type) {
+ switch (data_type) {
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FN:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FNUZ:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E5M2:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E5M2FNUZ:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8:
+ return 1;
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16:
+ return 2;
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32:
+ return 4;
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64:
+ case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64:
+ return 8;
+ default:
+ throw std::invalid_argument(std::format("unsupported tensor data type: {}", static_cast(data_type)));
+ }
+}
+
+void FillTensorWithZeroes(Ort::Value& value) {
+ const auto tensor_info = value.GetTensorTypeAndShapeInfo();
+ const auto data_type = tensor_info.GetElementType();
+ const auto num_elements = tensor_info.GetElementCount();
+ const auto data_type_size_in_bytes = GetDataTypeSizeInBytes(data_type);
+ const auto data_size_in_bytes = num_elements * data_type_size_in_bytes;
+
+ std::byte* data = static_cast(value.GetTensorMutableRawData());
+ std::fill(data, data + data_size_in_bytes, std::byte{0});
+}
+
+std::vector GetModelInputValues(const Ort::Session& session) {
+ const auto num_inputs = session.GetInputCount();
+
+ std::vector input_values{};
+ input_values.reserve(num_inputs);
+
+ Ort::AllocatorWithDefaultOptions allocator{};
+
+ for (size_t i = 0; i < num_inputs; ++i) {
+ auto type_info = session.GetInputTypeInfo(i);
+ auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
+
+ auto tensor_shape = tensor_info.GetShape();
+ // make this a static shape
+ for (auto& dim : tensor_shape) {
+ if (dim == -1) {
+ dim = 1;
+ }
+ }
+
+ const auto tensor_data_type = tensor_info.GetElementType();
+
+ auto value = Ort::Value::CreateTensor(allocator, tensor_shape.data(), tensor_shape.size(), tensor_data_type);
+
+ FillTensorWithZeroes(value);
+
+ input_values.emplace_back(std::move(value));
+ }
+
+ return input_values;
+}
+
+std::vector GetModelInputOrOutputNames(const Ort::Session& session, bool is_input) {
+ const auto num_inputs_or_outputs = is_input ? session.GetInputCount() : session.GetOutputCount();
+
+ std::vector names{};
+ names.reserve(num_inputs_or_outputs);
+
+ auto allocator = Ort::AllocatorWithDefaultOptions{};
+ for (size_t i = 0; i < num_inputs_or_outputs; ++i) {
+ auto name = is_input ? session.GetInputNameAllocated(i, allocator)
+ : session.GetOutputNameAllocated(i, allocator);
+ names.emplace_back(name.get());
+ }
+
+ return names;
+}
+
+std::vector GetModelInputNames(const Ort::Session& session) {
+ return GetModelInputOrOutputNames(session, /* is_input */ true);
+}
+
+std::vector GetModelOutputNames(const Ort::Session& session) {
+ return GetModelInputOrOutputNames(session, /* is_input */ false);
+}
+
+std::vector GetCstrs(std::span strs) {
+ std::vector cstrs{};
+ cstrs.reserve(strs.size());
+ std::transform(strs.begin(), strs.end(), std::back_inserter(cstrs),
+ [](const std::string& str) { return str.c_str(); });
+ return cstrs;
+}
+
+class Timer {
+ public:
+ Timer() { Reset(); }
+
+ void Reset() { start_ = Clock::now(); }
+
+ Duration Elapsed() const { return Clock::now() - start_; }
+
+ private:
+ Clock::time_point start_;
+};
+
+struct RunResultStats {
+ using DurationFp = std::chrono::duration;
+
+ size_t n;
+ DurationFp average;
+ Duration min, max;
+ Duration p50, p90, p99;
+};
+
+RunResultStats ComputeRunResultStats(const RunResult& run_result) {
+ using DurationFp = RunResultStats::DurationFp;
+
+ const auto& run_durations = run_result.run_durations;
+
+ RunResultStats stats{};
+ const auto n = run_durations.size();
+ stats.n = n;
+ if (n > 0) {
+ const auto total_run_duration = std::accumulate(run_durations.begin(), run_durations.end(),
+ DurationFp{0.0f});
+ stats.average = DurationFp{total_run_duration.count() / n};
+
+ auto sorted_run_durations = run_durations;
+ std::sort(sorted_run_durations.begin(), sorted_run_durations.end());
+ stats.min = sorted_run_durations.front();
+ stats.max = sorted_run_durations.back();
+ stats.p50 = sorted_run_durations[static_cast(0.5f * n)];
+ stats.p90 = sorted_run_durations[static_cast(0.9f * n)];
+ stats.p99 = sorted_run_durations[static_cast(0.99f * n)];
+ }
+
+ return stats;
+}
+
+} // namespace
+
+RunResult Run(const RunConfig& run_config) {
+ RunResult run_result{};
+
+ auto env = Ort::Env{};
+
+ if (run_config.log_level.has_value()) {
+ env.UpdateEnvWithCustomLogLevel(static_cast(*run_config.log_level));
+ }
+
+ auto session_options = Ort::SessionOptions{};
+
+ if (const auto& ep_config = run_config.ep; ep_config.has_value()) {
+ session_options.AppendExecutionProvider(ep_config->provider_name, ep_config->provider_options);
+ }
+
+ Timer timer{};
+
+ auto session = Ort::Session{nullptr};
+ if (std::holds_alternative(run_config.model_path_or_bytes)) {
+ const auto& model_path = std::get(run_config.model_path_or_bytes);
+ timer.Reset();
+ session = Ort::Session{env, model_path.c_str(), session_options};
+ run_result.load_duration = timer.Elapsed();
+ } else {
+ const auto& model_bytes = std::get>(run_config.model_path_or_bytes);
+ timer.Reset();
+ session = Ort::Session{env, model_bytes.data(), model_bytes.size(), session_options};
+ run_result.load_duration = timer.Elapsed();
+ }
+
+ auto input_names = GetModelInputNames(session);
+ auto input_name_cstrs = GetCstrs(input_names);
+
+ auto input_values = GetModelInputValues(session);
+
+ auto output_names = GetModelOutputNames(session);
+ auto output_name_cstrs = GetCstrs(output_names);
+
+ auto run_options = Ort::RunOptions{};
+
+ run_result.run_durations.reserve(run_config.num_iterations);
+
+ // warmup
+ if (run_config.run_warmup_iteration) {
+ auto outputs = session.Run(run_options,
+ input_name_cstrs.data(), input_values.data(), input_values.size(),
+ output_name_cstrs.data(), output_name_cstrs.size());
+ }
+
+ // measure runs
+ for (size_t i = 0; i < run_config.num_iterations; ++i) {
+ timer.Reset();
+ auto outputs = session.Run(run_options,
+ input_name_cstrs.data(), input_values.data(), input_values.size(),
+ output_name_cstrs.data(), output_name_cstrs.size());
+ run_result.run_durations.push_back(timer.Elapsed());
+ }
+
+ return run_result;
+}
+
+std::string GetRunSummary(const RunConfig& /*run_config*/, const RunResult& run_result) {
+ auto to_display_duration = [](std::chrono::duration d) {
+ using DisplayPeriod = std::chrono::microseconds::period;
+ using DisplayDuration = std::chrono::duration;
+ return std::chrono::duration_cast(d);
+ };
+
+ const auto stats = ComputeRunResultStats(run_result);
+
+ const auto summary = std::format(
+ "Load time: {}\n"
+ "N (number of runs): {}\n"
+ "Latency\n"
+ " avg: {}\n"
+ " p50: {}\n"
+ " p90: {}\n"
+ " p99: {}\n"
+ " min: {}\n"
+ " max: {}\n",
+ to_display_duration(run_result.load_duration),
+ stats.n,
+ to_display_duration(stats.average),
+ to_display_duration(stats.p50),
+ to_display_duration(stats.p90),
+ to_display_duration(stats.p99),
+ to_display_duration(stats.min),
+ to_display_duration(stats.max));
+
+ return summary;
+}
+
+} // namespace model_runner
diff --git a/mobile/examples/model_tester/ios/ModelRunner/model_runner_objc_wrapper.h b/mobile/examples/model_tester/ios/ModelRunner/model_runner_objc_wrapper.h
new file mode 100644
index 000000000..6adfd724a
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelRunner/model_runner_objc_wrapper.h
@@ -0,0 +1,29 @@
+#import
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * This class is an Objective-C wrapper around the C++ `model_runner::RunConfig` structure.
+ */
+@interface ModelRunnerRunConfig : NSObject
+
+- (void)setModelPath:(NSString*)modelPath;
+
+- (void)setNumIterations:(NSUInteger)numIterations;
+
+- (void)setExecutionProvider:(NSString*)providerName
+ options:(nullable NSDictionary*)providerOptions;
+
+@end
+
+/**
+ * This class is an Objective-C wrapper around the C++ model runner functions.
+ */
+@interface ModelRunner : NSObject
+
++ (nullable NSString*)runWithConfig:(ModelRunnerRunConfig*)config
+ error:(NSError**)error NS_SWIFT_NAME(run(config:));
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/mobile/examples/model_tester/ios/ModelRunner/model_runner_objc_wrapper.mm b/mobile/examples/model_tester/ios/ModelRunner/model_runner_objc_wrapper.mm
new file mode 100644
index 000000000..ab5e3a6d5
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelRunner/model_runner_objc_wrapper.mm
@@ -0,0 +1,72 @@
+#import "model_runner_objc_wrapper.h"
+
+#include "model_runner.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ModelRunnerRunConfig ()
+
+- (const model_runner::RunConfig&)cppRunConfig;
+
+@end
+
+@implementation ModelRunnerRunConfig {
+ model_runner::RunConfig _runConfig;
+}
+
+- (void)setModelPath:(nonnull NSString*)modelPath {
+ _runConfig.model_path_or_bytes = std::string{modelPath.UTF8String};
+}
+
+- (void)setNumIterations:(NSUInteger)numIterations {
+ _runConfig.num_iterations = static_cast(numIterations);
+}
+
+- (void)setExecutionProvider:(NSString*)providerName
+ options:(nullable NSDictionary*)providerOptions {
+ model_runner::RunConfig::EpConfig ep_config{};
+ ep_config.provider_name = providerName.UTF8String;
+ if (providerOptions != nil) {
+ for (NSString* optionName in providerOptions) {
+ NSString* optionValue = providerOptions[optionName];
+ ep_config.provider_options.emplace(optionName.UTF8String,
+ optionValue.UTF8String);
+ }
+ }
+ _runConfig.ep = std::move(ep_config);
+}
+
+- (const model_runner::RunConfig&)cppRunConfig {
+ return _runConfig;
+}
+
+@end
+
+@implementation ModelRunner
+
++ (nullable NSString*)runWithConfig:(ModelRunnerRunConfig*)objcConfig
+ error:(NSError**)error {
+ try {
+ const auto& config = [objcConfig cppRunConfig];
+
+ auto result = model_runner::Run(config);
+
+ auto summary = model_runner::GetRunSummary(config, result);
+
+ return [NSString stringWithUTF8String:summary.c_str()];
+ } catch (const std::exception& e) {
+ if (error) {
+ NSString* description = [NSString stringWithCString:e.what()
+ encoding:NSUTF8StringEncoding];
+
+ *error = [NSError errorWithDomain:@"ModelRunner"
+ code:0
+ userInfo:@{NSLocalizedDescriptionKey : description}];
+ }
+ return nil;
+ }
+}
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/mobile/examples/model_tester/ios/ModelTester-Bridging-Header.h b/mobile/examples/model_tester/ios/ModelTester-Bridging-Header.h
new file mode 100644
index 000000000..abebb0ec9
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester-Bridging-Header.h
@@ -0,0 +1,5 @@
+//
+// Use this file to import your target's public headers that you would like to expose to Swift.
+//
+
+#import "model_runner_objc_wrapper.h"
diff --git a/mobile/examples/model_tester/ios/ModelTester.xcodeproj/project.pbxproj b/mobile/examples/model_tester/ios/ModelTester.xcodeproj/project.pbxproj
new file mode 100644
index 000000000..4d5a142fd
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester.xcodeproj/project.pbxproj
@@ -0,0 +1,610 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 77;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 2E163DAB2DCBE38900B4ED4A /* model_runner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E163DAA2DCBE38900B4ED4A /* model_runner.cpp */; };
+ 2E163DD22DCBEC9F00B4ED4A /* model_runner_objc_wrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E163DD12DCBEC9200B4ED4A /* model_runner_objc_wrapper.mm */; };
+ 2E5D16F52DCD83DE0097F05B /* model.onnx in Resources */ = {isa = PBXBuildFile; fileRef = 2E5D16F42DCD83DE0097F05B /* model.onnx */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+ 2E163D6D2DCBDF6B00B4ED4A /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 2E163D542DCBDF6400B4ED4A /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 2E163D5B2DCBDF6400B4ED4A;
+ remoteInfo = ModelTester;
+ };
+ 2E163D772DCBDF6B00B4ED4A /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 2E163D542DCBDF6400B4ED4A /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 2E163D5B2DCBDF6400B4ED4A;
+ remoteInfo = ModelTester;
+ };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXFileReference section */
+ 2E163D5C2DCBDF6400B4ED4A /* ModelTester.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ModelTester.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 2E163D6C2DCBDF6B00B4ED4A /* ModelTesterTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ModelTesterTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
+ 2E163D762DCBDF6B00B4ED4A /* ModelTesterUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ModelTesterUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
+ 2E163DAA2DCBE38900B4ED4A /* model_runner.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = model_runner.cpp; path = ../common/model_runner.cpp; sourceTree = SOURCE_ROOT; };
+ 2E163DAC2DCBE3AE00B4ED4A /* model_runner.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = model_runner.h; path = ../common/include/model_runner.h; sourceTree = SOURCE_ROOT; };
+ 2E163DCF2DCBE98F00B4ED4A /* ModelTester-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ModelTester-Bridging-Header.h"; sourceTree = ""; };
+ 2E163DD02DCBEB0900B4ED4A /* model_runner_objc_wrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = model_runner_objc_wrapper.h; sourceTree = ""; };
+ 2E163DD12DCBEC9200B4ED4A /* model_runner_objc_wrapper.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = model_runner_objc_wrapper.mm; sourceTree = ""; };
+ 2E5D16F42DCD83DE0097F05B /* model.onnx */ = {isa = PBXFileReference; lastKnownFileType = file; path = model.onnx; sourceTree = ""; };
+/* End PBXFileReference section */
+
+/* Begin PBXFileSystemSynchronizedRootGroup section */
+ 2E163D5E2DCBDF6400B4ED4A /* ModelTester */ = {
+ isa = PBXFileSystemSynchronizedRootGroup;
+ exceptions = (
+ );
+ path = ModelTester;
+ sourceTree = "";
+ };
+ 2E163D6F2DCBDF6B00B4ED4A /* ModelTesterTests */ = {
+ isa = PBXFileSystemSynchronizedRootGroup;
+ exceptions = (
+ );
+ path = ModelTesterTests;
+ sourceTree = "";
+ };
+ 2E163D792DCBDF6B00B4ED4A /* ModelTesterUITests */ = {
+ isa = PBXFileSystemSynchronizedRootGroup;
+ exceptions = (
+ );
+ path = ModelTesterUITests;
+ sourceTree = "";
+ };
+/* End PBXFileSystemSynchronizedRootGroup section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 2E163D592DCBDF6400B4ED4A /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 2E163D692DCBDF6B00B4ED4A /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 2E163D732DCBDF6B00B4ED4A /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 2E163D532DCBDF6400B4ED4A = {
+ isa = PBXGroup;
+ children = (
+ 2E163DD72DCC23E500B4ED4A /* model */,
+ 2E163DAD2DCBE3BC00B4ED4A /* ModelRunner */,
+ 2E163D5E2DCBDF6400B4ED4A /* ModelTester */,
+ 2E163D6F2DCBDF6B00B4ED4A /* ModelTesterTests */,
+ 2E163D792DCBDF6B00B4ED4A /* ModelTesterUITests */,
+ 2E163D5D2DCBDF6400B4ED4A /* Products */,
+ 78FD58CC2213875ECC5EDF6B /* Pods */,
+ 2E163DCF2DCBE98F00B4ED4A /* ModelTester-Bridging-Header.h */,
+ );
+ sourceTree = "";
+ };
+ 2E163D5D2DCBDF6400B4ED4A /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 2E163D5C2DCBDF6400B4ED4A /* ModelTester.app */,
+ 2E163D6C2DCBDF6B00B4ED4A /* ModelTesterTests.xctest */,
+ 2E163D762DCBDF6B00B4ED4A /* ModelTesterUITests.xctest */,
+ );
+ name = Products;
+ sourceTree = "";
+ };
+ 2E163DAD2DCBE3BC00B4ED4A /* ModelRunner */ = {
+ isa = PBXGroup;
+ children = (
+ 2E163DD12DCBEC9200B4ED4A /* model_runner_objc_wrapper.mm */,
+ 2E163DD02DCBEB0900B4ED4A /* model_runner_objc_wrapper.h */,
+ 2E163DAC2DCBE3AE00B4ED4A /* model_runner.h */,
+ 2E163DAA2DCBE38900B4ED4A /* model_runner.cpp */,
+ );
+ path = ModelRunner;
+ sourceTree = "";
+ };
+ 2E163DD72DCC23E500B4ED4A /* model */ = {
+ isa = PBXGroup;
+ children = (
+ 2E5D16F42DCD83DE0097F05B /* model.onnx */,
+ );
+ path = model;
+ sourceTree = "";
+ };
+ 78FD58CC2213875ECC5EDF6B /* Pods */ = {
+ isa = PBXGroup;
+ children = (
+ );
+ path = Pods;
+ sourceTree = "";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 2E163D5B2DCBDF6400B4ED4A /* ModelTester */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 2E163D802DCBDF6B00B4ED4A /* Build configuration list for PBXNativeTarget "ModelTester" */;
+ buildPhases = (
+ 2E163D582DCBDF6400B4ED4A /* Sources */,
+ 2E163D592DCBDF6400B4ED4A /* Frameworks */,
+ 2E163D5A2DCBDF6400B4ED4A /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ fileSystemSynchronizedGroups = (
+ 2E163D5E2DCBDF6400B4ED4A /* ModelTester */,
+ );
+ name = ModelTester;
+ productName = ModelTester;
+ productReference = 2E163D5C2DCBDF6400B4ED4A /* ModelTester.app */;
+ productType = "com.apple.product-type.application";
+ };
+ 2E163D6B2DCBDF6B00B4ED4A /* ModelTesterTests */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 2E163D832DCBDF6B00B4ED4A /* Build configuration list for PBXNativeTarget "ModelTesterTests" */;
+ buildPhases = (
+ 2E163D682DCBDF6B00B4ED4A /* Sources */,
+ 2E163D692DCBDF6B00B4ED4A /* Frameworks */,
+ 2E163D6A2DCBDF6B00B4ED4A /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ 2E163D6E2DCBDF6B00B4ED4A /* PBXTargetDependency */,
+ );
+ fileSystemSynchronizedGroups = (
+ 2E163D6F2DCBDF6B00B4ED4A /* ModelTesterTests */,
+ );
+ name = ModelTesterTests;
+ productName = ModelTesterTests;
+ productReference = 2E163D6C2DCBDF6B00B4ED4A /* ModelTesterTests.xctest */;
+ productType = "com.apple.product-type.bundle.unit-test";
+ };
+ 2E163D752DCBDF6B00B4ED4A /* ModelTesterUITests */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 2E163D862DCBDF6B00B4ED4A /* Build configuration list for PBXNativeTarget "ModelTesterUITests" */;
+ buildPhases = (
+ 2E163D722DCBDF6B00B4ED4A /* Sources */,
+ 2E163D732DCBDF6B00B4ED4A /* Frameworks */,
+ 2E163D742DCBDF6B00B4ED4A /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ 2E163D782DCBDF6B00B4ED4A /* PBXTargetDependency */,
+ );
+ fileSystemSynchronizedGroups = (
+ 2E163D792DCBDF6B00B4ED4A /* ModelTesterUITests */,
+ );
+ name = ModelTesterUITests;
+ productName = ModelTesterUITests;
+ productReference = 2E163D762DCBDF6B00B4ED4A /* ModelTesterUITests.xctest */;
+ productType = "com.apple.product-type.bundle.ui-testing";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 2E163D542DCBDF6400B4ED4A /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ BuildIndependentTargetsInParallel = 1;
+ LastSwiftUpdateCheck = 1600;
+ LastUpgradeCheck = 1600;
+ TargetAttributes = {
+ 2E163D5B2DCBDF6400B4ED4A = {
+ CreatedOnToolsVersion = 16.0;
+ LastSwiftMigration = 1600;
+ };
+ 2E163D6B2DCBDF6B00B4ED4A = {
+ CreatedOnToolsVersion = 16.0;
+ TestTargetID = 2E163D5B2DCBDF6400B4ED4A;
+ };
+ 2E163D752DCBDF6B00B4ED4A = {
+ CreatedOnToolsVersion = 16.0;
+ TestTargetID = 2E163D5B2DCBDF6400B4ED4A;
+ };
+ };
+ };
+ buildConfigurationList = 2E163D572DCBDF6400B4ED4A /* Build configuration list for PBXProject "ModelTester" */;
+ developmentRegion = en;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = 2E163D532DCBDF6400B4ED4A;
+ minimizedProjectReferenceProxies = 1;
+ preferredProjectObjectVersion = 77;
+ productRefGroup = 2E163D5D2DCBDF6400B4ED4A /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 2E163D5B2DCBDF6400B4ED4A /* ModelTester */,
+ 2E163D6B2DCBDF6B00B4ED4A /* ModelTesterTests */,
+ 2E163D752DCBDF6B00B4ED4A /* ModelTesterUITests */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 2E163D5A2DCBDF6400B4ED4A /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 2E5D16F52DCD83DE0097F05B /* model.onnx in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 2E163D6A2DCBDF6B00B4ED4A /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 2E163D742DCBDF6B00B4ED4A /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 2E163D582DCBDF6400B4ED4A /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 2E163DAB2DCBE38900B4ED4A /* model_runner.cpp in Sources */,
+ 2E163DD22DCBEC9F00B4ED4A /* model_runner_objc_wrapper.mm in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 2E163D682DCBDF6B00B4ED4A /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 2E163D722DCBDF6B00B4ED4A /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+ 2E163D6E2DCBDF6B00B4ED4A /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 2E163D5B2DCBDF6400B4ED4A /* ModelTester */;
+ targetProxy = 2E163D6D2DCBDF6B00B4ED4A /* PBXContainerItemProxy */;
+ };
+ 2E163D782DCBDF6B00B4ED4A /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 2E163D5B2DCBDF6400B4ED4A /* ModelTester */;
+ targetProxy = 2E163D772DCBDF6B00B4ED4A /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
+/* Begin XCBuildConfiguration section */
+ 2E163D7E2DCBDF6B00B4ED4A /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_ENABLE_OBJC_WEAK = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ ENABLE_USER_SCRIPT_SANDBOXING = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu17;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 18.0;
+ LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
+ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+ MTL_FAST_MATH = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = iphoneos;
+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ };
+ name = Debug;
+ };
+ 2E163D7F2DCBDF6B00B4ED4A /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_ENABLE_OBJC_WEAK = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_USER_SCRIPT_SANDBOXING = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu17;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 18.0;
+ LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
+ MTL_ENABLE_DEBUG_INFO = NO;
+ MTL_FAST_MATH = YES;
+ SDKROOT = iphoneos;
+ SWIFT_COMPILATION_MODE = wholemodule;
+ VALIDATE_PRODUCT = YES;
+ };
+ name = Release;
+ };
+ 2E163D812DCBDF6B00B4ED4A /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
+ CLANG_ENABLE_MODULES = YES;
+ CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 1;
+ DEVELOPMENT_ASSET_PATHS = "\"ModelTester/Preview Content\"";
+ DEVELOPMENT_TEAM = UBF8T346G9;
+ ENABLE_PREVIEWS = YES;
+ GENERATE_INFOPLIST_FILE = YES;
+ INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
+ INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
+ INFOPLIST_KEY_UILaunchScreen_Generation = YES;
+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
+ MARKETING_VERSION = 1.0;
+ PRODUCT_BUNDLE_IDENTIFIER = com.onnxruntime.example.ModelTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_EMIT_LOC_STRINGS = YES;
+ SWIFT_OBJC_BRIDGING_HEADER = "ModelTester-Bridging-Header.h";
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ 2E163D822DCBDF6B00B4ED4A /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
+ CLANG_ENABLE_MODULES = YES;
+ CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 1;
+ DEVELOPMENT_ASSET_PATHS = "\"ModelTester/Preview Content\"";
+ DEVELOPMENT_TEAM = UBF8T346G9;
+ ENABLE_PREVIEWS = YES;
+ GENERATE_INFOPLIST_FILE = YES;
+ INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
+ INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
+ INFOPLIST_KEY_UILaunchScreen_Generation = YES;
+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
+ MARKETING_VERSION = 1.0;
+ PRODUCT_BUNDLE_IDENTIFIER = com.onnxruntime.example.ModelTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_EMIT_LOC_STRINGS = YES;
+ SWIFT_OBJC_BRIDGING_HEADER = "ModelTester-Bridging-Header.h";
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Release;
+ };
+ 2E163D842DCBDF6B00B4ED4A /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUNDLE_LOADER = "$(TEST_HOST)";
+ CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 1;
+ GENERATE_INFOPLIST_FILE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 18.0;
+ MARKETING_VERSION = 1.0;
+ PRODUCT_BUNDLE_IDENTIFIER = com.onnxruntime.example.ModelTesterTests;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_EMIT_LOC_STRINGS = NO;
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ModelTester.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/ModelTester";
+ };
+ name = Debug;
+ };
+ 2E163D852DCBDF6B00B4ED4A /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUNDLE_LOADER = "$(TEST_HOST)";
+ CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 1;
+ GENERATE_INFOPLIST_FILE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 18.0;
+ MARKETING_VERSION = 1.0;
+ PRODUCT_BUNDLE_IDENTIFIER = com.onnxruntime.example.ModelTesterTests;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_EMIT_LOC_STRINGS = NO;
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ModelTester.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/ModelTester";
+ };
+ name = Release;
+ };
+ 2E163D872DCBDF6B00B4ED4A /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 1;
+ GENERATE_INFOPLIST_FILE = YES;
+ MARKETING_VERSION = 1.0;
+ PRODUCT_BUNDLE_IDENTIFIER = com.onnxruntime.example.ModelTesterUITests;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_EMIT_LOC_STRINGS = NO;
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ TEST_TARGET_NAME = ModelTester;
+ };
+ name = Debug;
+ };
+ 2E163D882DCBDF6B00B4ED4A /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 1;
+ GENERATE_INFOPLIST_FILE = YES;
+ MARKETING_VERSION = 1.0;
+ PRODUCT_BUNDLE_IDENTIFIER = com.onnxruntime.example.ModelTesterUITests;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_EMIT_LOC_STRINGS = NO;
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ TEST_TARGET_NAME = ModelTester;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 2E163D572DCBDF6400B4ED4A /* Build configuration list for PBXProject "ModelTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 2E163D7E2DCBDF6B00B4ED4A /* Debug */,
+ 2E163D7F2DCBDF6B00B4ED4A /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 2E163D802DCBDF6B00B4ED4A /* Build configuration list for PBXNativeTarget "ModelTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 2E163D812DCBDF6B00B4ED4A /* Debug */,
+ 2E163D822DCBDF6B00B4ED4A /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 2E163D832DCBDF6B00B4ED4A /* Build configuration list for PBXNativeTarget "ModelTesterTests" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 2E163D842DCBDF6B00B4ED4A /* Debug */,
+ 2E163D852DCBDF6B00B4ED4A /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 2E163D862DCBDF6B00B4ED4A /* Build configuration list for PBXNativeTarget "ModelTesterUITests" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 2E163D872DCBDF6B00B4ED4A /* Debug */,
+ 2E163D882DCBDF6B00B4ED4A /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 2E163D542DCBDF6400B4ED4A /* Project object */;
+}
diff --git a/mobile/examples/model_tester/ios/ModelTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/mobile/examples/model_tester/ios/ModelTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 000000000..919434a62
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/AccentColor.colorset/Contents.json b/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/AccentColor.colorset/Contents.json
new file mode 100644
index 000000000..eb8789700
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/AccentColor.colorset/Contents.json
@@ -0,0 +1,11 @@
+{
+ "colors" : [
+ {
+ "idiom" : "universal"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
diff --git a/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/AppIcon.appiconset/Contents.json b/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 000000000..230588010
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,35 @@
+{
+ "images" : [
+ {
+ "idiom" : "universal",
+ "platform" : "ios",
+ "size" : "1024x1024"
+ },
+ {
+ "appearances" : [
+ {
+ "appearance" : "luminosity",
+ "value" : "dark"
+ }
+ ],
+ "idiom" : "universal",
+ "platform" : "ios",
+ "size" : "1024x1024"
+ },
+ {
+ "appearances" : [
+ {
+ "appearance" : "luminosity",
+ "value" : "tinted"
+ }
+ ],
+ "idiom" : "universal",
+ "platform" : "ios",
+ "size" : "1024x1024"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
diff --git a/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/Contents.json b/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/Contents.json
new file mode 100644
index 000000000..73c00596a
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester/Assets.xcassets/Contents.json
@@ -0,0 +1,6 @@
+{
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
diff --git a/mobile/examples/model_tester/ios/ModelTester/ContentView.swift b/mobile/examples/model_tester/ios/ModelTester/ContentView.swift
new file mode 100644
index 000000000..518aa3286
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester/ContentView.swift
@@ -0,0 +1,118 @@
+import SwiftUI
+
+enum ModelTesterError: Error {
+ case runtimeError(msg: String)
+}
+
+enum ExecutionProviderType: String, CaseIterable, Identifiable {
+ case cpu = "CPU"
+ case coreml = "CoreML"
+
+ var id: Self { self }
+}
+
+struct ContentView: View {
+ enum Field: Hashable {
+ case numIterations
+ case executionProviderType
+ case executionProviderOptionsText
+ }
+
+ @State private var runResultMessage: String = ""
+ @State private var isRunning: Bool = false
+ @State private var numIterations: UInt = 10
+ @State private var executionProviderType: ExecutionProviderType = .cpu
+ @State private var executionProviderOptionsText: String = ""
+ @FocusState private var focusedField: Field?
+
+ private func parseExecutionProviderOptionsText() throws -> [String: String] {
+ let executionProviderOptions =
+ try executionProviderOptionsText
+ .components(separatedBy: "\n")
+ .reduce(
+ into: [String: String](),
+ { options, line in
+ guard !line.isEmpty else {
+ return
+ }
+ let nameAndValue = line.split(separator: ":", maxSplits: 2)
+ guard nameAndValue.count == 2 else {
+ throw ModelTesterError.runtimeError(msg: "Failed to parse provider option: '\(line)'")
+ }
+ options[String(nameAndValue[0])] = String(nameAndValue[1])
+ })
+
+ return executionProviderOptions
+ }
+
+ private func run() {
+ isRunning = true
+ focusedField = nil
+
+ DispatchQueue.global().async {
+ var output: String
+ do {
+ guard let modelPath = Bundle.main.path(forResource: "model", ofType: "onnx") else {
+ throw ModelTesterError.runtimeError(msg: "Failed to find model file path.")
+ }
+
+ let config = ModelRunnerRunConfig()
+ config.setModelPath(modelPath)
+ config.setNumIterations(numIterations)
+
+ if executionProviderType != .cpu {
+ let executionProviderOptions = try parseExecutionProviderOptionsText()
+
+ print("Execution provider type: \(executionProviderType)")
+ print("Execution provider options: \(executionProviderOptions)")
+ config.setExecutionProvider(executionProviderType.rawValue, options: executionProviderOptions)
+ }
+
+ output = try ModelRunner.run(config: config)
+ } catch ModelTesterError.runtimeError(let msg) {
+ output = "Error: \(msg)"
+ } catch {
+ output = "Error: \(error)"
+ }
+
+ print(output)
+ runResultMessage = output
+ isRunning = false
+ }
+ }
+
+ var body: some View {
+ Form {
+ Text("Iterations")
+ TextField(
+ "", value: $numIterations,
+ format: IntegerFormatStyle.number
+ ).keyboardType(.numberPad)
+ .focused($focusedField, equals: .numIterations)
+
+ Picker("Execution provider type", selection: $executionProviderType) {
+ ForEach(ExecutionProviderType.allCases) { epType in
+ Text(epType.rawValue).tag(epType)
+ }
+ }.focused($focusedField, equals: .executionProviderType)
+
+ if executionProviderType != .cpu {
+ Text("Execution provider options")
+ Text("The expected format is 'name:value', one per line")
+ .font(.caption)
+ TextEditor(text: $executionProviderOptionsText)
+ .focused($focusedField, equals: .executionProviderOptionsText)
+ }
+
+ Button(action: run) { Text("Run") }
+ .disabled(isRunning)
+
+ Text(runResultMessage)
+ .font(.body.monospaced())
+ }
+ }
+}
+
+#Preview{
+ ContentView()
+}
diff --git a/mobile/examples/model_tester/ios/ModelTester/ModelTesterApp.swift b/mobile/examples/model_tester/ios/ModelTester/ModelTesterApp.swift
new file mode 100644
index 000000000..4932a22c5
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester/ModelTesterApp.swift
@@ -0,0 +1,10 @@
+import SwiftUI
+
+@main
+struct ModelTesterApp: App {
+ var body: some Scene {
+ WindowGroup {
+ ContentView()
+ }
+ }
+}
diff --git a/mobile/examples/model_tester/ios/ModelTester/Preview Content/Preview Assets.xcassets/Contents.json b/mobile/examples/model_tester/ios/ModelTester/Preview Content/Preview Assets.xcassets/Contents.json
new file mode 100644
index 000000000..73c00596a
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTester/Preview Content/Preview Assets.xcassets/Contents.json
@@ -0,0 +1,6 @@
+{
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
diff --git a/mobile/examples/model_tester/ios/ModelTesterTests/ModelTesterTests.swift b/mobile/examples/model_tester/ios/ModelTesterTests/ModelTesterTests.swift
new file mode 100644
index 000000000..63ba3ed8b
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTesterTests/ModelTesterTests.swift
@@ -0,0 +1,30 @@
+import XCTest
+
+@testable import ModelTester
+
+final class ModelTesterTests: XCTestCase {
+
+ override func setUpWithError() throws {
+ // Put setup code here. This method is called before the invocation of each test method in the class.
+ }
+
+ override func tearDownWithError() throws {
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
+ }
+
+ func testExample() throws {
+ // This is an example of a functional test case.
+ // Use XCTAssert and related functions to verify your tests produce the correct results.
+ // Any test you write for XCTest can be annotated as throws and async.
+ // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
+ // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
+ }
+
+ func testPerformanceExample() throws {
+ // This is an example of a performance test case.
+ self.measure {
+ // Put the code you want to measure the time of here.
+ }
+ }
+
+}
diff --git a/mobile/examples/model_tester/ios/ModelTesterUITests/ModelTesterUITests.swift b/mobile/examples/model_tester/ios/ModelTesterUITests/ModelTesterUITests.swift
new file mode 100644
index 000000000..defc3df6c
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTesterUITests/ModelTesterUITests.swift
@@ -0,0 +1,36 @@
+import XCTest
+
+final class ModelTesterUITests: XCTestCase {
+
+ override func setUpWithError() throws {
+ // Put setup code here. This method is called before the invocation of each test method in the class.
+
+ // In UI tests it is usually best to stop immediately when a failure occurs.
+ continueAfterFailure = false
+
+ // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
+ }
+
+ override func tearDownWithError() throws {
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
+ }
+
+ @MainActor
+ func testExample() throws {
+ // UI tests must launch the application that they test.
+ let app = XCUIApplication()
+ app.launch()
+
+ // Use XCTAssert and related functions to verify your tests produce the correct results.
+ }
+
+ @MainActor
+ func testLaunchPerformance() throws {
+ if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
+ // This measures how long it takes to launch your application.
+ measure(metrics: [XCTApplicationLaunchMetric()]) {
+ XCUIApplication().launch()
+ }
+ }
+ }
+}
diff --git a/mobile/examples/model_tester/ios/ModelTesterUITests/ModelTesterUITestsLaunchTests.swift b/mobile/examples/model_tester/ios/ModelTesterUITests/ModelTesterUITestsLaunchTests.swift
new file mode 100644
index 000000000..b46f21e50
--- /dev/null
+++ b/mobile/examples/model_tester/ios/ModelTesterUITests/ModelTesterUITestsLaunchTests.swift
@@ -0,0 +1,26 @@
+import XCTest
+
+final class ModelTesterUITestsLaunchTests: XCTestCase {
+
+ override class var runsForEachTargetApplicationUIConfiguration: Bool {
+ true
+ }
+
+ override func setUpWithError() throws {
+ continueAfterFailure = false
+ }
+
+ @MainActor
+ func testLaunch() throws {
+ let app = XCUIApplication()
+ app.launch()
+
+ // Insert steps here to perform after app launch but before taking a screenshot,
+ // such as logging into a test account or navigating somewhere in the app
+
+ let attachment = XCTAttachment(screenshot: app.screenshot())
+ attachment.name = "Launch Screen"
+ attachment.lifetime = .keepAlways
+ add(attachment)
+ }
+}
diff --git a/mobile/examples/model_tester/ios/Podfile b/mobile/examples/model_tester/ios/Podfile
new file mode 100644
index 000000000..d616675c7
--- /dev/null
+++ b/mobile/examples/model_tester/ios/Podfile
@@ -0,0 +1,20 @@
+# Uncomment the next line to define a global platform for your project
+platform :ios, '16.0'
+
+target 'ModelTester' do
+ # Comment the next line if you don't want to use dynamic frameworks
+ use_frameworks!
+
+ # Pods for ModelTester
+ pod "onnxruntime-c"
+
+ target 'ModelTesterTests' do
+ inherit! :search_paths
+ # Pods for testing
+ end
+
+ target 'ModelTesterUITests' do
+ # Pods for testing
+ end
+
+end
diff --git a/mobile/examples/model_tester/ios/model/download_model.py b/mobile/examples/model_tester/ios/model/download_model.py
new file mode 100644
index 000000000..e4c96a7ff
--- /dev/null
+++ b/mobile/examples/model_tester/ios/model/download_model.py
@@ -0,0 +1,11 @@
+from pathlib import Path
+from onnx import hub
+import onnx
+
+if __name__ == "__main__":
+ script_dir = Path(__file__).parent
+ output_path = script_dir / "model.onnx"
+ model_name = "MobileNet v2-1.0-fp32"
+
+ model = hub.load(model_name)
+ onnx.save(model, output_path)
diff --git a/mobile/examples/model_tester/ios/model/download_model.requirements.txt b/mobile/examples/model_tester/ios/model/download_model.requirements.txt
new file mode 100644
index 000000000..b20b937c0
--- /dev/null
+++ b/mobile/examples/model_tester/ios/model/download_model.requirements.txt
@@ -0,0 +1 @@
+onnx
diff --git a/mobile/examples/model_tester/ios/model/readme.md b/mobile/examples/model_tester/ios/model/readme.md
new file mode 100644
index 000000000..96c057cdc
--- /dev/null
+++ b/mobile/examples/model_tester/ios/model/readme.md
@@ -0,0 +1,10 @@
+Add a model here and name it model.onnx.
+
+You can run `download_model.py` to obtain a model.
+
+```bash
+python -m pip install -r ./download_model.requirements.txt
+
+python ./download_model.py
+```
+
diff --git a/mobile/examples/model_tester/ios/readme.md b/mobile/examples/model_tester/ios/readme.md
new file mode 100644
index 000000000..6f5c91c27
--- /dev/null
+++ b/mobile/examples/model_tester/ios/readme.md
@@ -0,0 +1,11 @@
+This is a basic app that runs an arbitrary ONNX model. It can measure the model's performance.
+
+# Set Up Instructions
+
+Copy an ONNX model to `model/model.onnx`.
+
+Install the CocoaPods dependencies. From this directory, run `pod install`.
+
+Open the xcworkspace file. From this directory, run `open ModelTester.xcworkspace`.
+
+Build and run the ModelTester app from Xcode.
diff --git a/mobile/examples/model_tester/readme.md b/mobile/examples/model_tester/readme.md
new file mode 100644
index 000000000..56b32959a
--- /dev/null
+++ b/mobile/examples/model_tester/readme.md
@@ -0,0 +1,5 @@
+This directory contains example code for apps that can be used to run a model with onnxruntime. They can be used for basic performance testing.
+
+- `common/` contains common, cross-platform, code.
+- `ios/` contains an example iOS app.
+