<p><strong>让我先回答您的第三个问题:</strong></p>
<p>如果要在conda env中运行自编译版本,可以。这些是我运行的一般说明,以使tensorflow安装在我的系统上,并附带附加说明。注意:这个版本是为运行Ubuntu16.04LTS的AMDA10-7850版本(检查你的CPU是否支持什么指令…可能有所不同)。我在conda env中使用Python 3.5。本文将介绍tensorflow源代码安装页面和上面提供的答案。</p>
<pre><code>git clone https://github.com/tensorflow/tensorflow
# Install Bazel
# https://bazel.build/versions/master/docs/install.html
sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel
# Create your virtual env with conda.
source activate YOUR_ENV
pip install six numpy wheel, packaging, appdir
# Follow the configure instructions at:
# https://www.tensorflow.org/install/install_sources
# Build your build like below. Note: Check what instructions your CPU
# support. Also. If resources are limited consider adding the following
# tag --local_resources 2048,.5,1.0 . This will limit how much ram many
# local resources are used but will increase time to compile.
bazel build -c opt --copt=-mavx --copt=-msse4.1 --copt=-msse4.2 -k //tensorflow/tools/pip_package:build_pip_package
# Create the wheel like so:
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
# Inside your conda env:
pip install /tmp/tensorflow_pkg/NAME_OF_WHEEL.whl
# Then install the rest of your stack
pip install keras jupyter etc. etc.
</code></pre>
<p><strong>关于第二个问题:</strong></p>
<p>在我看来,一个经过优化的自编版本是非常值得的。在我的特殊设置中,过去需要560-600秒的计算现在只需要大约300秒!虽然确切的数字会有所不同,但我认为您可以预期在您的特定设置上的速度通常会提高35-50%。</p>
<p><strong>最后一个问题:</strong></p>
<p>上面已经提供了很多答案。综上所述:<a href="https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#AVX2" rel="noreferrer">AVX</a>,<a href="https://en.wikipedia.org/wiki/SSE4" rel="noreferrer">SSE4.1, SSE4.2</a>,MFA是X86 cpu上不同类型的扩展指令集。许多包含处理矩阵或向量运算的优化指令。</p>
<p>我将强调我自己的误解,希望能为您节省一些时间:并不是说SSE4.2是取代SSE4.1的指令的新版本。SSE4=SSE4.1(一组47条指令)+SSE4.2(一组7条指令)。</p>
<p>在tensorflow编译的上下文中,如果您的计算机支持AVX2和AVX,以及SSE4.1和SSE4.2,那么您应该为所有人放置这些优化标志。不要像我这样做,只要去SSE4.2认为它是新的,应该超越SSE4.1。那显然是错的!我不得不重新编译,因为那花了我整整40分钟。</p>