Skip to content

Commit 7e178bd

Browse files
authored
Merge branch 'master' into system-protobuf
2 parents 733a3c6 + 5994cbe commit 7e178bd

11 files changed

Lines changed: 68 additions & 31 deletions

Dockerfiles/BAZEL_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.0
1+
3.7.2

Dockerfiles/archlinux-cuda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ RUN ./tensorflow_cc/Dockerfiles/install-archlinux.sh --cuda
1010

1111
ENV NVIDIA_VISIBLE_DEVICES all
1212
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
13-
ENV NVIDIA_REQUIRE_CUDA "cuda>=10.1"
13+
ENV NVIDIA_REQUIRE_CUDA "cuda>=11.1"

Dockerfiles/install-archlinux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ fi
5959
# cleanup packages
6060
rm -rvf /usr/local/lib/bazel/
6161
rm -vf /usr/local/bin/bazel
62-
pacman --noconfirm -R jdk11-openjdk python python-numpy
62+
pacman --noconfirm -R jdk11-openjdk
6363
pacman --noconfirm -Rns $(pacman -Qtdq)

Dockerfiles/install-common.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ chmod go+rX tensorflow_cc/tensorflow_cc/build
1919
cd tensorflow_cc/tensorflow_cc/build
2020

2121
# build and install
22-
cmake ..
22+
cmake -DLOCAL_RAM_RESOURCES=2048 -DLOCAL_CPU_RESOURCES=2 ..
2323
make
2424
rm -rf /home/tensorflow_cc/.cache
2525
rm -rf /root/.cache
2626
make install
27+
ldconfig
2728
cd "$cwd"
2829
rm -rf tensorflow_cc/tensorflow_cc/build
2930

Dockerfiles/ubuntu-cuda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
1+
FROM nvidia/cuda:11.1-cudnn8-devel-ubuntu18.04
22

33
# copy the contents of this repository to the container
44
COPY . tensorflow_cc

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# tensorflow_cc
2-
[![Build Status](http://elm.floop.cz:8080/buildStatus/icon?job=tensorflow_cc)](http://elm.floop.cz:8080/job/tensorflow_cc/)
3-
[![TF version](https://img.shields.io/badge/TF%20version-2.3.1-brightgreen.svg)]()
2+
[![Build Status](http://oak.floop.cz:8080/buildStatus/icon?job=tensorflow_cc)](http://oak.floop.cz:8080/job/tensorflow_cc/)
3+
[![TF version](https://img.shields.io/badge/TF%20version-2.5.0-brightgreen.svg)]()
44

55
This repository makes possible the usage of the [TensorFlow C++](https://www.tensorflow.org/api_docs/cc/) API from the outside of the TensorFlow source code folders and without the use of the [Bazel](https://bazel.build/) build system.
66

@@ -46,12 +46,13 @@ sudo apt-get install cmake curl g++-7 git python3-dev python3-numpy sudo wget
4646

4747
In order to build the TensorFlow itself, the build procedure also requires [Bazel](https://bazel.build/):
4848
```
49-
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
49+
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
50+
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
5051
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
5152
sudo apt-get update && sudo apt-get install bazel
5253
```
5354

54-
If you require GPU support on Ubuntu, please also install NVIDIA CUDA Toolkit (>=10.1), NVIDIA drivers, cuDNN, and `cuda-command-line-tools` package.
55+
If you require GPU support on Ubuntu, please also install NVIDIA CUDA Toolkit (>=11.1), NVIDIA drivers, cuDNN, and `cuda-command-line-tools` package.
5556
The build procedure will automatically detect CUDA if it is installed in `/opt/cuda` or `/usr/local/cuda` directories.
5657

5758
##### Arch Linux:
@@ -66,7 +67,7 @@ sudo pacman -S cuda cudnn nvidia
6667
```
6768

6869
**Warning:** Newer versions of TensorFlow sometimes fail to build with the latest version of Bazel. You may wish
69-
to install an older version of Bazel (e.g., 3.1.0).
70+
to install an older version of Bazel (e.g., 3.7.2).
7071

7172
#### 2) Clone this repository
7273
```
@@ -82,13 +83,19 @@ mkdir build && cd build
8283
cmake ..
8384
make
8485
sudo make install
86+
sudo ldconfig
8587
```
8688

87-
**Warning:** Optimizations for Intel CPU generation `>=ivybridge` are enabled by default. If you have a
88-
processor that is older than `ivybridge` generation, you may wish to run `export CC_OPT_FLAGS="-march=native"`
89+
**Warning:** Optimizations for Intel CPU generation `>=haswell` are enabled by default. If you have a
90+
processor that is older than `haswell` generation, you may wish to run `export CC_OPT_FLAGS="-march=native"`
8991
before the build. This command provides the best possible optimizations for your current CPU generation, but
9092
it may cause the built library to be incompatible with older generations.
9193

94+
**Warning:** In low-memory or many-cpu environments, the bazel scheduler can miss the resource consumption
95+
estimates and the build may be terminated by the out-of-memory killer.
96+
If that is your case, consider adding resource limit parameters to CMake, e.g.,
97+
`cmake -DLOCAL_RAM_RESOURCES=2048 -DLOCAL_CPU_RESOURCES=4 ..`
98+
9299
#### 4) (Optional) Free disk space
93100

94101
```

tensorflow_cc/CMakeLists.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
2+
cmake_policy(SET CMP0048 NEW) # Enable version parameter in project().
23
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/PROJECT_VERSION" version)
34
project(
45
"tensorflow_cc"
5-
VERSION "${version}"
6+
VERSION ${version}
67
)
78

8-
# If enabled, bazel has to be installed.
99
option(ALLOW_CUDA "Try to find and use CUDA." ON)
1010
option(REQUIRE_CUDA "Make sure to find and use CUDA (implies ALLOW_CUDA)." OFF)
11+
set(LOCAL_RAM_RESOURCES 4096 CACHE STRING "The amount of local RAM resources passed to bazel scheduler (e.g., 4096).")
12+
set(LOCAL_CPU_RESOURCES HOST_CPUS CACHE STRING "The amount of local CPU cores passed to bazel scheduler (e.g., 2).")
1113
set(TENSORFLOW_TAG "v${version}" CACHE STRING "The tensorflow release tag to be checked out (default v${version}).")
1214
option(SYSTEM_PROTOBUF "Link to system protobuf." OFF)
13-
set(TARGET_CXX_STANDARD "cxx_std_11" CACHE STRING "C++ standard to be enforced when linking to TensorflowCC targets (e.g., cxx_std_11).")
15+
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard for building and linking the library (e.g., 14).")
1416

1517
# -------------
1618
# CMake Options
@@ -22,9 +24,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
2224
include(CMakePackageConfigHelpers)
2325
set(CMAKECFG_INSTALL_DIR lib/cmake/TensorflowCC)
2426

25-
set_property(CACHE TARGET_CXX_STANDARD PROPERTY STRINGS
26-
"cxx_std_11" "cxx_std_14" "cxx_std_17" "cxx_std_20")
27-
2827
# Configure the build_tensorflow script.
2928
configure_file("cmake/build_tensorflow.sh.in" "build_tensorflow.sh" @ONLY)
3029

@@ -39,15 +38,15 @@ include(TensorflowBase)
3938
# ------------------------------
4039

4140
add_library(tensorflow_cc INTERFACE)
42-
target_compile_features(tensorflow_cc INTERFACE ${TARGET_CXX_STANDARD})
41+
target_compile_features(tensorflow_cc INTERFACE "cxx_std_${CMAKE_CXX_STANDARD}")
4342

4443
# The include folders are sometimes contained under bazel-bin/bin/ and sometimes just bazel-bin.
4544
target_include_directories(
4645
tensorflow_cc INTERFACE
47-
"${CMAKE_INSTALL_PREFIX}/include/tensorflow/bazel-bin/tensorflow/include"
48-
"${CMAKE_INSTALL_PREFIX}/include/tensorflow/bazel-bin/tensorflow/include/src"
49-
"${CMAKE_INSTALL_PREFIX}/include/tensorflow/bazel-bin/bin/tensorflow/include"
50-
"${CMAKE_INSTALL_PREFIX}/include/tensorflow/bazel-bin/bin/tensorflow/include/src"
46+
$<INSTALL_INTERFACE:include/tensorflow/bazel-bin/tensorflow/include>
47+
$<INSTALL_INTERFACE:include/tensorflow/bazel-bin/tensorflow/include/src>
48+
$<INSTALL_INTERFACE:include/tensorflow/bazel-bin/bin/tensorflow/include>
49+
$<INSTALL_INTERFACE:include/tensorflow/bazel-bin/bin/tensorflow/include/src>
5150
)
5251
target_link_libraries(
5352
tensorflow_cc INTERFACE

tensorflow_cc/PROJECT_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.1
1+
2.5.0

tensorflow_cc/cmake/TensorflowBase.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ ExternalProject_Add(
1919
COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/tensorflow/bazel-bin/bin/tensorflow/include/src"
2020
COMMAND touch "${CMAKE_CURRENT_BINARY_DIR}/tensorflow/bazel-bin/tensorflow/include/src/__placeholder__.h"
2121
COMMAND touch "${CMAKE_CURRENT_BINARY_DIR}/tensorflow/bazel-bin/bin/tensorflow/include/src/__placeholder__.h"
22+
# Fix compilation with CUDA 11.3.
23+
PATCH_COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/patches/v2.5.0-Fix-NCCL-build-failure-with-CUDA-11.3.patch" .
24+
COMMAND patch -p1 < v2.5.0-Fix-NCCL-build-failure-with-CUDA-11.3.patch
2225
)

tensorflow_cc/cmake/build_tensorflow.sh.in

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ function version_gt {
77
}
88

99
# configure environmental variables
10-
export CC_OPT_FLAGS=${CC_OPT_FLAGS:-"-march=ivybridge"}
10+
export CC_OPT_FLAGS=${CC_OPT_FLAGS:-"-march=haswell"}
1111
export TF_NEED_GCP=${TF_NEED_GCP:-0}
1212
export TF_NEED_HDFS=${TF_NEED_HDFS:-0}
1313
export TF_NEED_OPENCL=${TF_NEED_OPENCL:-0}
14-
export TF_NEED_OPENCL_SYCL=${TF_NEED_OPENCL_SYCL:-0}
1514
export TF_NEED_TENSORRT=${TF_NEED_TENSORRT:-0}
1615
export TF_NEED_NGRAPH=${TF_NEED_NGRAPH:-0}
1716
export TF_NEED_JEMALLOC=${TF_NEED_JEMALLOC:-1}
1817
export TF_NEED_VERBS=${TF_NEED_VERBS:-0}
1918
export TF_NEED_MKL=${TF_NEED_MKL:-1}
2019
export TF_DOWNLOAD_MKL=${TF_DOWNLOAD_MKL:-1}
2120
export TF_NEED_MPI=${TF_NEED_MPI:-0}
22-
export TF_ENABLE_XLA=${TF_ENABLE_XLA:-1}
2321
export TF_NEED_AWS=${TF_NEED_AWS:-0}
2422
export TF_NEED_GDR=${TF_NEED_GDR:-0}
2523
export TF_CUDA_CLANG=${TF_CUDA_CLANG:-0}
@@ -58,12 +56,14 @@ if [ "$cuda_allowed" == true ] && [ "$cuda_available" == true ]; then
5856
export TF_CUDA_COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES:-"3.5,7.0"} # default from configure.py
5957
export TF_CUDA_PATHS=${TF_CUDA_PATHS:-"/opt/cuda,/usr/local/cuda,/usr/local,/usr/cuda,/usr"}
6058
export TF_CUDA_VERSION="$(nvcc --version | sed -n 's/^.*release \(.*\),.*/\1/p')"
61-
export TF_NCCL_VERSION="$(find /opt /usr -name 'libnccl.so.*' | tail -n1 | sed -r 's/^.*\.so\.//')"
62-
export TF_CUDNN_VERSION="$(find /opt /usr -name 'libcudnn.so.*' | tail -n1 | sed -r 's/^.*\.so\.//')"
59+
export TF_NCCL_VERSION="$(find /opt /usr -name 'libnccl.so.*' -path '*/cuda*' | tail -n1 | sed -r 's/^.*\.so\.//')"
60+
export TF_CUDNN_VERSION="$(find /opt /usr -name 'libcudnn.so.*' -path '*/cuda*' | tail -n1 | sed -r 's/^.*\.so\.//')"
6361

6462
# choose the right version of CUDA compiler
6563
if [ -z "$GCC_HOST_COMPILER_PATH" ]; then
66-
if hash gcc-9 2>/dev/null && version_gt 9.4 `gcc-9 -dumpversion`; then
64+
if hash gcc-10 2>/dev/null && version_gt 10.3 `gcc-10 -dumpversion`; then
65+
export GCC_HOST_COMPILER_PATH=${GCC_HOST_COMPILER_PATH:-"/usr/bin/gcc-10"}
66+
elif hash gcc-9 2>/dev/null && version_gt 9.4 `gcc-9 -dumpversion`; then
6767
export GCC_HOST_COMPILER_PATH=${GCC_HOST_COMPILER_PATH:-"/usr/bin/gcc-9"}
6868
elif hash gcc-8 2>/dev/null && version_gt 8.5 `gcc-8 -dumpversion`; then
6969
export GCC_HOST_COMPILER_PATH=${GCC_HOST_COMPILER_PATH:-"/usr/bin/gcc-8"}
@@ -93,10 +93,24 @@ else
9393
export TF_NEED_CUDA=0
9494
fi
9595

96+
# set bazel options for c++17 standard if necessary
97+
cxx_std_opts=""
98+
if [ "@CMAKE_CXX_STANDARD@" == 17 ]; then
99+
echo "Using C++17 standard"
100+
cxx_std_opts="--config=c++17_gcc"
101+
fi
102+
96103
# configure and build
97104
./configure
98-
bazel build --config=opt \
105+
JVM_RAM_RESOURCES=$((@LOCAL_RAM_RESOURCES@ / 4))
106+
JVM_RAM_RESOURCES=$((${JVM_RAM_RESOURCES} < 1024 ? 1024 : ${JVM_RAM_RESOURCES}))
107+
bazel --host_jvm_args="-Xmx${JVM_RAM_RESOURCES}m" \
108+
build --config=opt \
99109
--config=monolithic \
110+
--local_ram_resources=@LOCAL_RAM_RESOURCES@ \
111+
--local_cpu_resources=@LOCAL_CPU_RESOURCES@ \
112+
--discard_analysis_cache \
113+
$cxx_std_opts \
100114
$cuda_config_opts \
101115
tensorflow:libtensorflow_cc.so \
102116
tensorflow:install_headers

0 commit comments

Comments
 (0)