Skip to content
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

Java API for onnxruntime #2215

Merged
merged 76 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
88f2f55
Added a Java API, plus unit tests ported from the C# API in v0.5.0.
Craigacp Oct 21, 2019
023fff3
Fixes for the JNI build on macOS.
Craigacp Oct 23, 2019
157a7f3
Adding two JVM startup flags which turn on additional debug logging o…
Craigacp Oct 28, 2019
46521e7
Fixing a typo and missing logging statement.
Craigacp Oct 28, 2019
72813bc
Handle flatten string array as input/output of onnx
Nov 3, 2019
5f590fb
Remove duplicated example
Nov 3, 2019
7c89d7d
Updating copyright statement to include license reference.
Craigacp Nov 4, 2019
bccfe61
Repackaging to ai.onnxruntime.
Craigacp Nov 4, 2019
14fa539
Renaming native code.
Craigacp Nov 4, 2019
e226c83
Small fixes to names & javadoc.
Craigacp Nov 4, 2019
6dfa0bc
Merge branch 'java-api-fix-string' of https://github.com/XciD/onnxrunt…
Craigacp Nov 4, 2019
94119e5
Fixing the issue where a multidimensional String is passed to createT…
Craigacp Nov 4, 2019
75df6db
Merge branch 'XciD-java-api-fix-string' into java-api
Craigacp Nov 4, 2019
c37c8fb
Comment and exception error message fixes for ONNXAllocator.
Craigacp Nov 4, 2019
6ede863
Tidying up the array creation via reflection.
Craigacp Nov 5, 2019
19e0c02
Refactoring the reshape method to reduce code size.
Craigacp Nov 13, 2019
a8d65a3
Fixes to make the JNI code compile with -Werror -Wunused-parameter.
Craigacp Nov 20, 2019
b018923
Initial pass at CMake integration for the Java build. Does not produc…
Craigacp Nov 20, 2019
0d5f92d
Fix for clang warning.
Craigacp Nov 20, 2019
607ac1e
More work on Java CMake build.
Craigacp Nov 20, 2019
078d6b5
Merge branch 'master' into java-api
Craigacp Nov 20, 2019
4fa9927
Change the java provider ifdefs to trigger on the values set by CMake.
Craigacp Nov 20, 2019
f5d45b6
Finished the Java/CMake integration for builds. Doesn't run the tests…
Craigacp Nov 20, 2019
bc9c17f
Making two jars, one with binaries, one without.
Craigacp Nov 25, 2019
d447bde
Adding the onnx Java protobuf file.
Craigacp Nov 26, 2019
1607412
Fixing the Java providers so they don't trigger the unused parameter …
Craigacp Nov 26, 2019
e1da6e8
Changes to the gradle build to support running the tests from CMake a…
Craigacp Nov 26, 2019
f32f522
Adding initial Java test support.
Craigacp Nov 26, 2019
db96bb9
Integration of the Java tests with ctest. All the Java tests are exec…
Craigacp Nov 26, 2019
e476701
Starting the renaming of the Java classes.
Craigacp Nov 26, 2019
c6810ac
Renaming the JNI parts of the Java API.
Craigacp Nov 26, 2019
11c2da7
Finishing the renaming of the Java classes and JNI code.
Craigacp Nov 26, 2019
aacd5a4
Updating the CMake to build the renamed Java files.
Craigacp Nov 27, 2019
b5c8e44
Refactoring OrtEnvironment to enforce that it's a singleton and autoc…
Craigacp Nov 27, 2019
d56d38d
OrtSession.run now accepts Map<String,OnnxTensor> and returns Map<Str…
Craigacp Dec 2, 2019
a17b953
Adding some java specific things to gitignore.
Craigacp Dec 2, 2019
9d9fbb4
Converting OrtSession.run() over to produce an AutoCloseable Result o…
Craigacp Dec 2, 2019
d0cd066
Enabling some disabled Java tests.
Craigacp Dec 2, 2019
df89715
Merge branch 'master' into java-api
Craigacp Dec 2, 2019
f4691ef
Renaming the JNI helper ONNXUtil.c to OrtJniUtil.c
Craigacp Dec 3, 2019
2387821
Minor cleanup of Java bits, adding toString to some classes, removing…
Craigacp Dec 3, 2019
fd79837
Adding Java method to control the telemetry.
Craigacp Dec 3, 2019
b664d89
Adding a method to get ByteBuffers (and other primitive buffers) out …
Craigacp Dec 4, 2019
5677541
Removing gradle project files.
Craigacp Dec 4, 2019
4e8fc9e
Removing old comments from OrtSession.SessionOptions.
Craigacp Dec 4, 2019
7836689
Slight rearrangement of OrtAllocator.close to make it not set the def…
Craigacp Dec 4, 2019
441cd55
Converting the SessionOptions.setSequentialExecution method over to e…
Craigacp Dec 4, 2019
c0d1438
Small javadoc update.
Craigacp Dec 4, 2019
f22b6bb
Fixing a bug in Java's convertExecutionMode function.
Craigacp Dec 4, 2019
2a195c5
Updating a java test after changing the execution mode to an enum.
Craigacp Dec 4, 2019
86080bb
Adding javadoc to cmake, fixing javadoc warnings.
Craigacp Dec 4, 2019
8bcfd92
Merge branch 'master' into java-api
Craigacp Dec 4, 2019
ff3e5db
Moving createTensor to OnnxTensor. Updating to use DNNL rather than M…
Craigacp Dec 5, 2019
4d03337
Adding more javadoc.
Craigacp Dec 5, 2019
9e2dc06
Small changes to javadoc and naming in OrtEnvironment.
Craigacp Dec 5, 2019
0c26d4e
Switching use_mkldnn for use_dnnl in linux-ci-pipeline-with-java.yml
Craigacp Dec 5, 2019
5b796cd
Adding --build_java to win-ci-pipeline.yml
Craigacp Dec 5, 2019
fd034b4
Adding file encoding to javac command.
Craigacp Dec 5, 2019
9ea9928
Fix for fp16 to float C conversion.
Craigacp Dec 5, 2019
ef2cdd3
Fixing the fp16 to float conversion again.
Craigacp Dec 5, 2019
5343746
Adding documentation for the Java API.
Craigacp Dec 5, 2019
bac2da2
Updating the cmake to give the javadoc window a title.
Craigacp Dec 5, 2019
443d653
Different fix for the javadoc window title. The create_javadoc comman…
Craigacp Dec 5, 2019
aef09cc
Updated Java CMake build to hopefully fix the windows issues.
Craigacp Dec 5, 2019
6a211ae
Replacing the copyright symbol with (c) to make the java files ASCII.
Craigacp Dec 6, 2019
f9f037c
Fix for nuphar on Java.
Craigacp Dec 6, 2019
9a0691c
Updating the Java tests to minimise the cascading errors issue.
Craigacp Dec 6, 2019
a8d0a8b
Adding a couple of new overloads to OnnxTensor.createTensor for deali…
Craigacp Dec 6, 2019
26ab79b
Merge branch 'master' into java-api
Craigacp Dec 6, 2019
40b1756
Adding a patch for Windows file paths in Java.
Craigacp Dec 9, 2019
ca4dcd2
added path to build dir before running test
shahasad Dec 9, 2019
4f1f1da
fix syntax error
shahasad Dec 9, 2019
399c847
Merge branch 'master' of https://github.com/Microsoft/onnxruntime int…
shahasad Dec 9, 2019
5b42825
try localising the path setting
shahasad Dec 9, 2019
b4a79e6
Merge branch 'master' into java-api
shahasad Dec 10, 2019
4d468c5
added an echo %PATH% after path setting
shahasad Dec 10, 2019
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
153 changes: 153 additions & 0 deletions java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
* Licensed under the MIT License.
*/
import org.gradle.internal.jvm.Jvm
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

plugins {
id 'cpp-library'
id 'java'
id 'maven'
id 'maven-publish'
}

group 'com.microsoft.onnxruntime'
version '1.0.0-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

def os = DefaultNativePlatform.currentOperatingSystem
def platform = 'unknown'

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.4.2')
}

compileJava {
options.headerOutputDirectory = file("src/main/native")
}

library {
baseName = "ONNX4j"
targetMachines = [
machines.linux,
machines.macOS
]
binaries.configureEach {
def compileTask = compileTask.get()
compileTask.dependsOn "compileJava"
compileTask.source.from fileTree(dir: "src/main/native", include: "**/*.c")
List<String> newCompilerArgs = new ArrayList<String>()
newCompilerArgs.add("-x")
newCompilerArgs.add("c")
newCompilerArgs.add("-std=c11")
if (targetMachine.operatingSystemFamily.macOs) {
newCompilerArgs.add("-I")
newCompilerArgs.add("${Jvm.current().javaHome}/include")
newCompilerArgs.add("-I")
newCompilerArgs.add("${Jvm.current().javaHome}/include/darwin")
} else if (targetMachine.operatingSystemFamily.linux) {
newCompilerArgs.add("-I")
newCompilerArgs.add("${Jvm.current().javaHome}/include")
newCompilerArgs.add("-I")
newCompilerArgs.add("${Jvm.current().javaHome}/include/linux")
newCompilerArgs.add("-D_FILE_OFFSET_BITS=64")
}
newCompilerArgs.add("-I")
newCompilerArgs.add("${project.rootDir}/../include/")
newCompilerArgs.add("-I")
newCompilerArgs.add("${project.rootDir}/../include/onnxruntime/")
newCompilerArgs.add("-I")
newCompilerArgs.add("${project.rootDir}/../include/onnxruntime/core/session/")
newCompilerArgs.add("-Werror")
compileTask.compilerArgs = newCompilerArgs

def linkTask = linkTask.get()
if (toolChain instanceof GccCompatibleToolChain) {
linkTask.linkerArgs = ["-nodefaultlibs", "-L../build/Linux/Debug/", "-lc", "-lonnxruntime"]
}
}
}

jar {
manifest {
attributes (
'Main-Class': "com.microsoft.onnxruntime.Main",
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Built-JDK': System.getProperty('java.version'),
'Build-Time-ISO-8601': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
)
}
into("META-INF/maven/$project.group/$project.name") {
from { generatePomFileForMavenPublication }
rename ".*", "pom.xml"
}
into("/lib/") {
from { "build/lib/main/release/" + platform + "/" }
from { "../build/Linux/Debug/libonnxruntime.so" }
}
}

task('debugJar', type: Jar) {
dependsOn ":compileJava"
manifest {
attributes (
'Main-Class': "com.microsoft.onnxruntime.Main",
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Built-JDK': System.getProperty('java.version'),
'Build-Time-ISO-8601': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
)
}
classifier = 'debug'
into("/") {
from { "build/classes/java/main/" }
}
into("META-INF/maven/$project.group/$project.name") {
from { generatePomFileForMavenPublication }
rename ".*", "pom.xml"
}
into("/lib/") {
from { "build/lib/main/debug/" + platform + "/" }
from { "../build/Linux/Debug/libonnxruntime.so" }
}
}

if (os.isLinux()) {
jar.dependsOn ":linkReleaseLinux"
debugJar.dependsOn ":linkDebugLinux"
platform = "linux"
} else if (os.isMacOsX()) {
jar.dependsOn ":linkReleaseMacos"
debugJar.dependsOn ":linkDebugMacos"
platform = "macos"
}

test {
classpath = project.sourceSets.test.runtimeClasspath + files("build/lib/main/debug/" + platform + "/") + files("../build/Linux/Debug/")
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed","skipped","failed"
}
}

publishing {
publications {
maven(MavenPublication) {
groupId project.group
artifactId project.name
version project.version

from components.java
}
}
}
Binary file added java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed May 15 16:11:00 EDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
172 changes: 172 additions & 0 deletions java/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## 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=""

# 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, switch paths to Windows format before running java
if $cygwin ; 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=$((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"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading