Java bindings for In-Process Triton Server API — NVIDIA Triton Inference Server (original) (raw)

The Triton Inference Server uses Java CPPto create bindings around Tritonserver to create Java API.

The API is documented intritonserver.java. Alternatively, the user can refer to the web version API docsgenerated from tritonserver.java.Note: Currently, tritonserver.java contains bindings for both the In-process C-APIand the bindings for C-API Wrapper. More information about the developer_tools/server C-API wrapper can be found in the developer_tools repository.

A simple example using the Java API can be found inSamples folderwhich includes Simple.java which is similar tosimple.cc. Please refer tosample usage documentationto learn about how to build and run Simple.java.

In the QA folder, folders starting with L0_java include Java API tests. These can be useful references for getting started, such as theResNet50 test.

Java API setup instructions#

To use the Tritonserver Java API, you will need to have the Tritonserver library and dependencies installed in your environment. There are two ways to do this:

  1. Use a Tritonserver docker container with
    1. .jar Java bindings to C API (recommended)
    2. maven and build bindings yourself
  2. Build Triton from your environment without Docker (not recommended)

Run Tritonserver container and install dependencies#

To set up your environment with Triton Java API, please follow the following steps:

  1. First run Docker container:

$ docker run -it --gpus=all -v ${pwd}:/workspace nvcr.io/nvidia/tritonserver:-py3 bash

  1. Install jdk:

$ apt update && apt install -y openjdk-11-jdk

  1. Install maven (only if you want to build the bindings yourself):

$ cd /opt/tritonserver $ wget https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz $ tar zxvf apache-maven-3.8.4-bin.tar.gz $ export PATH=/opt/tritonserver/apache-maven-3.8.4/bin:$PATH

Run Java program with Java bindings Jar#

After ensuring that Tritonserver and dependencies are installed, you can run your Java program with the Java bindings with the following steps:

  1. Place Java bindings into your environment. You can do this by either:
    a. Building Java API bindings with provided build script:

Clone Triton client repo. Recommended client repo tag is: main

$ git clone --single-branch --depth=1 -b
https://github.com/triton-inference-server/client.git clientrepo

Run build script

For In-Process C-API Java Bindings

$ source clientrepo/src/java-api-bindings/scripts/install_dependencies_and_build.sh

For C-API Wrapper (Triton with C++ bindings) Java Bindings

$ source clientrepo/src/java-api-bindings/scripts/install_dependencies_and_build.sh --enable-developer-tools-server
This will install the Java bindings to /workspace/install/java-api-bindings/tritonserver-java-bindings.jar
or
b. Copying “Uber Jar” from Triton SDK container to your environment
$ id=$(docker run -dit nvcr.io/nvidia/tritonserver:-py3-sdk bash)
$ docker cp ${id}:/workspace/install/java-api-bindings/tritonserver-java-bindings.jar /tritonserver-java-bindings.jar
$ docker stop ${id}
Note: tritonserver-java-bindings.jar only includes the In-Process Java Bindings. To use the C-API Wrapper Java Bindings, please use the build script. 2. Use the built “Uber Jar” that contains the Java bindings
$ java -cp /tritonserver-java-bindings.jar

Build Java bindings and run Java program with Maven#

If you want to make changes to the Java bindings, then you can use Maven to build yourself. You can refer to part 1.a of Run Java program with Java bindings Jar to also build the jar yourself without any modifications to the Tritonserver bindings in JavaCPP-presets. You can do this using the following steps:

  1. Create the JNI binaries in your local repository (/root/.m2/repository) with javacpp-presets/tritonserver. For C-API Wrapper Java bindings (Triton with C++ bindings), you need to install some build specific dependencies including cmake and rapidjson. Refer to java installation scriptfor dependencies you need to install and modifications you need to make for your container. After installing dependencies, you can build the tritonserver project on javacpp-presets:

$ git clone https://github.com/bytedeco/javacpp-presets.git $ cd javacpp-presets $ mvn clean install --projects .,tritonserver $ mvn clean install -f platform --projects ../tritonserver/platform -Djavacpp.platform=linux-x86_64

  1. Create your custom *.pom file for Maven. Please refer tosamples/simple/pom.xml as reference for how to create your pom file.
  2. After creating your pom.xml file you can build your application with:

$ mvn compile exec:java -Djavacpp.platform=linux-x86_64 -Dexec.args=""