参考https://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions,安装好编译工具bazel后(https://docs.bazel.build/versions/master/install-ubuntu.html),可以用以下命令编译:
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda -k //tensorflow/tools/pip_package:build_pip_package
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda -k //tensorflow/tools/pip_package:build_pip_package如果你编译的时候碰到以下错误:
Loading:
Loading: 0 packages loaded
ERROR: Skipping '//tensorflow/tools/pip_package:build_pip_package': error loading package 'tensorflow/tools/pip_package': Encountered error while reading extension file 'cuda/build_defs.bzl': no such package '@local_config_cuda//cuda': Traceback (most recent call last):
Loading: Loading: 0 packages loaded ERROR: Skipping '//tensorflow/tools/pip_package:build_pip_package': error loading package 'tensorflow/tools/pip_package': Encountered error while reading extension file 'cuda/build_defs.bzl': no such package '@local_config_cuda//cuda': Traceback (most recent call last):这是一个已知问题(https://github.com/tensorflow/tensorflow/pull/11949),解决方法见https://github.com/tensorflow/tensorflow/pull/11949/commits/c5d311eaf8cc6471643b5c43810a1feb19662d6c,目前貌似还没有pick到发布分支,人肉pick下吧,应该就解决了。编译好后用下面命令在指定目录(如~/tmp/)生成whl安装包,然后就和前面一样安装即可。
bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/tmp/
bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/tmp/如果运行时出现下面错误:
ImportError: Traceback (most recent call last):
File "tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named pywrap_tensorflow_internal
ImportError: Traceback (most recent call last): File "tensorflow/python/pywrap_tensorflow.py", line 41, in <module> from tensorflow.python.pywrap_tensorflow_internal import * ImportError: No module named pywrap_tensorflow_internal根据https://stackoverflow.com/questions/35953210/error-running-basic-tensorflow-example,cd到非tensorflow源码目录即可。
Ubuntu 15.04 下Caffe + + CUDA 7.0 安装配置指南
Ubuntu 16.04下Matlab2014a+Anaconda2+OpenCV3.1+Caffe安装
Ubuntu 16.04系统下CUDA7.5配置Caffe教程
Caffe + Ubuntu 14.04 64bit + CUDA 6.5 配置说明
Caffe配置简明教程 ( Ubuntu 14.04 / CUDA 7.5 / cuDNN 5.1 / OpenCV 3.1 )