mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
[java] Adds the provider compile-time flags where the JNI code expects them. (#3082)
This commit is contained in:
parent
a506911208
commit
b23b7f0fea
3 changed files with 34 additions and 8 deletions
|
|
@ -50,6 +50,30 @@ file(GLOB onnxruntime4j_native_src
|
|||
)
|
||||
# Build the JNI library
|
||||
add_library(onnxruntime4j_jni SHARED ${onnxruntime4j_native_src})
|
||||
|
||||
# Tell the JNI code about the requested providers
|
||||
if (onnxruntime_USE_CUDA)
|
||||
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_CUDA=1)
|
||||
endif()
|
||||
if (onnxruntime_USE_DNNL)
|
||||
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_DNNL=1)
|
||||
endif()
|
||||
if (onnxruntime_USE_NGRAPH)
|
||||
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_NGRAPH=1)
|
||||
endif()
|
||||
if (onnxruntime_USE_OPENVINO)
|
||||
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_OPENVINO=1)
|
||||
endif()
|
||||
if (onnxruntime_USE_TENSORRT)
|
||||
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_TENSORRT=1)
|
||||
endif()
|
||||
if (onnxruntime_USE_NNAPI)
|
||||
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_NNAPI=1)
|
||||
endif()
|
||||
if (onnxruntime_USE_NUPHAR)
|
||||
target_compile_definitions(onnxruntime4j_jni PRIVATE USE_NUPHAR=1)
|
||||
endif()
|
||||
|
||||
# depend on java sources. if they change, the JNI should recompile
|
||||
add_dependencies(onnxruntime4j_jni onnxruntime4j)
|
||||
onnxruntime_add_include_to_target(onnxruntime4j_jni onnxruntime_session)
|
||||
|
|
@ -69,4 +93,4 @@ file(MAKE_DIRECTORY ${JAVA_PACKAGE_JNI_DIR})
|
|||
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:onnxruntime> ${JAVA_PACKAGE_LIB_DIR}/$<TARGET_LINKER_FILE_NAME:onnxruntime>)
|
||||
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:onnxruntime4j_jni> ${JAVA_PACKAGE_JNI_DIR}/$<TARGET_LINKER_FILE_NAME:onnxruntime4j_jni>)
|
||||
# run the build process (this copies the results back into CMAKE_CURRENT_BINARY_DIR)
|
||||
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} cmakeBuild -DcmakeBuildDir=${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${JAVA_ROOT})
|
||||
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} cmakeBuild -DcmakeBuildDir=${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${JAVA_ROOT})
|
||||
|
|
|
|||
|
|
@ -33,16 +33,16 @@ The build will generate output in `$REPO_ROOT/build/$OS/$CONFIGURATION/java/buil
|
|||
|
||||
* `docs/javadoc/` - HTML javadoc
|
||||
* `reports/` - detailed test results and other reports
|
||||
* `libs/onnxruntime.jar` - JAR with classes, depends on `onnxruntime-jni.jar` and `onnxruntime-lib.jar `
|
||||
* `libs/onnxruntime-jni.jar`- JAR with JNI shared library
|
||||
* `libs/onnxruntime-lib.jar` - JAR with onnxruntime shared library
|
||||
* `libs/onnxruntime-all.jar` - the 3 preceding jars all combined: JAR with classes, JNI shared library, and onnxruntime shared library
|
||||
* `libs/onnxruntime-<version-number>.jar` - JAR with classes, depends on `onnxruntime-<version-number>-jni.jar` and `onnxruntime-<version-number>-lib.jar `
|
||||
* `libs/onnxruntime-<version-number>-jni.jar`- JAR with JNI shared library
|
||||
* `libs/onnxruntime-<version-number>-lib.jar` - JAR with onnxruntime shared library
|
||||
* `libs/onnxruntime-<version-number>-all.jar` - the 3 preceding jars all combined: JAR with classes, JNI shared library, and onnxruntime shared library
|
||||
|
||||
The reason the shared libraries are split out like that is that users can mix and match to suit their use case:
|
||||
|
||||
* To support a single OS/Architecture without any dependencies, use `libs/onnxruntime-all.jar`.
|
||||
* To support cross-platform: bundle a single `libs/onnxruntime.jar` and with all of the respective `libs/onnxruntime-jni.jar` and `libs/onnxruntime-lib.jar` for all of the desired OS/Architectures.
|
||||
* To support use case where an onnxruntime shared library will reside in the system's library search path: bundle a single `libs/onnxruntime.jar` and with all of the `libs/onnxruntime-jni.jar`. The onnxruntime shared library should be loaded using one of the other methods described in the "Advanced Loading" section below.
|
||||
* To support a single OS/Architecture without any dependencies, use `libs/onnxruntime-<version-number>-all.jar`.
|
||||
* To support cross-platform: bundle a single `libs/onnxruntime-<version-number>.jar` and with all of the respective `libs/onnxruntime-<version-number>-jni.jar` and `libs/onnxruntime-<version-number>-lib.jar` for all of the desired OS/Architectures.
|
||||
* To support use case where an onnxruntime shared library will reside in the system's library search path: bundle a single `libs/onnxruntime-<version-number>.jar` and with all of the `libs/onnxruntime-<version-number>-jni.jar`. The onnxruntime shared library should be loaded using one of the other methods described in the "Advanced Loading" section below.
|
||||
|
||||
#### Build System Overview
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib"
|
|||
def cmakeNativeJniDir = "${cmakeJavaDir}/native-jni"
|
||||
def cmakeBuildOutputDir = "${cmakeJavaDir}/build"
|
||||
|
||||
version = rootProject.file('../VERSION_NUMBER').text.trim()
|
||||
|
||||
compileJava {
|
||||
options.compilerArgs += ["-h", "${project.buildDir}/headers/"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue