-
Notifications
You must be signed in to change notification settings - Fork 399
Add BasicPluginEp example with Android package #545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edgchen1
wants to merge
14
commits into
main
Choose a base branch
from
edgchen1/basic_plugin_ep
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4637f1f
add basic plugin EP files
edgchen1 d064631
update .clang-format column limit
edgchen1 1e69853
update cmakelists.txt
edgchen1 bbcaadc
add plugin_execution_providers/basic/android
edgchen1 d165c2f
add comments about deps
edgchen1 c1cc30b
update message
edgchen1 2b9a08d
add automatic downloading of ORT
edgchen1 c8bf6fa
move plugin_ep_utils.h to common dir
edgchen1 535aacf
remove some unused code from plugin_ep_utils.h
edgchen1 065bc93
add copyright comment
edgchen1 d752300
add comment about ORT_HOME to CMakeLists.txt
edgchen1 53eb7a1
update comments
edgchen1 1abf3b8
add mul.onnx
edgchen1 eedbd40
add gen_mul_model.py
edgchen1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| cmake_minimum_required(VERSION 3.31) | ||
|
|
||
| project(BasicPluginEp) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 20) | ||
|
|
||
| set(plugin_ep_common_dir ${CMAKE_SOURCE_DIR}/../common) | ||
|
|
||
| include(${plugin_ep_common_dir}/cmake/onnxruntime_library_utils.cmake) | ||
|
|
||
| # Set ORT_HOME (e.g., with cmake -D) to specify the directory with the ONNX Runtime header and library files to use. | ||
| # This is optional. If unspecified, the ONNX Runtime files will be downloaded. | ||
|
|
||
| set_onnxruntime_paths( | ||
| ORT_HOME ${ORT_HOME} | ||
| DEFAULT_ORT_VERSION "1.23.2" | ||
| ORT_INCLUDE_DIR_VAR ORT_INCLUDE_DIR | ||
| ORT_LIBRARY_DIR_VAR ORT_LIBRARY_DIR) | ||
|
|
||
| message(STATUS "ORT_LIBRARY_DIR: ${ORT_LIBRARY_DIR}") | ||
| message(STATUS "ORT_INCLUDE_DIR: ${ORT_INCLUDE_DIR}") | ||
|
|
||
| # | ||
| # basic_plugin_ep | ||
| # | ||
| block() | ||
|
|
||
| add_library(basic_plugin_ep MODULE) | ||
|
|
||
| target_sources(basic_plugin_ep PRIVATE | ||
| ${CMAKE_SOURCE_DIR}/src/ep_factory.cc | ||
| ${CMAKE_SOURCE_DIR}/src/ep_factory.h | ||
| ${CMAKE_SOURCE_DIR}/src/ep_lib_entry.cc | ||
| ${CMAKE_SOURCE_DIR}/src/ep.cc | ||
| ${CMAKE_SOURCE_DIR}/src/ep.h | ||
| ${plugin_ep_common_dir}/src/plugin_ep_utils.h | ||
| ) | ||
|
|
||
| target_include_directories(basic_plugin_ep PRIVATE | ||
| ${ORT_INCLUDE_DIR} | ||
| ${plugin_ep_common_dir}/src | ||
| ) | ||
|
|
||
| target_link_directories(basic_plugin_ep PRIVATE ${ORT_LIBRARY_DIR}) | ||
| target_link_libraries(basic_plugin_ep PRIVATE onnxruntime) | ||
|
|
||
| set(basic_plugin_ep_link_options) | ||
| if(MSVC) | ||
| list(APPEND basic_plugin_ep_link_options | ||
| "-DEF:${CMAKE_SOURCE_DIR}/src/ep_lib.def") | ||
| else() | ||
| if(UNIX) | ||
| if(APPLE) | ||
| list(APPEND basic_plugin_ep_link_options | ||
| "LINKER:-dead_strip") | ||
| else() | ||
| list(APPEND basic_plugin_ep_link_options | ||
| "LINKER:--version-script=${CMAKE_SOURCE_DIR}/src/ep_lib.lds" | ||
| "LINKER:--no-undefined" | ||
| "LINKER:--gc-sections" | ||
| "-z" "noexecstack") | ||
| endif() | ||
| endif() | ||
| endif() | ||
|
|
||
| target_link_options(basic_plugin_ep PRIVATE ${basic_plugin_ep_link_options}) | ||
|
|
||
| endblock() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
1 change: 1 addition & 0 deletions
1
plugin_execution_providers/basic/android/basicpluginep/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
63 changes: 63 additions & 0 deletions
63
plugin_execution_providers/basic/android/basicpluginep/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Specifies a directory containing ONNX Runtime libraries and headers to use. This directory | ||
| // should match the onnxruntime-android AAR structure. | ||
| // Specifying `ortHome` is optional. If unspecified, the ONNX Runtime files will be downloaded. | ||
| val ortHome: String? = System.getProperty("ortHome") | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.android.library) | ||
| alias(libs.plugins.kotlin.android) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "ai.onnxruntime.example.basicpluginep" | ||
| compileSdk { | ||
| version = release(36) | ||
| } | ||
|
|
||
| defaultConfig { | ||
| minSdk = 26 | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| consumerProguardFiles("consumer-rules.pro") | ||
| externalNativeBuild { | ||
| cmake { | ||
| if (ortHome != null) { | ||
| arguments += listOf("-DORT_HOME=${ortHome}") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| isMinifyEnabled = false | ||
| proguardFiles( | ||
| getDefaultProguardFile("proguard-android-optimize.txt"), | ||
| "proguard-rules.pro" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| externalNativeBuild { | ||
| cmake { | ||
| path("../../CMakeLists.txt") | ||
| version = "3.31.6" | ||
| } | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
| kotlinOptions { | ||
| jvmTarget = "11" | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(libs.androidx.core.ktx) | ||
| implementation(libs.androidx.appcompat) | ||
| implementation(libs.material) | ||
| testImplementation(libs.junit) | ||
| androidTestImplementation(libs.androidx.junit) | ||
| androidTestImplementation(libs.androidx.espresso.core) | ||
| } |
Empty file.
21 changes: 21 additions & 0 deletions
21
plugin_execution_providers/basic/android/basicpluginep/proguard-rules.pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
24 changes: 24 additions & 0 deletions
24
...inep/src/androidTest/java/ai/onnxruntime/example/basicpluginep/ExampleInstrumentedTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package ai.onnxruntime.example.basicpluginep | ||
|
|
||
| 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("ai.onnxruntime.example.basicpluginep.test", appContext.packageName) | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
plugin_execution_providers/basic/android/basicpluginep/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| </manifest> |
11 changes: 11 additions & 0 deletions
11
.../basicpluginep/src/main/java/ai/onnxruntime/example/basicpluginep/BasicPluginEpLibrary.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package ai.onnxruntime.example.basicpluginep | ||
|
|
||
| private const val basicPluginEpLibraryName = "basic_plugin_ep" | ||
|
|
||
| /** | ||
| * Returns the path to the basic plugin EP library. | ||
| * This path can be used with `OrtEnvironment.registerExecutionProviderLibrary()`. | ||
| */ | ||
| fun getBasicPluginEpLibraryPath() : String { | ||
| return "lib${basicPluginEpLibraryName}.so" | ||
| } |
17 changes: 17 additions & 0 deletions
17
...droid/basicpluginep/src/test/java/ai/onnxruntime/example/basicpluginep/ExampleUnitTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package ai.onnxruntime.example.basicpluginep | ||
|
|
||
| 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) | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
plugin_execution_providers/basic/android/basicpluginepusage/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
69 changes: 69 additions & 0 deletions
69
plugin_execution_providers/basic/android/basicpluginepusage/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| plugins { | ||
| alias(libs.plugins.android.application) | ||
| alias(libs.plugins.kotlin.android) | ||
| alias(libs.plugins.kotlin.compose) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "ai.onnxruntime.example.basicpluginepusage" | ||
| compileSdk { | ||
| version = release(36) | ||
| } | ||
|
|
||
| defaultConfig { | ||
| applicationId = "ai.onnxruntime.example.basicpluginepusage" | ||
| minSdk = 26 | ||
| targetSdk = 36 | ||
| 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_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
| kotlinOptions { | ||
| jvmTarget = "11" | ||
| } | ||
| buildFeatures { | ||
| compose = true | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| // Plugin EP library module dependency | ||
| implementation(project(":basicpluginep")) | ||
|
|
||
| // onnxruntime-android dependency | ||
| // Note: Typically, we would want to use a release version, but some of the plugin EP | ||
| // infrastructure is not available in a released version yet. We'll depend on a dev version. | ||
| //implementation("com.microsoft.onnxruntime:onnxruntime-android:latest.release") | ||
| implementation(files("lib/onnxruntime-android-1.24.0-dev+commit-75d35474.aar")) | ||
|
|
||
| implementation(libs.androidx.core.ktx) | ||
| implementation(libs.androidx.lifecycle.runtime.ktx) | ||
| implementation(libs.androidx.activity.compose) | ||
| implementation(platform(libs.androidx.compose.bom)) | ||
| implementation(libs.androidx.compose.ui) | ||
| implementation(libs.androidx.compose.ui.graphics) | ||
| implementation(libs.androidx.compose.ui.tooling.preview) | ||
| implementation(libs.androidx.compose.material3) | ||
| testImplementation(libs.junit) | ||
| androidTestImplementation(libs.androidx.junit) | ||
| androidTestImplementation(libs.androidx.espresso.core) | ||
| androidTestImplementation(platform(libs.androidx.compose.bom)) | ||
| androidTestImplementation(libs.androidx.compose.ui.test.junit4) | ||
| debugImplementation(libs.androidx.compose.ui.tooling) | ||
| debugImplementation(libs.androidx.compose.ui.test.manifest) | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
plugin_execution_providers/basic/android/basicpluginepusage/gen_mul_model.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from pathlib import Path | ||
| import onnx | ||
| from onnxscript import script, FLOAT, opset15 as op | ||
|
|
||
| @script(default_opset=op) | ||
| def model(x: FLOAT[2, 3], y: FLOAT[2, 3]) -> FLOAT[2, 3]: | ||
| return x * y | ||
|
|
||
| model_proto = model.to_model_proto() | ||
| script_dir = Path(__file__).parent | ||
| onnx.save(model_proto, f"{script_dir}/src/main/res/raw/mul.onnx") |
Binary file added
BIN
+39.4 MB
...s/basic/android/basicpluginepusage/lib/onnxruntime-android-1.24.0-dev+commit-75d35474.aar
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
plugin_execution_providers/basic/android/basicpluginepusage/proguard-rules.pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
24 changes: 24 additions & 0 deletions
24
...src/androidTest/java/ai/onnxruntime/example/basicpluginepusage/ExampleInstrumentedTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package ai.onnxruntime.example.basicpluginepusage | ||
|
|
||
| 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("ai.onnxruntime.example.basicpluginepusage", appContext.packageName) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use onnxruntime-android 1.24 if that gets released before this PR is merged