Skip to content

Instantly share code, notes, and snippets.

@jackersson
Last active February 6, 2019 10:51
Show Gist options
  • Save jackersson/3158238a142bb7f54db3e6144bb18763 to your computer and use it in GitHub Desktop.
Save jackersson/3158238a142bb7f54db3e6144bb18763 to your computer and use it in GitHub Desktop.
tensorflow.sh
#!/bin/bash
#!/usr/bin/env bash
#
SCRIPT_DIR="$(cd "$(dirname "${0}")"; pwd)"
RED="\033[1;31m"
YELLOW="\033[1;33m"
GREEN="\033[0;32m"
NO_COLOR="\033[0m"
TF_DIR=$(readlink -f "${1}")
echo ${TF_DIR}
################################### Functions ###################################
# Prints an error message and exits with an error code of 1
fail () {
echo -e "${RED}Command failed - script terminated${NO_COLOR}"
exit 1
}
install_packages () {
for PKG in ${*}; do
if ! dpkg -l ${PKG} > /dev/null 2>&1; then
sudo apt-get -y install ${PKG} || fail
fi
done
sudo apt-get update -y
}
################################### Script ###################################
if [ ${#} -lt 1 ]; then
echo "Usage: ${0} <install-dir>"
exit 0
fi
# install required packages
install_packages git autoconf build-essential automake libtool curl make g++ unzip python-numpy swig python-dev python-wheel openjdk-8-jdk pkg-config zip zlib1g-dev wget libcupti-dev libre2-dev libjsoncpp-dev || fail
# install bazel
if ! bazel version | grep "Build label: 0.16.0"; then
if [ ! -f "bazel-0.16.0-installer-linux-x86_64.sh" ]; then
wget https://github.com/bazelbuild/bazel/releases/download/0.16.0/bazel-0.16.0-installer-linux-x86_64.sh || fail
chmod 775 bazel-0.16.0-installer-linux-x86_64.sh || fail
sudo ./bazel-0.16.0-installer-linux-x86_64.sh || fail
fi
fi
# install tensorflow
for f in avx512fintrin.h avx512pfintrin.h avx512vlintrin.h; do
curl -H "User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36" -o $f "https://gcc.gnu.org/viewcvs/gcc/branches/gcc-5-branch/gcc/config/i386/${f}?view=co&revision=245536&content-type=text%2Fplain&pathrev=245536"
done && sudo mv avx512*intrin.h /usr/lib/gcc/x86_64-linux-gnu/5/include/
if [ ! -f "v1.8.0.tar.gz" ]; then
wget https://github.com/tensorflow/tensorflow/archive/v1.8.0.tar.gz
tar -xzvf v1.8.0.tar.gz
pushd tensorflow-1.8.0
./configure
bazel build -c opt --copt=-mavx2 --copt=-msse4.2 --copt=-msse4.1 --config=monolithic //tensorflow:libtensorflow_cc.so //tensorflow/core/profiler:profiler
mkdir -p ${TF_DIR}/lib
cp -vL ./bazel-bin/tensorflow/libtensorflow_cc.so ${TF_DIR}/lib/libtensorflow_cc.so
mkdir -p ${TF_DIR}/include/tensorflow
cp -vrL ./tensorflow/core ${TF_DIR}/include/tensorflow
cp -vrL ./tensorflow/cc ${TF_DIR}/include/tensorflow
cp -vrL ./tensorflow/c ${TF_DIR}/include/tensorflow
mkdir -p ${TF_DIR}/include/third_party
cp -vRL ./third_party/eigen3 ${TF_DIR}/include/third_party
rm -rf ${DST}/third_party/eigen3/unsupported
cp -vRL ./bazel-tensorflow-1.8.0/external/eigen_archive/unsupported ${TF_DIR}/include
cp -vRL ./bazel-genfiles/tensorflow/cc ${TF_DIR}/include/tensorflow
cp -vRL ./bazel-genfiles/tensorflow/core ${TF_DIR}/include/tensorflow
cp -vRL ./bazel-tensorflow-1.8.0/external/eigen_archive/Eigen ${TF_DIR}/include/Eigen
sudo ln -s /usr/include/jsoncpp/json/ ${TF_DIR}/include/json
popd
fi
# install protobuf
if [ ! -f "protobuf-cpp-3.5.0.tar.gz" ]; then
wget https://github.com/google/protobuf/releases/download/v3.5.0/protobuf-cpp-3.5.0.tar.gz
tar -xzvf protobuf-cpp-3.5.0.tar.gz
pushd protobuf-3.5.0
./autogen.sh
./configure --prefix=${TF_DIR}
make -j6
make -j6 check
make install
popd
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment