Skip to content
This repository was archived by the owner on Feb 12, 2020. It is now read-only.

Ubuntu1804 #26

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ git clone https://github.com/hadim/docker-tensorflow-builder.git
- Edit the `build.sh` file to modify TensorFlow compilation parameters. Then launch the build:

```bash
LINUX_DISTRO="ubuntu-16.04"
# LINUX_DISTRO="ubuntu-16.04"
LINUX_DISTRO="ubuntu-18.04"
# or LINUX_DISTRO="ubuntu-18.10"
# or LINUX_DISTRO="centos-7.4"
# or LINUX_DISTRO="centos-6.6"
Expand Down Expand Up @@ -52,7 +53,8 @@ docker-compose run tf
- Edit the `build.sh` file to modify TensorFlow compilation parameters. Then launch the build:

```bash
LINUX_DISTRO="ubuntu-16.04"
# LINUX_DISTRO="ubuntu-16.04"
LINUX_DISTRO="ubuntu-18.04"
# or LINUX_DISTRO="ubuntu-18.10"
# or LINUX_DISTRO="centos-7.4"
# or LINUX_DISTRO="centos-6.6"
Expand Down Expand Up @@ -81,6 +83,7 @@ docker-compose run tf
---

- Refer to [tested build configurations](https://www.tensorflow.org/install/source#tested_build_configurations) to know which `BAZEL_VERSION` you need.
- Refer to [the nvidia cuda capabilites table](https://developer.nvidia.com/cuda-gpus#compute) to check the cuda capabilities of your GPU and set accordingly the variable `TF_CUDA_COMPUTE_CAPABILITIES` within the `build.sh` script.
- Be patient, the compilation can be long.
- Enjoy your Python wheels in the `wheels/` folder.
- *Don't forget to remove the container to free the space after the build: `docker-compose rm --force`.*
Expand Down
27 changes: 27 additions & 0 deletions tensorflow/ubuntu-18.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:18.04

RUN apt update && apt install -y \
build-essential \
curl \
git \
wget \
libjpeg-dev \
openjdk-8-jdk \
gcc-7 \
g++-7 \
&& rm -rf /var/lib/lists/*

# Install Anaconda
WORKDIR /
RUN wget "https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh" -O "miniconda.sh" && \
bash "miniconda.sh" -b -p "/conda" && \
rm miniconda.sh && \
echo PATH='/conda/bin:$PATH' >> /root/.bashrc && \
/conda/bin/conda config --add channels conda-forge && \
/conda/bin/conda update --yes -n base conda && \
/conda/bin/conda update --all --yes

COPY build.sh /build.sh
COPY cuda.sh /cuda.sh

CMD bash build.sh
133 changes: 133 additions & 0 deletions tensorflow/ubuntu-18.04/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env bash
set -ex

export PATH="/conda/bin:/usr/bin:$PATH"

if [ "$USE_GPU" -eq "1" ]; then
export CUDA_HOME="/usr/local/cuda"
alias sudo=""
source cuda.sh
cuda.install $CUDA_VERSION $CUDNN_VERSION $NCCL_VERSION
cd /
fi

# Set correct GCC version
GCC_VERSION="7"
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$GCC_VERSION 10
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-$GCC_VERSION 10
update-alternatives --set gcc "/usr/bin/gcc-$GCC_VERSION"
update-alternatives --set g++ "/usr/bin/g++-$GCC_VERSION"
gcc --version

# Install an appropriate Python environment
conda config --add channels conda-forge
conda create --yes -n tensorflow python==$PYTHON_VERSION
source activate tensorflow
conda install --yes numpy wheel bazel==$BAZEL_VERSION
pip install keras-applications keras-preprocessing

# Compile TensorFlow

# Here you can change the TensorFlow version you want to build.
# You can also tweak the optimizations and various parameters for the build compilation.
# See https://www.tensorflow.org/install/install_sources for more details.

cd /
rm -fr tensorflow/
git clone --depth 1 --branch $TF_VERSION_GIT_TAG "https://github.com/tensorflow/tensorflow.git"

TF_ROOT=/tensorflow
cd $TF_ROOT

# Python path options
export PYTHON_BIN_PATH=$(which python)
export PYTHON_LIB_PATH="$($PYTHON_BIN_PATH -c 'import site; print(site.getsitepackages()[0])')"
export PYTHONPATH=${TF_ROOT}/lib
export PYTHON_ARG=${TF_ROOT}/lib

# Compilation parameters
export TF_NEED_CUDA=0
export TF_NEED_GCP=1
export TF_CUDA_COMPUTE_CAPABILITIES=6.1,5.2,3.5
export TF_NEED_HDFS=1
export TF_NEED_OPENCL=0
export TF_NEED_JEMALLOC=1 # Need to be disabled on CentOS 6.6
export TF_ENABLE_XLA=0
export TF_NEED_VERBS=0
export TF_CUDA_CLANG=0
export TF_DOWNLOAD_CLANG=0
export TF_NEED_MKL=0
export TF_DOWNLOAD_MKL=0
export TF_NEED_MPI=0
export TF_NEED_S3=1
export TF_NEED_KAFKA=1
export TF_NEED_GDR=0
export TF_NEED_OPENCL_SYCL=0
export TF_SET_ANDROID_WORKSPACE=0
export TF_NEED_AWS=0
export TF_NEED_IGNITE=0
export TF_NEED_ROCM=0

# Compiler options
export GCC_HOST_COMPILER_PATH=$(which gcc)

# Here you can edit this variable to set any optimizations you want.
export CC_OPT_FLAGS="-march=native"

if [ "$USE_GPU" -eq "1" ]; then
# Cuda parameters
export CUDA_TOOLKIT_PATH=$CUDA_HOME
export CUDNN_INSTALL_PATH=$CUDA_HOME
export TF_CUDA_VERSION="$CUDA_VERSION"
export TF_CUDNN_VERSION="$CUDNN_VERSION"
export TF_NEED_CUDA=1
export TF_NEED_TENSORRT=0
export TF_NCCL_VERSION=$NCCL_VERSION
export NCCL_INSTALL_PATH=$CUDA_HOME
export NCCL_INSTALL_PATH=$CUDA_HOME

# Those two lines are important for the linking step.
export LD_LIBRARY_PATH="$CUDA_TOOLKIT_PATH/lib64:${LD_LIBRARY_PATH}"
ldconfig
fi

# Compilation
./configure

if [ "$USE_GPU" -eq "1" ]; then

bazel build --config=opt \
--config=cuda \
--linkopt="-lrt" \
--linkopt="-lm" \
--host_linkopt="-lrt" \
--host_linkopt="-lm" \
--action_env="LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" \
//tensorflow/tools/pip_package:build_pip_package

PACKAGE_NAME=tensorflow-gpu
SUBFOLDER_NAME="${TF_VERSION_GIT_TAG}-py${PYTHON_VERSION}-cuda${TF_CUDA_VERSION}-cudnn${TF_CUDNN_VERSION}"

else

bazel build --config=opt \
--linkopt="-lrt" \
--linkopt="-lm" \
--host_linkopt="-lrt" \
--host_linkopt="-lm" \
--action_env="LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" \
//tensorflow/tools/pip_package:build_pip_package

PACKAGE_NAME=tensorflow
SUBFOLDER_NAME="${TF_VERSION_GIT_TAG}-py${PYTHON_VERSION}"
fi

mkdir -p "/wheels/$SUBFOLDER_NAME"

bazel-bin/tensorflow/tools/pip_package/build_pip_package "/wheels/$SUBFOLDER_NAME" --project_name "$PACKAGE_NAME"

# Use the following for TF <= 1.8
# bazel-bin/tensorflow/tools/pip_package/build_pip_package "/wheels/$SUBFOLDER_NAME"

# Fix wheel folder permissions
chmod -R 777 /wheels/
Loading