Skip to content

Commit

Permalink
[tvm4j] fix java build (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhliu authored and tqchen committed Jul 22, 2018
1 parent ad28f5c commit efe2f6a
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 247 deletions.
21 changes: 10 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,20 @@ cyclean:

# JVM build rules
ifeq ($(OS),Windows_NT)
JVM_PKG_PROFILE := windows
SHARED_LIBRARY_SUFFIX := dll
JVM_PKG_PROFILE := windows
SHARED_LIBRARY_SUFFIX := dll
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
JVM_PKG_PROFILE := osx-x86_64
SHARED_LIBRARY_SUFFIX := dylib
else
JVM_PKG_PROFILE := linux-x86_64
SHARED_LIBRARY_SUFFIX := so
endif
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
JVM_PKG_PROFILE := osx-x86_64
SHARED_LIBRARY_SUFFIX := dylib
else
JVM_PKG_PROFILE := linux-x86_64
SHARED_LIBRARY_SUFFIX := so
endif
endif

JVM_TEST_ARGS := $(if $(JVM_TEST_ARGS),$(JVM_TEST_ARGS),-DskipTests -Dcheckstyle.skip=true)
JVM_PKG_PROFILE := $(JVM_PKG_PROFILE)-gpu

jvmpkg:
(cd $(ROOTDIR)/jvm; \
Expand Down
2 changes: 1 addition & 1 deletion jvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ make jvmpkg
(Optional) run unit test by

```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,
Expand Down
55 changes: 0 additions & 55 deletions jvm/assembly/linux-x86_64-cpu/pom.xml

This file was deleted.

35 changes: 0 additions & 35 deletions jvm/assembly/linux-x86_64-gpu/src/main/assembly/assembly.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</parent>

<groupId>ml.dmlc.tvm</groupId>
<artifactId>tvm4j-full-linux-x86_64-gpu</artifactId>
<artifactId>tvm4j-full-linux-x86_64</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TVM4J Package - Full Linux-x86_64 GPU</name>
<name>TVM4J Package - Full Linux-x86_64</name>
<packaging>jar</packaging>

<dependencies>
Expand All @@ -24,7 +24,7 @@
</dependency>
<dependency>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>libtvm4j-linux-x86_64-gpu</artifactId>
<artifactId>libtvm4j-linux-x86_64</artifactId>
<version>${project.version}</version>
<type>so</type>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<useProjectArtifact>false</useProjectArtifact>
<useStrictFiltering>false</useStrictFiltering>
<includes>
<include>ml.dmlc.tvm:libtvm4j-linux-x86_64-cpu:so</include>
<include>ml.dmlc.tvm:libtvm4j-linux-x86_64:so</include>
</includes>
</dependencySet>
</dependencySets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</parent>

<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>
<name>TVM4J Package - Full OSX-x86_64 CPU-only</name>
<name>TVM4J Package - Full OSX-x86_64</name>
<packaging>jar</packaging>

<dependencies>
Expand All @@ -24,7 +24,7 @@
</dependency>
<dependency>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>libtvm4j-osx-x86_64-cpu</artifactId>
<artifactId>libtvm4j-osx-x86_64</artifactId>
<version>${project.version}</version>
<type>jnilib</type>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<useProjectArtifact>false</useProjectArtifact>
<useStrictFiltering>false</useStrictFiltering>
<includes>
<include>ml.dmlc.tvm:libtvm4j-osx-x86_64-cpu:jnilib</include>
<include>ml.dmlc.tvm:libtvm4j-osx-x86_64:jnilib</include>
</includes>
</dependencySet>
</dependencySets>
Expand Down
14 changes: 4 additions & 10 deletions jvm/assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@

<profiles>
<profile>
<id>osx-x86_64-cpu</id>
<id>osx-x86_64</id>
<modules>
<module>osx-x86_64-cpu</module>
<module>osx-x86_64</module>
</modules>
</profile>
<profile>
<id>linux-x86_64-cpu</id>
<id>linux-x86_64</id>
<modules>
<module>linux-x86_64-cpu</module>
</modules>
</profile>
<profile>
<id>linux-x86_64-gpu</id>
<modules>
<module>linux-x86_64-gpu</module>
<module>linux-x86_64</module>
</modules>
</profile>
<profile>
Expand Down
7 changes: 7 additions & 0 deletions jvm/conf/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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
28 changes: 17 additions & 11 deletions jvm/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@

<profiles>
<profile>
<id>osx-x86_64-cpu</id>
<id>osx-x86_64</id>
<properties>
<platform>osx-x86_64-cpu</platform>
<platform>osx-x86_64</platform>
<libtvm.so.filename>libtvm_runtime.dylib</libtvm.so.filename>
</properties>
</profile>
<profile>
<id>linux-x86_64-cpu</id>
<id>linux-x86_64</id>
<properties>
<platform>linux-x86_64-cpu</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>
<platform>linux-x86_64</platform>
<libtvm.so.filename>libtvm_runtime.so</libtvm.so.filename>
</properties>
</profile>
Expand Down Expand Up @@ -92,6 +85,7 @@
<argLine>
-Djava.library.path=${project.parent.basedir}/native/${platform}/target
-Dlibtvm.so.path=${project.parent.basedir}/../build/${libtvm.so.filename}
-Dlog4j.configuration=file://${project.parent.basedir}/conf/log4j.properties
</argLine>
</configuration>
<executions>
Expand Down Expand Up @@ -119,5 +113,17 @@
<version>4.11</version>
<scope>test</scope>
</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>
</project>
10 changes: 2 additions & 8 deletions jvm/core/src/main/java/ml/dmlc/tvm/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,8 @@ private static void tryLoadLibraryOS(String libname) throws UnsatisfiedLinkError
* @throws UnsatisfiedLinkError if loading fails
*/
private static void tryLoadLibraryXPU(String libname, String arch) throws UnsatisfiedLinkError {
try {
// try gpu first
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));
}
System.err.println(String.format("Try loading %s-%s from native path.", libname, arch));
System.loadLibrary(String.format("%s-%s", libname, arch));
}

// helper function definitions
Expand Down
12 changes: 10 additions & 2 deletions jvm/core/src/test/java/ml/dmlc/tvm/ModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.Assert.*;

import java.io.File;
import java.util.Random;

public class ModuleTest {
private final Logger logger = LoggerFactory.getLogger(ModuleTest.class);
private static String loadingDir;

@BeforeClass
Expand Down Expand Up @@ -60,12 +64,16 @@ public void test_load_add_func_cpu() {
public void test_load_add_func_gpu() {
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 faddDev = Module.load(loadingDir + File.separator + "add_gpu.ptx");
fadd.importModule(faddDev);

TVMContext ctx = new TVMContext("gpu", 0);

final int dim = 100;
long[] shape = new long[]{dim};
NDArray arr = NDArray.empty(shape, ctx);
Expand Down
3 changes: 3 additions & 0 deletions jvm/core/src/test/scripts/test_add_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from tvm.contrib import cc, util

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")
A = tvm.placeholder((n,), name='A')
B = tvm.placeholder((n,), name='B')
Expand Down
Loading

0 comments on commit efe2f6a

Please sign in to comment.