* First iteration of making cuda a shared provider. Separated out shared OpKernel change, so doing this to merge with that change. * More cuda shared library refactoring * More cuda shared library refactoring * More build options tested, converted the training ops over. * Fix merge breaks * Fix submodules * Fix submodules * Fix submodules * Fix python * Fix compile errors * Duplicate symbol fix * Test fix for ROCM provider * Another ROCM test workaround * ROCM Build Test * ROCM build fix * ROCM * ROCM * ROCM * ROCM * ROCM * ROCM test * Reduce header dependencies * Remove redundant namespace * Test fix for linux * Fix linux build * Fix Eigen build error * Fix unused parameter warning * Test link error * Another linker test * Linker test * Linker test * Another test * Another build test * Fix linux link error * Build test * Fix control flow ops to use common base class with core code * Remove extra qualifiers * Fix template syntax for linux * Fix cuda memory leak * Fix pybind * Test disabling cast * Cleanup * Restore cuda in test * Remove more header dependencies * Test not adding cuda provider to session * Make GetProviderInfo_CUDA throw * No-op cuda provider creation * Fix some setup issues * Fix memory cleanup on unload * Diagnostics * Don't unload library * Add diagnostics * Fix deleting registry at right time. * Test disabling profiler * Fix merge break * Revert profiler change * Move unloading of shared providers into Environment * Free more global allocations before library unloads * Add more diagnostics * Move unloading back to the OrtEnv as there are multiple Environments created during a session. Remove some library dependencies for tests. * Fix more cmake files * ERROR -> WARNING * Fix python shutdown * Test not using dml in pipeline * Change python version and disable dml * Update python version * Test adding unload method for shared providers * Disable DLL test * Python test * Revert "Python test" This reverts commit |
||
|---|---|---|
| .. | ||
| src | ||
| testdata | ||
| build-android.gradle | ||
| build.gradle | ||
| README.md | ||
| settings-android.gradle | ||
| settings.gradle | ||
ONNX Runtime Java API
This directory contains the Java language binding for the ONNX runtime. Java Native Interface (JNI) is used to allow for seamless calls to ONNX runtime from Java.
Usage
This document pertains to developing, building, running, and testing the API itself in your local environment. For general purpose usage of the publicly distributed API, please see the general Java API documentation.
Building
Use the main project's build instructions with the --build_java option.
Requirements
JDK version 8 or later is required.
The Gradle build system is required and used here to manage the Java project's dependency management, compilation, testing, and assembly.
You may use your system Gradle installation installed on your PATH.
Version 6 or newer is recommended.
Optionally, you may use your own Gradle wrapper which will be locked to a version specified in the build.gradle configuration.
This can be done once by using system Gradle installation to invoke the wrapper task in the java project's directory: cd REPO_ROOT/java && gradle wrapper
Any installed wrapper is gitignored.
Build Output
The build will generate output in $REPO_ROOT/build/$OS/$CONFIGURATION/java/build:
docs/javadoc/- HTML javadocreports/- detailed test results and other reportslibs/onnxruntime-VERSION.jar- JAR with compiled classes, platform-specific JNI shared library, and platform-specific onnxruntime shared library.
Build System Overview
The main CMake build system delegates building and testing to Gradle.
This allows the CMake system to ensure all of the C/C++ compilation is achieved prior to the Java build.
The Java build depends on C/C++ onnxruntime shared library and a C JNI shared library (source located in the src/main/native directory).
The JNI shared library is the glue that allows for Java to call functions in onnxruntime shared library.
Given the fact that CMake injects native dependencies during CMake builds, some gradle tasks (primarily, build, test, and check) may fail.
When running the build script, CMake will compile the onnxruntime target and the JNI glue onnxruntime4j_jni target and expose the resulting libraries in a place where Gradle can ingest them.
Upon successful compilation of those targets, a special Gradle task to build will be executed. The results will be placed in the output directory stated above.
Advanced Loading
The default behavior is to load the shared libraries using classpath resources. If your use case requires custom loading of the shared libraries, please consult the javadoc in the package-info.java or OnnxRuntime.java files.
Development
Code Formatting
Spotless is used to keep the code properly formatted.
Gradle's spotlessCheck task will show any misformatted code.
Gradle's spotlessApply task will try to fix the formatting.
Misformatted code will raise failures when checks are ran during test run.
JNI Headers
When adding or updating native methods in the Java files, it may be necessary to examine the relevant JNI headers in build/headers/ai_onnxruntime*.h.
These files can be manually generated using Gradle's compileJava task which will compile the Java and update the header files accordingly.
Then the corresponding C files in ./src/main/native/ai_onnxruntime*.c may be updated and the build can be ran.
Dependencies
The Java API does not have any runtime or compile dependencies currently.