ubuntu16.04解決tensorflow提示未編譯使用SSE3、SSE4.1、SSE4.2、AVX、AVX2、FMA的問題【轉】


本文轉載自:https://blog.csdn.net/Nicholas_Wong/article/details/70215127

rticle/details/70215127

在我的機器上出現的提示信息如下所示:

 

  1.  
    W tensorflow/core/platform/cpu_feature_guard.cc: 45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
  2.  
    W tensorflow/core/platform/cpu_feature_guard.cc: 45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
  3.  
    W tensorflow/core/platform/cpu_feature_guard.cc: 45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
  4.  
    W tensorflow/core/platform/cpu_feature_guard.cc: 45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
  5.  
    W tensorflow/core/platform/cpu_feature_guard.cc: 45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
  6.  
    W tensorflow/core/platform/cpu_feature_guard.cc: 45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.<span> </span>

 

那么需要說明的是:這些是warnings,不是error。這些warings的意思是說:你的機器上有這些指令集可以用,並且用了他們會加快你的CPU運行速度,但是你的TensorFlow在編譯的時候並沒有用到這些指令集。

 

我的tensorflow在安裝的時候采用的pip install指令,這種安裝方式會存在這種問題。主要有兩種解決方法,一種是修改警告信息的顯示級別,使這種信息不再出現,另外一種就是自己重新編譯安裝tensorflow,在編譯的時候使用這些指令集。這里我嘗試第二種解決方法。並且由於我的機器上沒有高效的GPU,所以我嘗試安裝的是CPU版本。

 

首先,卸載已經安裝的tensorflow:

 

sudo pip uninstall tensorflow

 

 

然后,克隆Tensorflow倉庫:

 

git clone --recurse-submodules https://github.com/tensorflow/tensorflow

上面的命令會在你的當前文件夾中創建一個叫做“tensorflow”的文件夾,下載的文件都存在里面。

由於編譯安裝tensorflow的時候要用到Bazel工具,所以接下來我們安裝Bazel。按照官網指導輸入以下命令:

 

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 -
sudo apt-get update && sudo apt-get install bazel
sudo apt-get upgrade bazel
然后安裝tensorflow所需要的其他依賴

 

 

[html]  view plain  copy
 
  1. <code class="language-html">sudo apt-get install python-numpy python-dev python-pip python-wheel</code>  
然后進入tensorflow文件夾,運行tensorflow的配置程序:

 

 

  1.  
    cd tensorflow/
  2.  
    ./configure
對我來說,在配置過程中出現如下錯誤:

 

 

Problem with java installation: couldn't find/access rt.jar in /usr/lib/jvm/java-9-openjdk-amd64
我沒有仔細研究原因,但是我用如下命令把java-9卸載之后就沒有問題了。

 

 

sudo apt-get purge openjdk-9*

然后用如下命令來生成一個pip的安裝包:

 

 

[html]  view plain  copy
 
  1. <code class="language-html">bazel build -c opt --copt=-msse3 --copt=-msse4.1 --copt=-msse4.2 --copt=-mavx --copt=-mavx2 --copt=-mfma //tensorflow/tools/pip_package:build_pip_package</code>  

這是一個相當耗時的過程。

上述命令會生成一個叫做build_pip_package的腳本,按照如下命令運行這個腳本,在/tmp/tensorflow_pkg文件夾中創建pip的安裝包:

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

然后運行下面的命令來安裝。需要說明的是,由於平台的不同,可能軟件包的名字是不一樣的。

sudo pip install /tmp/tensorflow_pkg/tensorflow-1.1.0rc1-cp27-cp27mu-linux_x86_64.whl
安裝成功,意味着大功告成。

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM