From f9a81ca2f97b5ae3155626f5157d4ecb0ab0a679 Mon Sep 17 00:00:00 2001 From: Pete Warden Date: Thu, 10 Aug 2017 18:16:26 -0700 Subject: [PATCH] Create CI build script for Raspberry Pi (#12190) * Create CI build script for Raspberry Pi * Moved location of Pi build script --- .../core/platform/cloud/oauth_client.cc | 1 + tensorflow/tools/ci_build/Dockerfile.pi | 20 +++++++++++++ .../ci_build/install/install_pi_toolchain.sh | 29 +++++++++++++++++++ .../tools/ci_build/pi}/build_raspberry_pi.sh | 28 +++++++++++++----- 4 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 tensorflow/tools/ci_build/Dockerfile.pi create mode 100755 tensorflow/tools/ci_build/install/install_pi_toolchain.sh rename {third_party/toolchains/cpus/arm => tensorflow/tools/ci_build/pi}/build_raspberry_pi.sh (70%) diff --git a/tensorflow/core/platform/cloud/oauth_client.cc b/tensorflow/core/platform/cloud/oauth_client.cc index 7a9588b56ad..b2ada534fc3 100644 --- a/tensorflow/core/platform/cloud/oauth_client.cc +++ b/tensorflow/core/platform/cloud/oauth_client.cc @@ -21,6 +21,7 @@ limitations under the License. #include #include #include +#include #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/strings/base64.h" #include "tensorflow/core/platform/cloud/http_request.h" diff --git a/tensorflow/tools/ci_build/Dockerfile.pi b/tensorflow/tools/ci_build/Dockerfile.pi new file mode 100644 index 00000000000..9d12ededb8b --- /dev/null +++ b/tensorflow/tools/ci_build/Dockerfile.pi @@ -0,0 +1,20 @@ +FROM ubuntu:14.04 + +MAINTAINER Jan Prach + +# Copy and run the install scripts. +COPY install/*.sh /install/ +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_bazel.sh +RUN /install/install_proto3.sh +RUN /install/install_buildifier.sh +RUN /install/install_auditwheel.sh +RUN /install/install_golang.sh +RUN /install/install_pi_toolchain.sh + +# Set up the master bazelrc configuration file. +COPY install/.bazelrc /etc/bazel.bazelrc diff --git a/tensorflow/tools/ci_build/install/install_pi_toolchain.sh b/tensorflow/tools/ci_build/install/install_pi_toolchain.sh new file mode 100755 index 00000000000..ef30ba58c28 --- /dev/null +++ b/tensorflow/tools/ci_build/install/install_pi_toolchain.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Copyright 2015 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. +# ============================================================================== + +dpkg --add-architecture armhf +echo 'deb [arch=armhf] http://ports.ubuntu.com/ trusty main restricted universe multiverse' >> /etc/apt/sources.list.d/armhf.list +echo 'deb [arch=armhf] http://ports.ubuntu.com/ trusty-updates main restricted universe multiverse' >> /etc/apt/sources.list.d/armhf.list +echo 'deb [arch=armhf] http://ports.ubuntu.com/ trusty-security main restricted universe multiverse' >> /etc/apt/sources.list.d/armhf.list +echo 'deb [arch=armhf] http://ports.ubuntu.com/ trusty-backports main restricted universe multiverse' >> /etc/apt/sources.list.d/armhf.list +sed -i 's#deb http://archive.ubuntu.com/ubuntu/#deb [arch=amd64] http://archive.ubuntu.com/ubuntu/#g' /etc/apt/sources.list +apt-get update +apt-get install -y libpython-all-dev:armhf +echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list +curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - +apt-get update +rm -rf /usr/local/bin/bazel +apt-get install -y bazel python python-numpy python-dev python-pip diff --git a/third_party/toolchains/cpus/arm/build_raspberry_pi.sh b/tensorflow/tools/ci_build/pi/build_raspberry_pi.sh similarity index 70% rename from third_party/toolchains/cpus/arm/build_raspberry_pi.sh rename to tensorflow/tools/ci_build/pi/build_raspberry_pi.sh index c9fe0bc7712..9e6cfc017e9 100755 --- a/third_party/toolchains/cpus/arm/build_raspberry_pi.sh +++ b/tensorflow/tools/ci_build/pi/build_raspberry_pi.sh @@ -18,7 +18,7 @@ set -e # By default this builds packages for the Pi Two and Three only, since the NEON support # this allows makes calculations many times faster. To support the Pi One or Zero, pass # PI_ONE as the first argument to the script, for example: -# third_party/toolchains/cpus/arm/build_raspberry_pi.sh PI_ONE +# tensorflow/tools/ci_build/pi/build_raspberry_pi.sh PI_ONE # # To install the cross-compilation support for Python this script needs on Ubuntu Trusty, run # something like these steps, after backing up your original /etc/apt/sources.list file: @@ -36,6 +36,17 @@ set -e yes '' | ./configure +# We need to update the Eigen version, because of compiler failures on ARM when +# using the version currently (Aug 10th 2017) pulled by mainline TensorFlow. We +# should be able to get rid of this hack once +# https://github.com/tensorflow/tensorflow/issues/9697 is addressed. +sed -i 's/f3a22f35b044/d781c1de9834/g' tensorflow/workspace.bzl +sed -i 's/ca7beac153d4059c02c8fc59816c82d54ea47fe58365e8aded4082ded0b820c4/a34b208da6ec18fa8da963369e166e4a368612c14d956dd2f9d7072904675d9b/g' tensorflow/workspace.bzl + +# Fix for curl build problem in 32-bit, see https://stackoverflow.com/questions/35181744/size-of-array-curl-rule-01-is-negative +sudo sed -i 's/define CURL_SIZEOF_LONG 8/define CURL_SIZEOF_LONG 4/g' /usr/include/curl/curlbuild.h +sudo sed -i 's/define CURL_SIZEOF_CURL_OFF_T 8/define CURL_SIZEOF_CURL_OFF_T 4/g' /usr/include/curl/curlbuild.h + if [[ $1 == "PI_ONE" ]]; then PI_COPTS="--copt=-march=armv6 --copt=-mfpu=vfp" echo "Building for the Pi One/Zero, with no NEON support" @@ -55,18 +66,19 @@ bazel build -c opt ${PI_COPTS} \ //tensorflow/tools/benchmark:benchmark_model \ //tensorflow/tools/pip_package:build_pip_package -TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXX) -echo "Final outputs will go to ${TMPDIR}" +OUTDIR=bazel-out/pi +mkdir -p ${OUTDIR} +echo "Final outputs will go to ${OUTDIR}" # Build a universal wheel. BDIST_OPTS="--universal" \ - bazel-bin/tensorflow/tools/pip_package/build_pip_package "${TMPDIR}" + bazel-bin/tensorflow/tools/pip_package/build_pip_package "${OUTDIR}" -OLD_FN=$(ls "${TMPDIR}" | grep \.whl) +OLD_FN=$(ls "${OUTDIR}" | grep \.whl) SUB='s/tensorflow-([^-]+)-([^-]+)-.*/tensorflow-\1-\2-none-any.whl/; print' NEW_FN=$(echo "${OLD_FN}" | perl -ne "${SUB}") -mv "${TMPDIR}/${OLD_FN}" "${TMPDIR}/${NEW_FN}" -cp bazel-bin/tensorflow/tools/benchmark/benchmark_model "${TMPDIR}" +mv "${OUTDIR}/${OLD_FN}" "${OUTDIR}/${NEW_FN}" +cp bazel-bin/tensorflow/tools/benchmark/benchmark_model "${OUTDIR}" echo "Output can be found here:" -find "${TMPDIR}" +find "${OUTDIR}"