Commit efe2f6a2 by Yizhi Liu Committed by Tianqi Chen

[tvm4j] fix java build (#1471)

parent ad28f5ca
......@@ -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; \
......
......@@ -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,
......
<?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 @@
</parent>
<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>
<name>TVM4J Package - Full Linux-x86_64 CPU-only</name>
<name>TVM4J Package - Full Linux-x86_64</name>
<packaging>jar</packaging>
<dependencies>
......@@ -24,7 +24,7 @@
</dependency>
<dependency>
<groupId>ml.dmlc.tvm</groupId>
<artifactId>libtvm4j-linux-x86_64-cpu</artifactId>
<artifactId>libtvm4j-linux-x86_64</artifactId>
<version>${project.version}</version>
<type>so</type>
</dependency>
......
......@@ -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>
......
......@@ -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>
......@@ -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>
......
......@@ -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>
......
......@@ -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>
......
# 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 @@
<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>
......@@ -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>
......@@ -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>
......@@ -155,14 +155,8 @@ final class Base {
* @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
......
......@@ -19,12 +19,16 @@ package ml.dmlc.tvm;
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
......@@ -60,12 +64,16 @@ public class ModuleTest {
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);
......
......@@ -4,6 +4,9 @@ import tvm
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')
......
<?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 @@
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>libtvm4j-linux-x86_64-cpu</artifactId>
<artifactId>libtvm4j-linux-x86_64</artifactId>
<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>
<packaging>so</packaging>
......
......@@ -10,9 +10,9 @@
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>libtvm4j-osx-x86_64-cpu</artifactId>
<artifactId>libtvm4j-osx-x86_64</artifactId>
<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>
<packaging>jnilib</packaging>
......
......@@ -17,21 +17,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>
</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