Last active
February 14, 2020 23:15
-
-
Save pavanky/5a45b29ed3ca56b7e1c747b9c0c88503 to your computer and use it in GitHub Desktop.
Tensorflow-centos7-docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# shellcheck disable=SC2155 | |
PYTHON_BIN=${1:-python} | |
wget -c https://bootstrap.pypa.io/get-pip.py | |
$PYTHON_BIN get-pip.py --user | |
export TF_CUDA_PATHS=/usr/local/cuda,/usr/ | |
export TF_NEED_GCP="1" | |
export TF_NEED_JEMALLOC="1" | |
export TF_NEED_HDFS="1" | |
export TF_NEED_S3="0" | |
export TF_NEED_GDR="0" | |
export TF_ENABLE_XLA="1" | |
export TF_NEED_VERBS="0" | |
export TF_NEED_OPENCL="0" | |
export TF_NEED_MPI=0 | |
# export TF_DOWNLOAD_CLANG=1 | |
PYTHON_BIN_PATH=$(which "$PYTHON_BIN") | |
export PYTHON_BIN_PATH | |
export PYTHON_LIB_PATH="$($PYTHON_BIN_PATH -c 'import site; print(site.getsitepackages()[0])')" | |
export GCC_HOST_COMPILER_PATH=$(which gcc) | |
export CC_OPT_FLAGS="-march=x86-64" | |
if [ "$TF_ENV_TYPE" = "gpu" ] | |
then | |
export TF_NEED_CUDA="1" | |
export TF_CUDA_VERSION="10.0" | |
export TF_CUDNN_VERSION="7" | |
export TF_CUDA_CLANG="0" | |
export TF_CUDA_COMPUTE_CAPABILITIES="5.2,3.5,3.7,7.0" | |
fi | |
if [ "$BUILD_WITH_MKL" = "1" ] | |
then | |
CONFIG_MKL="--config=mkl" | |
else | |
CONFIG_MKL="" | |
fi | |
$PYTHON_BIN -m pip install --upgrade pip wheel setuptools | |
$PYTHON_BIN -m pip --no-cache-dir install \ | |
grpcio \ | |
h5py \ | |
keras_applications \ | |
keras_preprocessing \ | |
mock \ | |
numpy \ | |
requests \ | |
future \ | |
enum34 \ | |
tensorflow-estimator | |
bazel clean | |
./configure | |
bazel build -c opt --copt=-msse4.2 --copt=-mavx \ | |
--copt=-O3 ${CONFIG_MKL} --linkopt -ldl \ | |
--copt=${CC_OPT_FLAGS} \ | |
//tensorflow/tools/pip_package:build_pip_package \ | |
//tensorflow/tools/lib_package:libtensorflow_jni \ | |
//tensorflow/tools/lib_package:libtensorflow \ | |
//tensorflow/tools/lib_package:libtensorflow_proto \ | |
mkdir -p /tfbuild/dist/wheel | |
mkdir -p /tfbuild/dist/bazel-bin/tools | |
bazel build //tensorflow/tools/pip_package:build_pip_package | |
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tfbuild/dist/wheel | |
cp -RL bazel-bin/tensorflow/libtensorflow*.so* /tfbuild/dist/bazel-bin/. | |
cp -RL bazel-bin/tensorflow/java /tfbuild/dist/bazel-bin/. | |
cp -RL bazel-bin/tensorflow/tools/lib_package /tfbuild/dist/bazel-bin/tools/. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM centos:7 | |
RUN yum makecache | |
RUN yum install -y centos-release-SCL which yum-utils centos-release-scl-rh epel-release | |
RUN yum install -y python27 \ | |
python27-python-devel \ | |
python27-python-wheel \ | |
java-1.8.0-openjdk-devel \ | |
devtoolset-8-toolchain \ | |
devtoolset-6-toolchain \ | |
devtoolset-7-toolchain \ | |
wget \ | |
gcc-c++ \ | |
devtoolset-8-c* \ | |
devtoolset-7-c* \ | |
yum-utils \ | |
hdf5 \ | |
hdf5-devel | |
RUN yum-config-manager --enable centos-sclo-rh-testing | |
RUN yum makecache | |
RUN yum install -y rh-python36 \ | |
rh-python36-python-devel \ | |
rh-python36-python-wheel | |
RUN rpm -ivh $PYTHON_37_RPM_BASE/$PYTHON_37_RPM | |
RUN yum groupinstall -y 'Development Tools' | |
RUN mkdir -p /tfbuild | |
# Install CUDA libraries | |
ENV CUDA_VERSION_MAJOR 10 | |
ENV CUDA_VERSION_MINOR 0 | |
ENV CUDA_VERSION_BUILD 130 | |
ENV CUDA_VERSION $CUDA_VERSION_MAJOR.$CUDA_VERSION_MINOR.$CUDA_VERSION_BUILD | |
ENV CUDA_RPM cuda-repo-rhel7-$CUDA_VERSION-1.x86_64.rpm | |
ENV CUDA_REMOTE https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/ | |
ENV CUDA_MACHINE_LEARNING_RPEO https://developer.download.nvidia.cn/compute/machine-learning/repos/rhel7/x86_64/ | |
RUN wget -c $CUDA_REMOTE/$CUDA_RPM | |
RUN rpm -vih $CUDA_RPM | |
RUN yum install -y cuda-libraries-dev-10-0 cuda-toolkit-10-0 | |
RUN ln -s /usr/local/cuda-10.0/lib64/stubs/libcuda.so /usr/local/cuda-10.0/lib64/libcuda.so.1 | |
RUN rpm -ivh $CUDA_MACHINE_LEARNING_RPEO/libcudnn7-7.6.1.34-1.cuda10.0.x86_64.rpm | |
RUN rpm -ivh $CUDA_MACHINE_LEARNING_RPEO/libnccl-2.4.7-1+cuda10.0.x86_64.rpm | |
RUN rpm -ivh $CUDA_MACHINE_LEARNING_RPEO/libcudnn7-devel-7.6.1.34-1.cuda10.0.x86_64.rpm | |
RUN rpm -ivh $CUDA_MACHINE_LEARNING_RPEO/libnccl-devel-2.4.7-1+cuda10.0.x86_64.rpm | |
ENV BAZEL_VERSION 0.24.1 | |
RUN wget https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ | |
chmod +x bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ | |
./bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ | |
rm bazel-$BAZEL_VERSION-installer-linux-x86_64.sh | |
RUN yum -y remove git* | |
RUN yum -y install https://centos7.iuscommunity.org/ius-release.rpm | |
RUN yum -y install git2u-all | |
COPY tensorflow-source.zip /tfbuild | |
RUN cd /tfbuild && unzip tensorflow-source.zip | |
ARG IMAGE_TYPE=cpu | |
ENV TF_ENV_TYPE=$IMAGE_TYPE | |
ARG PY_VER=27 | |
ENV BUILD_PY_VER=$PY_VER | |
ARG USE_MKL=1 | |
ENV BUILD_WITH_MKL=$USE_MKL | |
COPY entrypoint.sh /tfbuild/tensorflow-source | |
COPY build-tf.sh /tfbuild/tensorflow-source | |
WORKDIR /tfbuild/tensorflow-source/ | |
CMD /tfbuild/tensorflow-source/entrypoint.sh $BUILD_PY_VER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# shellcheck disable=SC2155 | |
if [ "$TF_ENV_TYPE" = "gpu" ] | |
then | |
DEVTOOLSET="devtoolset-6" | |
else | |
DEVTOOLSET="devtoolset-7" | |
fi | |
case $1 in | |
27) | |
# scl enable python2.7 and useit for build | |
SCL_PYTHON=python27 | |
PYTHON_BUILD_VER=python2.7 | |
;; | |
36) | |
# scl enable python3.6 and useit for build | |
SCL_PYTHON=rh-python36 | |
PYTHON_BUILD_VER=python3.6 | |
;; | |
37) | |
# scl enable python3.6, but use 3.7 for build | |
SCL_PYTHON=rh-python36 | |
PYTHON_BUILD_VER=python3.7 | |
;; | |
*) | |
echo "python version not specified" | |
exit 1 | |
;; | |
esac | |
scl enable $SCL_PYTHON $DEVTOOLSET \ | |
"/usr/bin/env bash -c '/tfbuild/tensorflow-source/build-tf.sh $PYTHON_BUILD_VER'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IMAGE_VERSION=1.15.2 | |
IMAGE_TYPE?=cpu | |
IMAGE_NAME="tensorflow-$(IMAGE_TYPE):$(IMAGE_VERSION)" | |
PY_VER?=27 | |
USE_MKL?=1 | |
build: clean-dist create-dist build-image run-container | |
clean-dist: | |
@sudo rm -rf $(PWD)/dist/* | |
create-dist: | |
@mkdir -p $(PWD)/dist | |
build-image: tensorflow-source.zip | |
docker build -t $(IMAGE_NAME) . \ | |
--build-arg IMAGE_TYPE=$(IMAGE_TYPE) \ | |
--build-arg PY_VER=$(PY_VER) \ | |
--build-arg USE_MKL=$(USE_MKL) | |
tensorflow-source.zip: | |
git clone https://github.com/tensorflow/tensorflow -b v$(IMAGE_VERSION) tensorflow-source | |
@zip -r tensorflow-source.zip tensorflow-source | |
@rm -rf tensorflow-source | |
run-container: | |
@docker run -v $(PWD)/dist:/tfbuild/dist $(IMAGE_NAME) | |
clean: | |
rm -f tensorflow-source.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment