This folder contains the Java interface for TVM runtime. It brings TVM runtime to Java virtual machine.
- It enables you to construct NDArray from Java native array and vice versa.
- You can register and convert Java native functions to TVM functions.
- It enables you to load shared libraries created by Python and C++.
- It provides a simple interface for RPC server and client.
## Installation
### Requirements
- JDK 1.6+. Oracle JDK and OpenJDK are well tested.
- Maven 3 for build.
### Modules
TVM4J contains three modules:
- core
* It contains all the Java interfaces.
- native
* The JNI native library is compiled in this module. It does not link TVM runtime library (libtvm\_runtime.so for Linux and libtvm\_runtime.dylib for OSX). Instead, you have to specify `libtvm.so.path` which contains the TVM runtime library as Java system property.
- assembly
* It assembles Java interfaces (core), JNI library (native) and TVM runtime library together. The simplest way to integrate tvm4j in your project is to rely on this module. It automatically extracts the native library to a tempfile and load it.
### Build
First please refer to [Installation Guide](http://docs.tvmlang.org/how_to/install.html) and build runtime shared library from the C++ codes (libtvm\_runtime.so for Linux and libtvm\_runtime.dylib for OSX).
Then you can compile tvm4j by
```bash
make jvmpkg
```
(Optional) run unit test by
```bash
make jvmpkg JVM_TEST_ARGS="-DskipTests=false"
```
After it is compiled and packaged, you can install tvm4j in your local maven repository,
```bash
make jvminstall
```
## Convert and Register Java Function as TVM Function
It is easy to define a Java function and call it from TVM. The following snippet demonstrate how to concatenate Java strings.
There are two ways to start an RPC server on JVM. A standalone server can be started by
```java
Serverserver=newServer(port);
server.start();
```
This will open a socket and wait for remote requests. You can use Java, Python, or any other frontend to make an RPC call. Here's an example for calling remote function `test.rpc.strcat` in Java.
Another way is to start a proxy, make server and client communicate with each other through the proxy. The following snippet shows how to start a server which connects to a proxy.
You can also use `StandaloneServerProcessor` and `ConnectProxyServerProcessor` to build your own RPC server. Refer to [Android RPC Server](https://github.com/dmlc/tvm/blob/master/apps/android_rpc/app/src/main/java/ml/dmlc/tvm/tvmrpc/RPCProcessor.java) for more details.