Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BasedOnStyle: Google

# 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: 120
ColumnLimit: 0
SortIncludes: false
DerivePointerAlignment: false
# Avoid adding spaces between tokens in GSL_SUPPRESS arguments.
Expand Down
71 changes: 71 additions & 0 deletions plugin_execution_providers/basic/CMakeLists.txt
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()
15 changes: 15 additions & 0 deletions plugin_execution_providers/basic/android/.gitignore
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
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)
}
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
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)
}
}
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>
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"
}
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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
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)
}
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 not shown.
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
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)
}
}
Loading
Loading