#!/usr/bin/env bash | |
# Author: Sasha Nikiforov | |
# source of inspiration | |
# https://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions | |
# Detect platform | |
if [ "$(uname)" == "Darwin" ]; then | |
# MacOS | |
raw_cpu_flags=`sysctl -a | grep machdep.cpu.features | cut -d ":" -f 2 | tr '[:upper:]' '[:lower:]'` | |
elif [ "$(uname)" == "Linux" ]; then | |
# GNU/Linux | |
raw_cpu_flags=`grep flags -m1 /proc/cpuinfo | cut -d ":" -f 2 | tr '[:upper:]' '[:lower:]'` | |
else | |
echo "Unknown plaform: $(uname)" | |
exit -1 | |
fi | |
# check if VirtuelEnv activated | |
if [ -z "$VIRTUAL_ENV" ]; then | |
echo "VirtualEnv is not activated" | |
exit -1 | |
fi | |
VENV_BIN=$VIRTUAL_ENV/bin | |
VENV_LIB=$VIRTUAL_ENV/lib | |
# bazel tf needs these env vars | |
export PYTHON_BIN_PATH=$VENV_BIN/python | |
export PYTHON_LIB_PATH=$VENV_LIB/`ls $VENV_LIB | grep python` | |
COPT="--copt=-march=native" | |
for cpu_feature in $raw_cpu_flags | |
do | |
case "$cpu_feature" in | |
"sse4.1" | "sse4.2" | "ssse3" | "fma" | "cx16" | "popcnt" | "maes") | |
COPT+=" --copt=-m$cpu_feature" | |
;; | |
"avx1.0") | |
COPT+=" --copt=-mavx" | |
;; | |
*) | |
# noop | |
;; | |
esac | |
done | |
bazel clean | |
./configure | |
bazel build -c opt $COPT -k //tensorflow/tools/pip_package:build_pip_package | |
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg | |
pip install --upgrade /tmp/tensorflow_pkg/`ls /tmp/tensorflow_pkg/ | grep tensorflow` |
This comment has been minimized.
This comment has been minimized.
@phobrain you have to clone the tensorflow repo and run this script inside it, more details: https://www.tensorflow.org/install/install_sources |
This comment has been minimized.
This comment has been minimized.
Thanks! I had a tree checked out or likely unpacked according to some instruction page, but it didn't have the configure script. Following the install_sources link led to a successful compile. Had to get latest keras from github with 5-day-old fix for compatibility. Looks like it's cranking a lot faster now. Even without that, it's worth it to see the warnings gone. :-) |
This comment has been minimized.
This comment has been minimized.
For training a truncated Inceptionv3 (pics 299x299) siamese-style in keras, batch_size=32, train/validate sizes=40/40, virtualenv version epochs (seconds): 153, 131, 128, 130, 128 (total runtime 12m 31s) Macbook Pro 2012. |
This comment has been minimized.
This comment has been minimized.
@rogeriochaves thx :) @phobrain great, thx for the input |
This comment has been minimized.
This comment has been minimized.
Tensorflow 1.4.1 did not work with bazel 0.9.0 for me. Had to downgrade bazel to 0.8.1 |
This comment has been minimized.
This comment has been minimized.
works with tag v1.11.0, commit c19e293 python 3, I wasnt able to build with python 2, but didnt spend much time to do it Note: python 3.7 wont work on MacOS, you need python 3.6 or mb 3.5. More details below Due to some problem with virtualenv small patch is needed to build TF on virtualenv.
|
This comment has been minimized.
What/where is the ./configure script?