Commit efe2f6a2 by Yizhi Liu Committed by Tianqi Chen

[tvm4j] fix java build (#1471)

parent ad28f5ca
...@@ -99,7 +99,6 @@ else ...@@ -99,7 +99,6 @@ else
endif endif
JVM_TEST_ARGS := $(if $(JVM_TEST_ARGS),$(JVM_TEST_ARGS),-DskipTests -Dcheckstyle.skip=true) JVM_TEST_ARGS := $(if $(JVM_TEST_ARGS),$(JVM_TEST_ARGS),-DskipTests -Dcheckstyle.skip=true)
JVM_PKG_PROFILE := $(JVM_PKG_PROFILE)-gpu
jvmpkg: jvmpkg:
(cd $(ROOTDIR)/jvm; \ (cd $(ROOTDIR)/jvm; \
......
...@@ -38,7 +38,7 @@ make jvmpkg ...@@ -38,7 +38,7 @@ make jvmpkg
(Optional) run unit test by (Optional) run unit test by
```bash ```bash
make jvmpkg JVM_TEST_ARGS="-DskipTests=false" sh tests/scripts/task_java_unittest.sh
``` ```
After it is compiled and packaged, you can install tvm4j in your local maven repository, After it is compiled and packaged, you can install tvm4j in your local maven repository,
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>tvm4j-full-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>tvm4j-full-linux-x86_64-gpu</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TVM4J Package - Full Linux-x86_64 GPU</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>tvm4j-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>libtvm4j-linux-x86_64-gpu</artifactId>
<version>${project.version}</version>
<type>so</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly>
<id>full</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>../../../build/libtvm_runtime.so</source>
<outputDirectory>lib/native</outputDirectory>
<fileMode>0644</fileMode>
</file>
</files>
<dependencySets>
<dependencySet>
<includes>
<include>*:*:jar</include>
</includes>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
<dependencySet>
<outputDirectory>lib/native</outputDirectory>
<outputFileNameMapping>libtvm4j.so</outputFileNameMapping>
<unpack>false</unpack>
<useProjectArtifact>false</useProjectArtifact>
<useStrictFiltering>false</useStrictFiltering>
<includes>
<include>ml.dmlc.tvm:libtvm4j-linux-x86_64-gpu:so</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
</parent> </parent>
<groupId>ml.dmlc.tvm</groupId> <groupId>ml.dmlc.tvm</groupId>
<artifactId>tvm4j-full-linux-x86_64-cpu</artifactId> <artifactId>tvm4j-full-linux-x86_64</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>TVM4J Package - Full Linux-x86_64 CPU-only</name> <name>TVM4J Package - Full Linux-x86_64</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>ml.dmlc.tvm</groupId> <groupId>ml.dmlc.tvm</groupId>
<artifactId>libtvm4j-linux-x86_64-cpu</artifactId> <artifactId>libtvm4j-linux-x86_64</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>so</type> <type>so</type>
</dependency> </dependency>
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<useProjectArtifact>false</useProjectArtifact> <useProjectArtifact>false</useProjectArtifact>
<useStrictFiltering>false</useStrictFiltering> <useStrictFiltering>false</useStrictFiltering>
<includes> <includes>
<include>ml.dmlc.tvm:libtvm4j-linux-x86_64-cpu:so</include> <include>ml.dmlc.tvm:libtvm4j-linux-x86_64:so</include>
</includes> </includes>
</dependencySet> </dependencySet>
</dependencySets> </dependencySets>
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
</parent> </parent>
<groupId>ml.dmlc.tvm</groupId> <groupId>ml.dmlc.tvm</groupId>
<artifactId>tvm4j-full-osx-x86_64-cpu</artifactId> <artifactId>tvm4j-full-osx-x86_64</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>TVM4J Package - Full OSX-x86_64 CPU-only</name> <name>TVM4J Package - Full OSX-x86_64</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>ml.dmlc.tvm</groupId> <groupId>ml.dmlc.tvm</groupId>
<artifactId>libtvm4j-osx-x86_64-cpu</artifactId> <artifactId>libtvm4j-osx-x86_64</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>jnilib</type> <type>jnilib</type>
</dependency> </dependency>
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<useProjectArtifact>false</useProjectArtifact> <useProjectArtifact>false</useProjectArtifact>
<useStrictFiltering>false</useStrictFiltering> <useStrictFiltering>false</useStrictFiltering>
<includes> <includes>
<include>ml.dmlc.tvm:libtvm4j-osx-x86_64-cpu:jnilib</include> <include>ml.dmlc.tvm:libtvm4j-osx-x86_64:jnilib</include>
</includes> </includes>
</dependencySet> </dependencySet>
</dependencySets> </dependencySets>
......
...@@ -18,21 +18,15 @@ ...@@ -18,21 +18,15 @@
<profiles> <profiles>
<profile> <profile>
<id>osx-x86_64-cpu</id> <id>osx-x86_64</id>
<modules> <modules>
<module>osx-x86_64-cpu</module> <module>osx-x86_64</module>
</modules> </modules>
</profile> </profile>
<profile> <profile>
<id>linux-x86_64-cpu</id> <id>linux-x86_64</id>
<modules> <modules>
<module>linux-x86_64-cpu</module> <module>linux-x86_64</module>
</modules>
</profile>
<profile>
<id>linux-x86_64-gpu</id>
<modules>
<module>linux-x86_64-gpu</module>
</modules> </modules>
</profile> </profile>
<profile> <profile>
......
# for development debugging
log4j.rootLogger = info, stdout
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n
...@@ -17,23 +17,16 @@ ...@@ -17,23 +17,16 @@
<profiles> <profiles>
<profile> <profile>
<id>osx-x86_64-cpu</id> <id>osx-x86_64</id>
<properties> <properties>
<platform>osx-x86_64-cpu</platform> <platform>osx-x86_64</platform>
<libtvm.so.filename>libtvm_runtime.dylib</libtvm.so.filename> <libtvm.so.filename>libtvm_runtime.dylib</libtvm.so.filename>
</properties> </properties>
</profile> </profile>
<profile> <profile>
<id>linux-x86_64-cpu</id> <id>linux-x86_64</id>
<properties> <properties>
<platform>linux-x86_64-cpu</platform> <platform>linux-x86_64</platform>
<libtvm.so.filename>libtvm_runtime.so</libtvm.so.filename>
</properties>
</profile>
<profile>
<id>linux-x86_64-gpu</id>
<properties>
<platform>linux-x86_64-gpu</platform>
<libtvm.so.filename>libtvm_runtime.so</libtvm.so.filename> <libtvm.so.filename>libtvm_runtime.so</libtvm.so.filename>
</properties> </properties>
</profile> </profile>
...@@ -92,6 +85,7 @@ ...@@ -92,6 +85,7 @@
<argLine> <argLine>
-Djava.library.path=${project.parent.basedir}/native/${platform}/target -Djava.library.path=${project.parent.basedir}/native/${platform}/target
-Dlibtvm.so.path=${project.parent.basedir}/../build/${libtvm.so.filename} -Dlibtvm.so.path=${project.parent.basedir}/../build/${libtvm.so.filename}
-Dlog4j.configuration=file://${project.parent.basedir}/conf/log4j.properties
</argLine> </argLine>
</configuration> </configuration>
<executions> <executions>
...@@ -119,5 +113,17 @@ ...@@ -119,5 +113,17 @@
<version>4.11</version> <version>4.11</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -155,14 +155,8 @@ final class Base { ...@@ -155,14 +155,8 @@ final class Base {
* @throws UnsatisfiedLinkError if loading fails * @throws UnsatisfiedLinkError if loading fails
*/ */
private static void tryLoadLibraryXPU(String libname, String arch) throws UnsatisfiedLinkError { private static void tryLoadLibraryXPU(String libname, String arch) throws UnsatisfiedLinkError {
try { System.err.println(String.format("Try loading %s-%s from native path.", libname, arch));
// try gpu first System.loadLibrary(String.format("%s-%s", libname, arch));
System.err.println(String.format("Try loading %s-%s-gpu from native path.", libname, arch));
System.loadLibrary(String.format("%s-%s-gpu", libname, arch));
} catch (UnsatisfiedLinkError e) {
System.err.println(String.format("Try loading %s-%s-cpu from native path.", libname, arch));
System.loadLibrary(String.format("%s-%s-cpu", libname, arch));
}
} }
// helper function definitions // helper function definitions
......
...@@ -19,12 +19,16 @@ package ml.dmlc.tvm; ...@@ -19,12 +19,16 @@ package ml.dmlc.tvm;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.File; import java.io.File;
import java.util.Random; import java.util.Random;
public class ModuleTest { public class ModuleTest {
private final Logger logger = LoggerFactory.getLogger(ModuleTest.class);
private static String loadingDir; private static String loadingDir;
@BeforeClass @BeforeClass
...@@ -60,12 +64,16 @@ public class ModuleTest { ...@@ -60,12 +64,16 @@ public class ModuleTest {
public void test_load_add_func_gpu() { public void test_load_add_func_gpu() {
final Random RND = new Random(0); final Random RND = new Random(0);
TVMContext ctx = new TVMContext("gpu", 0);
if (!ctx.exist()) {
logger.warn("GPU does not exist. Skip the test.");
return;
}
Module fadd = Module.load(loadingDir + File.separator + "add_gpu.so"); Module fadd = Module.load(loadingDir + File.separator + "add_gpu.so");
Module faddDev = Module.load(loadingDir + File.separator + "add_gpu.ptx"); Module faddDev = Module.load(loadingDir + File.separator + "add_gpu.ptx");
fadd.importModule(faddDev); fadd.importModule(faddDev);
TVMContext ctx = new TVMContext("gpu", 0);
final int dim = 100; final int dim = 100;
long[] shape = new long[]{dim}; long[] shape = new long[]{dim};
NDArray arr = NDArray.empty(shape, ctx); NDArray arr = NDArray.empty(shape, ctx);
......
...@@ -4,6 +4,9 @@ import tvm ...@@ -4,6 +4,9 @@ import tvm
from tvm.contrib import cc, util from tvm.contrib import cc, util
def test_add(target_dir): def test_add(target_dir):
if not tvm.module.enabled("cuda"):
print("skip %s because cuda is not enabled..." % __file__)
return
n = tvm.var("n") n = tvm.var("n")
A = tvm.placeholder((n,), name='A') A = tvm.placeholder((n,), name='A')
B = tvm.placeholder((n,), name='B') B = tvm.placeholder((n,), name='B')
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>tvm4j-native-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>libtvm4j-linux-x86_64-gpu</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TVM4J Package - Native Linux-x86_64 GPU</name>
<url>http://maven.apache.org</url>
<packaging>so</packaging>
<dependencies>
<dependency>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>tvm4j-core</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<!-- trigger javah -->
<javahOS>linux</javahOS>
<compilerProvider>generic-classic</compilerProvider>
<compilerExecutable>${cxx}</compilerExecutable>
<linkerExecutable>${cxx}</linkerExecutable>
<sources>
<source>
<directory>../src/main/native</directory>
<fileNames>
<fileName>ml_dmlc_tvm_native_c_api.cc</fileName>
</fileNames>
</source>
</sources>
<compilerStartOptions>
<compilerStartOption>-std=c++0x</compilerStartOption>
</compilerStartOptions>
<compilerEndOptions>
<compilerEndOption>-I../../../include</compilerEndOption>
<compilerEndOption>${cflags}</compilerEndOption>
</compilerEndOptions>
<linkerStartOptions>
<linkerStartOption>-shared</linkerStartOption>
</linkerStartOptions>
<linkerEndOptions>
<linkerEndOption>${ldflags}</linkerEndOption>
</linkerEndOptions>
</configuration>
<executions>
<execution>
<id>javah</id>
<phase>generate-sources</phase>
<configuration>
<javahOS>linux</javahOS>
<javahProvider>default</javahProvider>
<javahOutputDirectory>${project.build.directory}/custom-javah</javahOutputDirectory>
<workingDirectory>${basedir}</workingDirectory>
<javahOutputFileName>ml_dmlc_tvm_native_c_api.h</javahOutputFileName>
<javahClassNames>
<javahClassName>ml.dmlc.tvm.LibInfo</javahClassName>
</javahClassNames>
</configuration>
<goals>
<goal>javah</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>libtvm4j-linux-x86_64-cpu</artifactId> <artifactId>libtvm4j-linux-x86_64</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>TVM4J Package - Native Linux-x86_64 CPU-only</name> <name>TVM4J Package - Native Linux-x86_64</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<packaging>so</packaging> <packaging>so</packaging>
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>libtvm4j-osx-x86_64-cpu</artifactId> <artifactId>libtvm4j-osx-x86_64</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>TVM4J Package - Native OSX-x86_64 CPU-only</name> <name>TVM4J Package - Native OSX-x86_64</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<packaging>jnilib</packaging> <packaging>jnilib</packaging>
......
...@@ -17,21 +17,15 @@ ...@@ -17,21 +17,15 @@
<profiles> <profiles>
<profile> <profile>
<id>osx-x86_64-cpu</id> <id>osx-x86_64</id>
<modules> <modules>
<module>osx-x86_64-cpu</module> <module>osx-x86_64</module>
</modules> </modules>
</profile> </profile>
<profile> <profile>
<id>linux-x86_64-cpu</id> <id>linux-x86_64</id>
<modules> <modules>
<module>linux-x86_64-cpu</module> <module>linux-x86_64</module>
</modules>
</profile>
<profile>
<id>linux-x86_64-gpu</id>
<modules>
<module>linux-x86_64-gpu</module>
</modules> </modules>
</profile> </profile>
</profiles> </profiles>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment