zentf Plugin with Java API of TensorFlow - 57300

ZenDNN User Guide (57300)

Document ID
57300
Release Date
2025-08-18
Revision
5.1 English

This section provides the information you need to set up the zentf plugin for TensorFlow Java. This setup enables Java applications to exploit zentf in DNN inference using TensorFlow.

Prerequisites

Before building the project, ensure you have installed the following:

  • Maven 3.6 or higher
  • Java Development Kit (JDK) 11 or higher
  • Environment variable JAVA_HOME set to your JDK installation path
  • GLIBC v2.33 or higher

Note that you may need to set JAVA_HOME to the appropriate path to build this project with Maven. For example, set JAVA_HOME to the path: /usr/lib/jvm/java-<java-version>-openjdk-amd64.

For example:

  • For Ubuntu OS:
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
  • For RHEL OS:
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
    export PATH=$JAVA_HOME/bin:$PATH
Note: We assume users have installed Java-v11. Check the version running on your machine by navigating to: /usr/lib/jvm and set it accordingly.

Set up zentf Plugin for TensorFlow Java

Currently (as of v1.0.0 of TensorFlow Java), plugins are not supported. Hence, you cannot use TensorFlow Java builds available publicly.

Complete the following steps to enable the zentf plugin for TensorFlow-Java:

  1. Build TensorFlow-Java from source with changes for plugin.
  2. Set up zentf plugin.
Note: TensorFlow Java v1.0.0 supports TensorFlow v2.16.2.

Build TensorFlow Java from Source with Changes for Plugin

Run the script: build_tf_java.sh to get the source code of TensorFlow Java, and apply the source code changes to support the plugin. Build and install TensorFlow Java from source.

We reproduce the following steps from build_tf_java.sh for easy reference.

git clone https://github.com/tensorflow/java.git tf_java.git
wget https://patch-diff.githubusercontent.com/raw/tensorflow/java/pull/605.patch
cd $current_dir/tf_java
git apply ../605.patch
mvn clean install
cd <Path to zentf plugin parent folder>/ZenDNN_TensorFlow_Plugin/scripts/java
bash build_tf_java.sh

Set up the zentf Plugin

  1. Download the zentf C++ plugin package v5.1.0 from the AMD Developer Forum.
  2. Set the environment variable LD_LIBRARY_PATH to the zentf plugin libraries path.
    unzip ZENTF_v5.1.0_C++_API.zip
    export LD_LIBRARY_PATH=<Path to zentf C++ parent folder>/ZENTF_v5.1.0_C++_API/lib-tensorflow-plugins
  3. Source the script to set the ZenDNN specific environment variables as shown here:
    cd <Path to zentf C++ parent folder>/ZENTF_v5.1.0_C++_API
    source zentf_env_setup.sh java

Example

To try a setup on an example inference application, refer to the README file available at the ./examples/java folder.

Here is an example of how to run the WideDeepLarge model.

  1. Download the model.
    wget https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_8/wide_deep_fp32_pretrained_model.pb
    cd <Path to zentf plugin parent folder>/ZenDNN_TensorFlow_Plugin/examples/java
    mvn clean package
  2. Run the model.
    java -cp target/tensorflow-benchmark-0.1-jar-with-dependencies.jar org.tensorflow.benchmark.RunWideDeeplarge <path to wide deep large .pb model> <batch size>
  3. On successful execution, the output would be as shown here:
    Batch Size = <batch size>
    Output:
    0
    End of execution.