Java GPu artifact naming (#4179)

Modify gradle build so artifactID has _gpu for GPU builds.
  Pass USE_CUDA flag on CUDA build
  Adjust publishing pipelines to extract POM from a correct path.

Co-Authored-By: @Craigacp
This commit is contained in:
Dmitri Smirnov 2020-06-10 11:15:48 -07:00 committed by GitHub
parent e8ed14bcb3
commit af0750ba1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 25 deletions

View file

@ -42,6 +42,9 @@ set(GRADLE_ARGS clean jar)
if(WIN32)
set(GRADLE_ARGS ${GRADLE_ARGS} -Dorg.gradle.daemon=false)
endif()
if(onnxruntime_USE_CUDA)
set(GRADLE_ARGS ${GRADLE_ARGS} -DUSE_CUDA=1)
endif()
add_custom_command(OUTPUT ${JAVA_OUTPUT_JAR} COMMAND ${GRADLE_EXECUTABLE} ${GRADLE_ARGS} WORKING_DIRECTORY ${JAVA_ROOT} DEPENDS ${onnxruntime4j_gradle_files} ${onnxruntime4j_src})
add_custom_target(onnxruntime4j DEPENDS ${JAVA_OUTPUT_JAR})
set_source_files_properties(${JAVA_OUTPUT_JAR} PROPERTIES GENERATED TRUE)
@ -159,6 +162,9 @@ set(GRADLE_ARGS cmakeBuild -DcmakeBuildDir=${CMAKE_CURRENT_BINARY_DIR})
if(WIN32)
set(GRADLE_ARGS ${GRADLE_ARGS} -Dorg.gradle.daemon=false)
endif()
if(onnxruntime_USE_CUDA)
set(GRADLE_ARGS ${GRADLE_ARGS} -DUSE_CUDA=1)
endif()
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} ${GRADLE_ARGS} WORKING_DIRECTORY ${JAVA_ROOT})
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} -b build-android.gradle -c settings-android.gradle build -DjniLibsDir=${ANDROID_PACKAGE_JNILIBS_DIR} -DbuildDir=${ANDROID_PACKAGE_OUTPUT_DIR} WORKING_DIRECTORY ${JAVA_ROOT})

View file

@ -15,6 +15,20 @@ allprojects {
project.group = "com.microsoft.onnxruntime"
version = rootProject.file('../VERSION_NUMBER').text.trim()
// cmake runs will inform us of the build directory of the current run
def cmakeBuildDir = System.properties['cmakeBuildDir']
def useCUDA = System.properties['USE_CUDA']
def cmakeJavaDir = "${cmakeBuildDir}/java"
def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib"
def cmakeNativeJniDir = "${cmakeJavaDir}/native-jni"
def cmakeNativeTestDir = "${cmakeJavaDir}/native-test"
def cmakeBuildOutputDir = "${cmakeJavaDir}/build"
def mavenUser = System.properties['mavenUser']
def mavenPwd = System.properties['mavenPwd']
def mavenArtifactId = useCUDA != null ? project.name + "_gpu" : project.name
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -29,7 +43,7 @@ jar {
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
into("META-INF/maven/$project.group/$project.name") {
into("META-INF/maven/$project.group/$mavenArtifactId") {
from { generatePomFileForMavenPublication }
rename ".*", "pom.xml"
}
@ -39,7 +53,7 @@ task sourcesJar(type: Jar, dependsOn: classes) {
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = "javadoc"
from javadoc.destinationDir
into("META-INF/maven/$project.group/$project.name") {
into("META-INF/maven/$project.group/$mavenArtifactId") {
from { generatePomFileForMavenPublication }
rename ".*", "pom.xml"
}
@ -61,17 +75,6 @@ spotless {
}
}
// cmake runs will inform us of the build directory of the current run
def cmakeBuildDir = System.properties['cmakeBuildDir']
def cmakeJavaDir = "${cmakeBuildDir}/java"
def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib"
def cmakeNativeJniDir = "${cmakeJavaDir}/native-jni"
def cmakeNativeTestDir = "${cmakeJavaDir}/native-test"
def cmakeBuildOutputDir = "${cmakeJavaDir}/build"
def mavenUser = System.properties['mavenUser']
def mavenPwd = System.properties['mavenPwd']
compileJava {
options.compilerArgs += ["-h", "${project.buildDir}/headers/"]
}
@ -98,7 +101,12 @@ if (cmakeBuildDir != null) {
// Overwrite jar location
task allJar(type: Jar) {
into("META-INF/maven/$project.group/$project.name") {
manifest {
attributes('Automatic-Module-Name': project.group,
'Implementation-Title': 'onnxruntime',
'Implementation-Version': project.version)
}
into("META-INF/maven/$project.group/$mavenArtifactId") {
from { generatePomFileForMavenPublication }
rename ".*", "pom.xml"
}
@ -157,7 +165,7 @@ publishing {
publications {
maven(MavenPublication) {
groupId = project.group
artifactId = project.name
artifactId = mavenArtifactId
from components.java
pom {

View file

@ -153,16 +153,17 @@ jobs:
- task: CmdLine@2
inputs:
script: |
@echo on
pushd onnxruntime-java-linux-x64-gpu
jar uf $(Build.BinariesDirectory)\java-artifact\onnxruntime-java-win-x64-gpu\testing.jar libcustom_op_library.so
del /F /Q libcustom_op_library.so
jar uf $(Build.BinariesDirectory)\java-artifact\onnxruntime-java-win-x64-gpu\onnxruntime-$(OnnxRuntimeVersion).jar .
popd
pushd onnxruntime-java-win-x64-gpu
ren onnxruntime-$(OnnxRuntimeVersion).jar onnxruntime-gpu-$(OnnxRuntimeVersion).jar
ren onnxruntime-$(OnnxRuntimeVersion)-javadoc.jar onnxruntime-gpu-$(OnnxRuntimeVersion)-javadoc.jar
ren onnxruntime-$(OnnxRuntimeVersion)-sources.jar onnxruntime-gpu-$(OnnxRuntimeVersion)-sources.jar
ren onnxruntime-$(OnnxRuntimeVersion).pom onnxruntime-gpu-$(OnnxRuntimeVersion).pom
ren onnxruntime-$(OnnxRuntimeVersion).jar onnxruntime_gpu-$(OnnxRuntimeVersion).jar
ren onnxruntime-$(OnnxRuntimeVersion)-javadoc.jar onnxruntime_gpu-$(OnnxRuntimeVersion)-javadoc.jar
ren onnxruntime-$(OnnxRuntimeVersion)-sources.jar onnxruntime_gpu-$(OnnxRuntimeVersion)-sources.jar
ren onnxruntime-$(OnnxRuntimeVersion).pom onnxruntime_gpu_$(OnnxRuntimeVersion).pom
popd
workingDirectory: '$(Build.BinariesDirectory)\java-artifact'
displayName: 'Create final GPU Jar'
@ -211,7 +212,7 @@ jobs:
popd
powershell -Command "Invoke-WebRequest https://oss.sonatype.org/service/local/repositories/releases/content/org/junit/platform/junit-platform-console-standalone/1.6.2/junit-platform-console-standalone-1.6.2.jar -OutFile junit-platform-console-standalone-1.6.2.jar"
powershell -Command "Invoke-WebRequest https://oss.sonatype.org/service/local/repositories/google-releases/content/com/google/protobuf/protobuf-java/3.9.2/protobuf-java-3.9.2.jar -OutFile protobuf-java-3.9.2.jar"
java -DUSE_CUDA=1 -jar junit-platform-console-standalone-1.6.2.jar -cp .;.\test;protobuf-java-3.9.2.jar;onnxruntime-gpu-$(OnnxRuntimeVersion).jar --scan-class-path --fail-if-no-tests --disable-banner
java -DUSE_CUDA=1 -jar junit-platform-console-standalone-1.6.2.jar -cp .;.\test;protobuf-java-3.9.2.jar;onnxruntime_gpu-$(OnnxRuntimeVersion).jar --scan-class-path --fail-if-no-tests --disable-banner
workingDirectory: '$(Build.BinariesDirectory)\final-jar'
- job: Final_Jar_Testing_Linux

View file

@ -216,6 +216,7 @@ jobs:
- task: CmdLine@2
inputs:
script: |
@echo on
pushd onnxruntime-java-linux-x64
jar uf $(Build.BinariesDirectory)\java-artifact\onnxruntime-java-win-x64\testing.jar libcustom_op_library.so
del /F /Q libcustom_op_library.so

View file

@ -9,15 +9,19 @@ steps:
- task: CmdLine@2
inputs:
script: |
echo "Java version"
java --version
@echo on
set NATIVE_FOLDER=$(Build.BinariesDirectory)\${{parameters.artifactName}}\stage\ai\onnxruntime\native\win-x64
mkdir %NATIVE_FOLDER%
echo "Directories created"
copy .\java\build\libs\*.jar $(Build.BinariesDirectory)\${{parameters.artifactName}}
pushd $(Build.BinariesDirectory)\${{parameters.artifactName}}
jar xf onnxruntime-${{parameters.version}}.jar META-INF\maven\ai.onnxruntime\onnxruntime\pom.xml
move META-INF\maven\ai.onnxruntime\onnxruntime\pom.xml onnxruntime-${{parameters.version}}.pom
if ${{parameters.artifactName}} == onnxruntime-java-win-x64 (
set artifact_id=onnxruntime
) else (
set artifact_id=onnxruntime_gpu
)
jar xf onnxruntime-${{parameters.version}}.jar META-INF\maven\com.microsoft.onnxruntime\%artifact_id%\pom.xml
move META-INF\maven\com.microsoft.onnxruntime\%artifact_id%\pom.xml onnxruntime-${{parameters.version}}.pom
rd /s /q META-INF
popd
copy .\${{parameters.buildConfig}}\onnxruntime.pdb %NATIVE_FOLDER%

View file

@ -28,7 +28,7 @@ popd
wget https://oss.sonatype.org/service/local/repositories/releases/content/org/junit/platform/junit-platform-console-standalone/1.6.2/junit-platform-console-standalone-1.6.2.jar -P ./
wget https://oss.sonatype.org/service/local/repositories/google-releases/content/com/google/protobuf/protobuf-java/3.9.2/protobuf-java-3.9.2.jar -P ./
java -DUSE_CUDA=1 -jar ./junit-platform-console-standalone-1.6.2.jar -cp .:./test:./protobuf-java-3.9.2.jar:./onnxruntime-gpu-${VERSION_NUMBER}.jar --scan-class-path --fail-if-no-tests --disable-banner
java -DUSE_CUDA=1 -jar ./junit-platform-console-standalone-1.6.2.jar -cp .:./test:./protobuf-java-3.9.2.jar:./onnxruntime_gpu-${VERSION_NUMBER}.jar --scan-class-path --fail-if-no-tests --disable-banner
EXIT_CODE=$?