From 2afcda57062b5ebb94c35a2bbd3581c9b8bc7393 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 5 Jun 2019 12:28:34 -0700 Subject: [PATCH] Add ubuntu16.04 devtoolset-7 cross-compiler. PiperOrigin-RevId: 251694973 --- ...dnn7-ubuntu16.04-devtoolset7-manylinux2010 | 156 ++++++++++++++++++ .../tools/ci_build/devtoolset/fixlinks.sh | 28 ++++ .../tools/ci_build/devtoolset/platlib.patch | 34 ++++ .../tools/ci_build/devtoolset/rpm-patch.sh | 28 ++++ 4 files changed, 246 insertions(+) create mode 100644 tensorflow/tools/ci_build/Dockerfile.rbe.cuda10.0-cudnn7-ubuntu16.04-devtoolset7-manylinux2010 create mode 100755 tensorflow/tools/ci_build/devtoolset/fixlinks.sh create mode 100644 tensorflow/tools/ci_build/devtoolset/platlib.patch create mode 100755 tensorflow/tools/ci_build/devtoolset/rpm-patch.sh diff --git a/tensorflow/tools/ci_build/Dockerfile.rbe.cuda10.0-cudnn7-ubuntu16.04-devtoolset7-manylinux2010 b/tensorflow/tools/ci_build/Dockerfile.rbe.cuda10.0-cudnn7-ubuntu16.04-devtoolset7-manylinux2010 new file mode 100644 index 00000000000..84603c79795 --- /dev/null +++ b/tensorflow/tools/ci_build/Dockerfile.rbe.cuda10.0-cudnn7-ubuntu16.04-devtoolset7-manylinux2010 @@ -0,0 +1,156 @@ +# Dockerfile to build a manylinux 2010 compliant cross-compiler. +# +# Builds a devtoolset-7 gcc/libstdc++ that targets manylinux 2010 compatible +# glibc (2.12) and system libstdc++ (4.4). + +FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu16.04 as devtoolset + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -y \ + cpio \ + file \ + flex \ + g++ \ + make \ + rpm2cpio \ + unar \ + wget \ + && \ + rm -rf /var/lib/apt/lists/* + + +# Set up a sysroot for glibc 2.12 / libstdc++ 4.4 / devtoolset-7 in /dt7. +WORKDIR /dt7 + +# Download binary glibc 2.12 release. +RUN wget http://old-releases.ubuntu.com/ubuntu/pool/main/e/eglibc/libc6_2.12.1-0ubuntu6_amd64.deb && \ + unar libc6_2.12.1-0ubuntu6_amd64.deb && \ + tar xvzf libc6_2.12.1-0ubuntu6_amd64/data.tar.gz && \ + rm -rf libc6_2.12.1-0ubuntu6_amd64.deb libc6_2.12.1-0ubuntu6_amd64 +RUN wget http://old-releases.ubuntu.com/ubuntu/pool/main/e/eglibc/libc6-dev_2.12.1-0ubuntu6_amd64.deb && \ + unar libc6-dev_2.12.1-0ubuntu6_amd64.deb && \ + tar xvzf libc6-dev_2.12.1-0ubuntu6_amd64/data.tar.gz && \ + rm -rf libc6-dev_2.12.1-0ubuntu6_amd64.deb libc6-dev_2.12.1-0ubuntu6_amd64 + +# Put the current kernel headers from ubuntu in place. +RUN ln -s /usr/include/linux /dt7/usr/include/linux +RUN ln -s /usr/include/asm-generic /dt7/usr/include/asm-generic +RUN ln -s /usr/include/x86_64-linux-gnu/asm /dt7/usr/include/asm + +# Symlinks in the binary distribution are set up for installation in /usr, we +# need to fix up all the links to stay within /dt7. +ADD devtoolset/fixlinks.sh fixlinks.sh +RUN ./fixlinks.sh /dt7 + +# Patch to allow non-glibc 2.12 compatible builds to work. +RUN sed -i '54i#define TCP_USER_TIMEOUT 18' /dt7/usr/include/netinet/tcp.h + +# Download binary libstdc++ 4.4 release. +WORKDIR /libstdc++-4.4 +RUN wget http://old-releases.ubuntu.com/ubuntu/pool/main/g/gcc-4.4/libstdc++6_4.4.3-4ubuntu5_amd64.deb && \ + unar libstdc++6_4.4.3-4ubuntu5_amd64.deb && \ + tar xvzf libstdc++6_4.4.3-4ubuntu5_amd64/data.tar.gz && \ + rm -rf libstdc++6_4.4.3-4ubuntu5_amd64.deb libstdc++6_4.4.3-4ubuntu5_amd64 + +# We only need the shared library, as we're going to develop against the +# libstdc++ provided by devtoolset-7. +RUN cp ./usr/lib/libstdc++.so.6.0.13 /dt7/usr/lib + +# Build a devtoolset-7 cross-compiler based on our glibc 2.12 sysroot setup. +WORKDIR /dts/src +RUN wget http://vault.centos.org/centos/6/sclo/Source/rh/devtoolset-7/devtoolset-7-gcc-7.3.1-5.15.el6.src.rpm +RUN rpm2cpio devtoolset-7-gcc-7.3.1-5.15.el6.src.rpm |cpio -idmv +RUN tar xvjf gcc-7.3.1-20180303.tar.bz2 --strip 1 + +# Apply the devtoolset patches to gcc. +ADD devtoolset/rpm-patch.sh rpm-patch.sh +RUN ./rpm-patch.sh gcc.spec + +RUN ./contrib/download_prerequisites + +WORKDIR /dts/build +RUN /dts/src/configure \ + --prefix=/dt7/usr \ + --with-sysroot=/dt7 \ + --disable-bootstrap \ + --disable-libmpx \ + --disable-libsanitizer \ + --disable-libunwind-exceptions \ + --disable-libunwind-exceptions \ + --disable-lto \ + --disable-multilib \ + --enable-__cxa_atexit \ + --enable-gnu-indirect-function \ + --enable-gnu-unique-object \ + --enable-initfini-array \ + --enable-languages="c,c++" \ + --enable-linker-build-id \ + --enable-plugin \ + --enable-shared \ + --enable-threads=posix \ + --with-default-libstdcxx-abi=gcc4-compatible \ + --with-gcc-major-version-only \ + --with-linker-hash-style=gnu \ + --with-tune=generic \ + && \ + make -j 42 && \ + make install + +# Create the devtoolset libstdc++ linkerscript that links dynamically against +# the system libstdc++ 4.4 and provides all other symbols statically. +RUN mv /dt7/usr/lib/libstdc++.so.6.0.24 /dt7/usr/lib/libstdc++.so.6.0.24.backup +RUN echo "OUTPUT_FORMAT(elf64-x86-64)\nINPUT ( libstdc++.so.6.0.13 -lstdc++_nonshared44 )" \ + > /dt7/usr/lib/libstdc++.so.6.0.24 +RUN cp ./x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++_nonshared44.a \ + /dt7/usr/lib + +# Link in architecture specific includes from the system; note that we cannot +# link in the whole x86_64-linux-gnu folder, as otherwise we're overlaying +# system gcc paths that we do not want to find. +# TODO(klimek): Automate linking in all non-gcc / non-kernel include +# directories. +RUN mkdir -p /dt7/usr/include/x86_64-linux-gnu +RUN ln -s /usr/include/x86_64-linux-gnu/python3.5m /dt7/usr/include/x86_64-linux-gnu/python3.5m + +# TODO(klimek): Split up into two different docker images. +FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu16.04 +COPY --from=devtoolset /dt7 /dt7 + +# Copy and run the install scripts. +COPY install/*.sh /install/ +ARG DEBIAN_FRONTEND=noninteractive +RUN /install/install_bootstrap_deb_packages.sh +RUN add-apt-repository -y ppa:openjdk-r/ppa && \ + add-apt-repository -y ppa:george-edison55/cmake-3.x +RUN /install/install_deb_packages.sh +RUN /install/install_pip_packages.sh +RUN /install/install_golang.sh +RUN /install/install_bazel.sh + +# Install TensorRT. +RUN apt-get update && apt-get install -y \ + libnvinfer-dev=5.1.5-1+cuda10.0 \ + libnvinfer5=5.1.5-1+cuda10.0 \ + && \ + rm -rf /var/lib/apt/lists/* + +# Build the pip package. +WORKDIR /tf +RUN git clone https://github.com/tensorflow/tensorflow . + +ENV TF_NEED_GCP=1 \ + TF_NEED_HDFS=1 \ + TF_NEED_CUDA=1 \ + GCC_HOST_COMPILER_PATH=/dt7/usr/bin/gcc \ + PATH=/dt7/usr/bin:$PATH \ + PYTHON_BIN_PATH=/usr/bin/python3.5 \ + TF_NEED_TENSORRT=1 + +ADD devtoolset/platlib.patch platlib.patch +RUN patch -p1 < platlib.patch + +RUN yes "" | ./configure + +RUN bazel build --config=opt tensorflow/tools/pip_package:build_pip_package --nodistinct_host_configuration + +RUN ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tf-wheel diff --git a/tensorflow/tools/ci_build/devtoolset/fixlinks.sh b/tensorflow/tools/ci_build/devtoolset/fixlinks.sh new file mode 100755 index 00000000000..86856d80d9c --- /dev/null +++ b/tensorflow/tools/ci_build/devtoolset/fixlinks.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Copyright 2016 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# +# Re-direct all links in $1 that point to /lib... to point to $1/lib... instead. + +BASE="$1" +find "${BASE}" -type l | \ + while read l ; do + if [[ "$(readlink "$l")" == /lib* ]]; then + ORIG="$(readlink "$l")"; + rm "$l"; + ln -s "${BASE}${ORIG}" "$l" + fi + done + diff --git a/tensorflow/tools/ci_build/devtoolset/platlib.patch b/tensorflow/tools/ci_build/devtoolset/platlib.patch new file mode 100644 index 00000000000..60f05bd65fc --- /dev/null +++ b/tensorflow/tools/ci_build/devtoolset/platlib.patch @@ -0,0 +1,34 @@ +diff --git a/tensorflow/tools/pip_package/build_pip_package.sh b/tensorflow/tools/pip_package/build_pip_package.sh +index 305033cd44..d2c43dc7ab 100755 +--- a/tensorflow/tools/pip_package/build_pip_package.sh ++++ b/tensorflow/tools/pip_package/build_pip_package.sh +@@ -135,6 +135,7 @@ function prepare_src() { + cp tensorflow/tools/pip_package/MANIFEST.in ${TMPDIR} + cp tensorflow/tools/pip_package/README ${TMPDIR} + cp tensorflow/tools/pip_package/setup.py ${TMPDIR} ++ touch ${TMPDIR}/stub.cc + + rm -f ${TMPDIR}/tensorflow/libtensorflow_framework.so + rm -f ${TMPDIR}/tensorflow/libtensorflow_framework.so.[0-9].* +diff --git a/tensorflow/tools/pip_package/setup.py b/tensorflow/tools/pip_package/setup.py +index c36a2a0fa8..6ed096aafc 100644 +--- a/tensorflow/tools/pip_package/setup.py ++++ b/tensorflow/tools/pip_package/setup.py +@@ -34,7 +34,7 @@ import os + import re + import sys + +-from setuptools import Command ++from setuptools import Command, Extension + from setuptools import find_packages + from setuptools import setup + from setuptools.command.install import install as InstallCommandBase +@@ -269,6 +269,7 @@ setup( + EXTENSION_NAME, + ] + matches, + }, ++ ext_modules=[Extension('_foo', ['stub.cc'])], + zip_safe=False, + distclass=BinaryDistribution, + cmdclass={ +) diff --git a/tensorflow/tools/ci_build/devtoolset/rpm-patch.sh b/tensorflow/tools/ci_build/devtoolset/rpm-patch.sh new file mode 100755 index 00000000000..892ae2af86a --- /dev/null +++ b/tensorflow/tools/ci_build/devtoolset/rpm-patch.sh @@ -0,0 +1,28 @@ +#!/bin/bash -eu +# Copyright 2016 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# +# Given an RPM spec file $1, apply its patches. + +SPEC="$1" +grep '%patch' "${SPEC}" |while read cmd ; do + N=$(echo "${cmd}" |sed 's,%patch\([0-9]\+\).*,\1,') + file=$(grep "Patch$N:" "${SPEC}" |sed 's,.*: ,,') + parg=$(echo "${cmd}" |sed 's,.*\(-p[0-9]\).*,\1,') + if [[ ! "${file}" =~ doxygen && "${cmd}" != \#* ]]; then + echo "patch ${parg} -s < ${file}" + patch ${parg} -s < "${file}" + fi +done