This guide walks through building the TensorFlow-ZenDNN plug-in C++ package (ZENTF_v5.2.1_C++_SOURCE_BUILD) from source. The package enables ZenDNN-accelerated inference via the TensorFlow C++ API on AMD CPUs.
| Requirement | Details |
|---|---|
| OS | Any Linux distribution (tested on Ubuntu, RHEL) |
| Conda | Active conda environment |
| TensorFlow | v2.16.0 -- v2.21.0 installed in the environment |
| Bazel | Version matching the .bazelversion in the repo |
| GCC | >= 13.3 |
| Python 3 | Available as python3 |
ZenDNN_TensorFlow_Plugin repository must be cloned:
<workspace>/
└── ZenDNN_TensorFlow_Plugin/ # TensorFlow plug-in repo
pip install tensorflow==2.21.0 # or any version in [2.16.0, 2.21.0]Verify the installation:
python3 -c "import tensorflow as tf; print(tf.__version__)"cd <workspace>/ZenDNN_TensorFlow_Plugin
bazel clean --expunge --async
./configureThe configure script auto-detects your Python environment and TensorFlow installation. It writes TF_HEADER_DIR and TF_SHARED_LIBRARY_DIR into the Bazel configuration, pointing at the pip-installed TensorFlow headers and shared libraries.
bazel build -c opt //tensorflow_plugin:libamdcpu_plugin_cc.so \
--verbose_failures \
--copt=-Wall \
--copt=-Werror \
--spawn_strategy=standaloneThis produces the plug-in shared library at:
bazel-bin/tensorflow_plugin/libamdcpu_plugin_cc.so
Create the output directory and copy the build artifacts:
cd <workspace>
mkdir -p ZENTF_v5.2.1_C++_SOURCE_BUILD/lib-tensorflow-plugins
# Plug-in library
cp ZenDNN_TensorFlow_Plugin/bazel-bin/tensorflow_plugin/libamdcpu_plugin_cc.so \
ZENTF_v5.2.1_C++_SOURCE_BUILD/lib-tensorflow-plugins/
# OpenMP runtime
cp ZenDNN_TensorFlow_Plugin/bazel-bin/tensorflow_plugin/libamdcpu_plugin_cc.so.runfiles/llvm_openmp/libiomp5.so \
ZENTF_v5.2.1_C++_SOURCE_BUILD/lib-tensorflow-plugins/
# Helper scripts and sample code
cp ZenDNN_TensorFlow_Plugin/scripts/c++/zentf_cc_api_setup.sh ZENTF_v5.2.1_C++_SOURCE_BUILD/
cp ZenDNN_TensorFlow_Plugin/scripts/zentf_env_setup.sh ZENTF_v5.2.1_C++_SOURCE_BUILD/
cp ZenDNN_TensorFlow_Plugin/examples/c++/sample_inference.cpp ZENTF_v5.2.1_C++_SOURCE_BUILD/The C++ API requires TensorFlow headers and shared libraries. Download the matching wheel and extract them:
TF_VERSION="2.21.0" # must match the installed version
mkdir -p tf_wheel_tmp
pip download "tensorflow==${TF_VERSION}" --no-deps --only-binary=:all: -d tf_wheel_tmp
unzip tf_wheel_tmp/tensorflow*.whl -d "ZENTF_v5.2.1_C++_SOURCE_BUILD/tensorflow_${TF_VERSION}"
rm -rf tf_wheel_tmpCreate the required symlinks:
cd "ZENTF_v5.2.1_C++_SOURCE_BUILD/tensorflow_${TF_VERSION}/tensorflow"
ln -s libtensorflow_cc.so.2 libtensorflow_cc.so
ln -s libtensorflow_framework.so.2 libtensorflow_framework.so
cd <workspace>cd <workspace>/ZENTF_v5.2.1_C++_SOURCE_BUILD
# Sets TF_CC_API_ZENDNN_ROOT, LIBRARY_PATH, LD_LIBRARY_PATH,
# and creates the libomp.so.5 symlink.
source zentf_cc_api_setup.sh
# Enables ZenDNN plug-in and sets recommended performance tuning variables
# (KMP, OMP, ZENDNNL_MATMUL_ALGO, etc.).
source zentf_env_setup.shNote: The
zentf_env_setup.shships with OMP defaults tuned for AMD Turin. AdjustOMP_NUM_THREADSand related variables to match your hardware.
Please follow steps in Build C++ inference application to build and run the sample inference application.
| Issue | Resolution |
|---|---|
./configure fails to find TensorFlow |
Ensure TensorFlow is installed in the active conda env, or set TF_HEADER_DIR / TF_SHARED_LIBRARY_DIR manually. |
| Bazel version mismatch | Check .bazelversion in the repo and install the required Bazel version. |
libtensorflow_cc.so: cannot open shared object file |
Run source zentf_cc_api_setup.sh and verify LD_LIBRARY_PATH includes the TensorFlow library directory. |
Linker errors during g++ compilation |
Ensure the -rpath and -L flags point to the correct directory containing the TensorFlow .so files. |
| Poor inference performance | Review and tune OMP_NUM_THREADS, KMP_AFFINITY, and ZENDNNL_MATMUL_ALGO in zentf_env_setup.sh for your CPU. |