Skip to content

Commit

Permalink
Merge pull request #4 from ika-rwth-aachen/v2.10+
Browse files Browse the repository at this point in the history
Support v2.11.0, v2.10.1, v2.10.0
  • Loading branch information
lreiher authored Jan 24, 2023
2 parents 2d199e0 + 4ebcc84 commit 41665bb
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 28 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ DEFAULT_ARCH := $(shell dpkg --print-architecture)
ARCH := $(if $(ARCH),$(ARCH),$(DEFAULT_ARCH))

# defaults
DEFAULT_TF_VERSION := 2.9.3
TF_VERSIONS := 2.9.3 2.9.2 2.9.1 2.9.0 2.8.4 2.8.3 2.8.2 2.8.1 2.8.0 2.7.4 2.7.3 2.7.2 2.7.1 2.7.0 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.3 2.5.2 2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.3 2.2.2 2.2.1 2.2.0 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0
DEFAULT_TF_VERSION := 2.11.0
TF_VERSIONS := 2.11.0 2.10.1 2.10.0 2.9.3 2.9.2 2.9.1 2.9.0 2.8.4 2.8.3 2.8.2 2.8.1 2.8.0 2.7.4 2.7.3 2.7.2 2.7.1 2.7.0 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.3 2.5.2 2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.3 2.2.2 2.2.1 2.2.0 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0
DEFAULT_JOBS := $(shell nproc)
DEFAULT_GPU := 1
ifeq ($(ARCH), arm64)
Expand Down Expand Up @@ -130,15 +130,15 @@ clean-images: clean-official-devel-images clean-cpp-images clean-libtensorflow-c
$(MAKEFILE_DIR)/scripts/$@.sh

.PHONY: 4-test-libtensorflow-cc
4-test-libtensorflow-cc: 2-build-cpp-image
4-test-libtensorflow-cc:
$(MAKEFILE_DIR)/scripts/$@.sh

.PHONY: 5-print-versions
5-print-versions: 2-build-cpp-image
5-print-versions:
$(MAKEFILE_DIR)/scripts/$@.sh

.PHONY: 6-push-image
6-push-image: 2-build-cpp-image
6-push-image:
$(MAKEFILE_DIR)/scripts/$@.sh

# ----- MULTI VERSION RULES ----------------------------------------------------
Expand Down
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ docker run --rm \
rwthika/tensorflow-cc:latest \
./build-and-run.sh

# Hello from TensorFlow C++ 2.9.3!
# Hello from TensorFlow C++ 2.11.0!
#
# A =
# 1 2
Expand All @@ -65,16 +65,16 @@ The pre-built `libtensorflow_cc.so` library and accompanying headers are package
#### GPU

```bash
wget https://github.com/ika-rwth-aachen/libtensorflow_cc/releases/download/v2.9.3/libtensorflow-cc_2.9.3-gpu_$(dpkg --print-architecture).deb
sudo dpkg -i libtensorflow-cc_2.9.3-gpu_$(dpkg --print-architecture).deb
wget https://github.com/ika-rwth-aachen/libtensorflow_cc/releases/download/v2.11.0/libtensorflow-cc_2.11.0-gpu_$(dpkg --print-architecture).deb
sudo dpkg -i libtensorflow-cc_2.11.0-gpu_$(dpkg --print-architecture).deb
ldconfig
```

#### CPU

```bash
wget https://github.com/ika-rwth-aachen/libtensorflow_cc/releases/download/v2.9.3/libtensorflow-cc_2.9.3_$(dpkg --print-architecture).deb
sudo dpkg -i libtensorflow-cc_2.9.3_$(dpkg --print-architecture).deb
wget https://github.com/ika-rwth-aachen/libtensorflow_cc/releases/download/v2.11.0/libtensorflow-cc_2.11.0_$(dpkg --print-architecture).deb
sudo dpkg -i libtensorflow-cc_2.11.0_$(dpkg --print-architecture).deb
ldconfig
```

Expand All @@ -101,15 +101,18 @@ The amd64 images are based on the [official TensorFlow Docker images](https://hu

| TensorFlow Version | CPU/GPU | Architecture | Image:Tag |
| :---: | :---: | :---: | --- |
| 2.9.3 | GPU | amd64, arm64 | `rwthika/tensorflow-cc:latest-gpu` |
| 2.9.3 | CPU | amd64, arm64 | `rwthika/tensorflow-cc:latest` |
| 2.11.0 | GPU | amd64, arm64 | `rwthika/tensorflow-cc:latest-gpu` |
| 2.11.0 | CPU | amd64, arm64 | `rwthika/tensorflow-cc:latest` |

<details>
<summary><i>All TensorFlow Versions (GPU)</i></summary>

| TensorFlow Version | Architecture | Image:Tag |
| :---: | :---: | --- |
| latest | amd64, arm64 | `rwthika/tensorflow-cc:latest-gpu` |
| 2.11.0 | amd64, arm64 | `rwthika/tensorflow-cc:2.11.0-gpu` |
| 2.10.1 | amd64, arm64 | `rwthika/tensorflow-cc:2.10.1-gpu` |
| 2.10.0 | amd64, arm64 | `rwthika/tensorflow-cc:2.10.0-gpu` |
| 2.9.3 | amd64, arm64 | `rwthika/tensorflow-cc:2.9.3-gpu` |
| 2.9.2 | amd64, arm64 | `rwthika/tensorflow-cc:2.9.2-gpu` |
| 2.9.1 | amd64 | `rwthika/tensorflow-cc:2.9.1-gpu` |
Expand All @@ -133,6 +136,9 @@ The amd64 images are based on the [official TensorFlow Docker images](https://hu
| TensorFlow Version | Architecture | Image:Tag |
| :---: | :---: | --- |
| latest | amd64, arm64 | `rwthika/tensorflow-cc:latest` |
| 2.11.0 | amd64, arm64 | `rwthika/tensorflow-cc:2.11.0` |
| 2.10.1 | amd64, arm64 | `rwthika/tensorflow-cc:2.10.1` |
| 2.10.0 | amd64, arm64 | `rwthika/tensorflow-cc:2.10.0` |
| 2.9.3 | amd64, arm64 | `rwthika/tensorflow-cc:2.9.3` |
| 2.9.2 | amd64, arm64 | `rwthika/tensorflow-cc:2.9.2` |
| 2.9.1 | amd64 | `rwthika/tensorflow-cc:2.9.1` |
Expand Down Expand Up @@ -172,7 +178,7 @@ The amd64 images are based on the [official TensorFlow Docker images](https://hu

If you would like to build the deb-package and Docker images yourself, use the [`Makefile`](Makefile) as instructed below.

All `make` targets support the flags `TF_VERSION` (defaults to `2.9.3`), `GPU` (defaults to `1`), and `ARCH` (defaults to host architecture) in order to build a specific TensorFlow version in CPU/GPU mode for a specific architecture.
All `make` targets support the flags `TF_VERSION` (defaults to `2.11.0`), `GPU` (defaults to `1`), and `ARCH` (defaults to host architecture) in order to build a specific TensorFlow version in CPU/GPU mode for a specific architecture.

All `make` targets listed below also have a counterpart named `<target>-all`, which can be used to build multiple TensorFlow versions one after the other using the `TF_VERSIONS` flag like so:

Expand Down Expand Up @@ -236,6 +242,12 @@ make 5-print-versions

| Version | Architecture | Step 1 (CPU) | Step 2 (CPU) | Step 4 (CPU) | Step 1 (GPU) | Step 2 (GPU) | Step 4 (GPU) | Notes |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | --- |
| 2.11.0 | amd64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| 2.11.0 | arm64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| 2.10.1 | amd64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| 2.10.1 | arm64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| 2.10.0 | amd64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| 2.10.0 | arm64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| 2.9.3 | amd64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| 2.9.3 | arm64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
| 2.9.2 | amd64 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |
Expand Down Expand Up @@ -298,6 +310,12 @@ make 5-print-versions

| TensorFlow | Architecture | Ubuntu | GCC | Bazel | Python | protobuf | CUDA | cuDNN | TensorRT | GPU Compute Capability |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 2.11.0 | amd64 | 20.04 | 9.4.0 | 6.0.0 | 3.8.10 | 3.9.2 | 11.2.152 | 8.1.0 | 7.2.2 | 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
| 2.11.0 | arm64 | 20.04 | 9.4.0 | 6.0.0 | 3.8.10 | 3.9.2 | 11.4.239 | 8.4.1 | 8.4.1 | 8.7, 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
| 2.10.1 | amd64 | 20.04 | 9.4.0 | 6.0.0 | 3.8.10 | 3.9.2 | 11.2.152 | 8.1.0 | 7.2.2 | 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
| 2.10.1 | arm64 | 20.04 | 9.4.0 | 6.0.0 | 3.8.10 | 3.9.2 | 11.4.239 | 8.4.1 | 8.4.1 | 8.7, 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
| 2.10.0 | amd64 | 20.04 | 9.4.0 | 6.0.0 | 3.8.10 | 3.9.2 | 11.2.152 | 8.1.0 | 7.2.2 | 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
| 2.10.0 | arm64 | 20.04 | 9.4.0 | 6.0.0 | 3.8.10 | 3.9.2 | 11.4.239 | 8.4.1 | 8.4.1 | 8.7, 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
| 2.9.3 | amd64 | 20.04 | 9.4.0 | 6.0.0 | 3.8.10 | 3.9.2 | 11.2.152 | 8.1.0 | 7.2.2 | 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
| 2.9.3 | arm64 | 20.04 | 9.4.0 | 6.0.0 | 3.8.10 | 3.9.2 | 11.4.239 | 8.4.1 | 8.4.1 | 8.7, 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
| 2.9.2 | amd64 | 20.04 | 9.4.0 | 5.3.1 | 3.8.10 | 3.9.2 | 11.2.152 | 8.1.0 | 7.2.2 | 8.6, 8.0, 7.5, 7.2, 7.0, 6.1, 6.0, 5.3 |
Expand Down
25 changes: 18 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,28 @@
# ==============================================================================

# --- build stage for building libtensorflow_cc --------------------------------
ARG TARGETARCH
ARG TF_VERSION=master
ARG GPU_POSTFIX=-gpu
ARG TF_CUDA_COMPUTE_CAPABILITIES=5.3,6.0,6.1,7.0,7.2,7.5,8.0,8.6
ARG TARGETARCH
FROM tensorflow/tensorflow:${TF_VERSION}-devel${GPU_POSTFIX}-${TARGETARCH} as build

ARG TARGETARCH
ARG TF_VERSION
ARG GPU_POSTFIX
ARG TF_CUDA_COMPUTE_CAPABILITIES
ARG JOBS="auto"

# clone TensorFlow
RUN git clone --branch v${TF_VERSION} --depth=1 https://github.com/tensorflow/tensorflow.git /tensorflow
WORKDIR /tensorflow

# fix build issue in v2.10.0
# fix build issue in 2.10.0, 2.10.1
# https://github.com/tensorflow/tensorflow/issues/57826
RUN if [ "${TF_VERSION}" = "2.10.0" ] || [ "${TF_VERSION}" = "2.10.1" ]; then \
git fetch --depth=1 origin b1bd1d6beeac169ce669f81dcbf3c48899ca1ed0 && \
git checkout FETCH_HEAD -- tensorflow/BUILD; \
fi

# configure compilation
ARG TF_CUDA_COMPUTE_CAPABILITIES=5.3,6.0,6.1,7.0,7.2,7.5,8.0,8.6
ENV PYTHON_BIN_PATH=/usr/bin/python3
ENV PYTHON_LIB_PATH=/usr/lib/python3/dist-packages
ENV TF_NEED_ROCM=0
Expand All @@ -54,15 +52,28 @@ ENV TF_SET_ANDROID_WORKSPACE=0
RUN ./configure

# build C++ library
# fix runtime issue in 2.10.0, 2.10.1, 2.11.0
# https://github.com/tensorflow/tensorflow/issues/59081
ARG JOBS="auto"
RUN if [ "${GPU_POSTFIX}" = "-gpu" ]; then \
bazel build --jobs ${JOBS} --config=cuda --config=opt --config=monolithic --verbose_failures tensorflow:libtensorflow_cc.so tensorflow:install_headers; \
if [ "${TF_VERSION}" = "2.10.0" ] || [ "${TF_VERSION}" = "2.10.1" ] || [ "${TF_VERSION}" = "2.11.0" ]; then \
bazel build --jobs ${JOBS} --config=cuda --config=opt --verbose_failures tensorflow:libtensorflow_cc.so tensorflow:install_headers; \
else \
bazel build --jobs ${JOBS} --config=cuda --config=opt --config=monolithic --verbose_failures tensorflow:libtensorflow_cc.so tensorflow:install_headers; \
fi; \
else \
bazel build --jobs ${JOBS} --config=opt --config=monolithic --verbose_failures tensorflow:libtensorflow_cc.so tensorflow:install_headers; \
if [ "${TF_VERSION}" = "2.10.0" ] || [ "${TF_VERSION}" = "2.10.1" ] || [ "${TF_VERSION}" = "2.11.0" ]; then \
bazel build --jobs ${JOBS} --config=opt --verbose_failures tensorflow:libtensorflow_cc.so tensorflow:install_headers; \
else \
bazel build --jobs ${JOBS} --config=opt --config=monolithic --verbose_failures tensorflow:libtensorflow_cc.so tensorflow:install_headers; \
fi; \
fi

# move libtensorflow_cc to separate folder for easier Dockerfile COPY
RUN mkdir bazel-bin/tensorflow/lib && \
mv bazel-bin/tensorflow/libtensorflow_cc.so* bazel-bin/tensorflow/lib/ && \
mv bazel-bin/tensorflow/libtensorflow_framework.so* bazel-bin/tensorflow/lib/ && \
ln -s libtensorflow_framework.so.2 bazel-bin/tensorflow/lib/libtensorflow_framework.so && \
rm bazel-bin/tensorflow/lib/*params

# build protobuf from source, same version as TensorFlow is using
Expand Down
7 changes: 4 additions & 3 deletions docker/cmake/TensorFlowConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ mark_as_advanced(INCLUDE_DIRS LIBRARY LIBRARY_FRAMEWORK)
# set INCLUDE_DIRS and LIBRARIES
if(TensorFlow_FOUND)
set(TensorFlow_INCLUDE_DIRS ${INCLUDE_DIRS})
set(TensorFlow_LIBRARIES ${LIBRARY} ${Protobuf_LIBRARY})
if(LIBRARY_FRAMEWORK)
string(APPEND TensorFlow_LIBRARIES ${LIBRARY_FRAMEWORK})
set(TensorFlow_LIBRARIES ${LIBRARY} ${LIBRARY_FRAMEWORK} ${Protobuf_LIBRARY})
else()
set(TensorFlow_LIBRARIES ${LIBRARY} ${Protobuf_LIBRARY})
endif()
endif()
endif()
9 changes: 9 additions & 0 deletions example/build-and-run-monolithic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

g++ -I /usr/local/include/tensorflow \
hello_tensorflow.cpp \
-ltensorflow_cc -lprotobuf \
-o hello_tensorflow

./hello_tensorflow
2 changes: 1 addition & 1 deletion example/build-and-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

g++ -I /usr/local/include/tensorflow \
hello_tensorflow.cpp \
-ltensorflow_cc -lprotobuf \
-ltensorflow_cc -ltensorflow_framework -lprotobuf \
-o hello_tensorflow

./hello_tensorflow
4 changes: 3 additions & 1 deletion example/hello_tensorflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ int main(int argc, char **argv) {

// run graph and fetch outputs of A, x, and b
vector<tensorflow::Tensor> outputs;
session.Run({A, x, b}, &outputs);
tensorflow::Status status = session.Run({A, x, b}, &outputs);
if (!status.ok())
throw std::runtime_error("Failed to run TensorFlow graph: " + status.ToString());

// print results
cout << "Hello from TensorFlow C++ " << TF_VERSION_STRING << "!" << endl << endl;
Expand Down
2 changes: 1 addition & 1 deletion scripts/.common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
set -e
set -o pipefail

DEFAULT_TF_VERSION="2.9.3"
DEFAULT_TF_VERSION="2.11.0"
DEFAULT_JOBS=$(nproc)
DEFAULT_GPU=1
DEFAULT_ARCH=$(dpkg --print-architecture)
Expand Down
7 changes: 6 additions & 1 deletion scripts/1-build-official-devel-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
source $(dirname "$0")/.common.sh

CPU_GPU_POSTFIX=${GPU_POSTFIX:--cpu}
BUILD_DIR=${DOWNLOAD_DOCKERFILE_DIR}

if [ "$ARCH" = "amd64" ]; then
DOCKERFILE=${DOWNLOAD_DOCKERFILE_DIR}/dockerfiles/devel${CPU_GPU_POSTFIX}.Dockerfile
elif [ "$ARCH" = "arm64" ]; then
Expand All @@ -32,7 +34,10 @@ elif [ "$ARCH" = "arm64" ]; then
sed -i "s/ubuntu:\${UBUNTU_VERSION}/nvcr.io\/nvidia\/l4t-tensorflow:r35.1.0-tf2.9-py3/" $DOCKERFILE
fi
fi
BUILD_DIR=${DOWNLOAD_DOCKERFILE_DIR}

# replace sklearn (deprecated) with scikit-learn
# https://pypi.org/project/sklearn/
sed -i "s/sklearn/scikit-learn/" $DOCKERFILE

echo "Building ${IMAGE_DEVEL_ARCH} ... "
docker build -t ${IMAGE_DEVEL_ARCH} -f ${DOCKERFILE} ${BUILD_DIR} | tee ${LOG_FILE}
6 changes: 5 additions & 1 deletion scripts/4-test-libtensorflow-cc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ source $(dirname "$0")/.common.sh

EXAMPLE_DIR=${REPOSITORY_DIR}/example
EXAMPLE_MOUNT="/example"
CMD="./build-and-run.sh"
if [ "${TF_VERSION}" = "2.10.0" ] || [ "${TF_VERSION}" = "2.10.1" ] || [ "${TF_VERSION}" = "2.11.0" ]; then
CMD="./build-and-run.sh"
else
CMD="./build-and-run-monolithic.sh"
fi

echo "Testing libtensorflow_cc in ${IMAGE_CPP} ... "
if [[ "$GPU" == "1" && "$ARCH" = "amd64" ]]; then
Expand Down

0 comments on commit 41665bb

Please sign in to comment.