TensorFlow CPU环境 SSE/AVX/FMA 指令集编译
TensorFlow CPU環(huán)境 SSE/AVX/FMA 指令集編譯
sess.run()出現(xiàn)如下Warning
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.
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.
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.
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.
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.
這說明你的machine支持這些指令集但是TensorFlow在編譯的時候并沒有加入這些指令集,需要手動編譯才能夠介入這些指令集。
# 1. 下載最新的 TensorFlow $ git clone https://github.com/tensorflow/tensorflow# 2. 安裝 bazel # mac os $ brew install bazel# ubuntu $ sudo apt-get update && sudo apt-get install bazel# Windows $ choco install bazel# 3. Install TensorFlow Python dependencies # 如果使用的是Anaconda這部可以跳過# mac os $ pip install six numpy wheel $ brew install coreutils # 安裝coreutils for cuda $ sudo xcode-select -s /Applications/Xcode.app # set build tools# ubuntu sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel sudo apt-get install libcupti-dev# 4. 開始編譯TensorFlow# 4.1 configure $ cd tensorflow # cd to the top-level directory created # configure 的時候要選擇一些東西是否支持,這里建議都選N,不然后面會包錯,如果支持顯卡,就在cuda的時候選擇y $ ./configure # configure# 4.2 bazel build # CUP-only $ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package# GPU support bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package# 4.3生成whl文件 bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg# 5 安裝剛剛編譯好的pip 包 # 這里安裝的時候官方文檔使用的是sudo命令,如果是個人電腦,不建議使用sudo, 直接pip即可。 $ pip install /tmp/tensorflow_pkg/tensorflow-{version}-none-any.whl# 6 接下來就是驗證你是否已經(jīng)安裝成功 $ python -c "import tensorflow as tf; print(tf.Session().run(tf.constant('Hello, TensorFlow')))" # 然后你就會看到如下輸出 b'Hello, TensorFlow'# 恭喜你,成功編譯了tensorflow,Warning也都解決了!報錯解決
Do you wish to build TensorFlow with MKL support? [y/N] y MKL support will be enabled for TensorFlow Do you wish to download MKL LIB from the web? [Y/n] y Darwin is unsupported yet # 這里MKL不支持Darwin(MAC),因此要選擇NERROR: /Users/***/Documents/tensorflow/tensorflow/core/BUILD:1331:1: C++ compilation of rule '//tensorflow/core:lib_hash_crc32c_accelerate_internal' failed: cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG ... (remaining 32 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1. clang: error: no such file or directory: 'y' clang: error: no such file or directory: 'y'# 這里是因為在configure的時候有些包不支持但是選擇了y,因此記住一點所有的都選nReference
[1]: https://www.tensorflow.org/install/install_sources
?
先概述下問題:之前是在終端中使用 pip install tensorflow==1.1.0 命令來完成安裝的,在eclipse中能夠運行,但是卻會提示報錯,在控制臺輸出一串未使用SSE4.1,SSE4,2等字樣的信息,本人有強迫癥無法容忍項目中各種報錯提示的存在,然后花了半天功夫解決了這個問題,步驟如下:
???這個問題的出現(xiàn)主要是和tensorflow的安裝方式有關(guān)系,使用pip安裝就會出現(xiàn)對代碼編譯優(yōu)化的問題,使得你電腦有SSE4.1等命令,卻無法調(diào)用來加速訓練,所以最好是安裝時候多費點事,能夠解決這個報錯提示的問題,同時也能在以后的項目中發(fā)揮本機CPU的性能進行加速訓練
第一步:卸載已經(jīng)安裝的tensorflow???命令: sudo pip uninstall tensorflow??(一定要先卸載,不然之后所有工作都是白費)
第二步:創(chuàng)建文件夾并下載源碼??????????命令: git?clone?--recurse-submodules?https://github.com/tensorflow/tensorflow
第三步: 安裝bazel工具(提示最后兩條命令,別忘記輸入sudo,否則會出錯)??命令如下:
?????????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所需的各種包??命令:sudo?apt-get?install?python-numpy?python-dev?python-pip?python-wheel
第五步:配置tensorflow???命令如下:
????????cd tensorflow/????(進入第二步中創(chuàng)建的tensorflow文件夾)
???????./configure??
此時會彈出一些配置需要你填寫,首先彈出的是選擇python的路徑和版本,在提示信息中會給出defult信息,我們就完全填寫defult中的信息就行(避免出錯和麻煩)
完成之后會讓你輸入Y/N選擇tensorflow是否支持google cloud,Hadoop等,建議Hadoop選Y其他選擇N即可(如果都選Y又需要額外下載很多東西)
第六步:生成pip安裝包???命令: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??(時間較長,請耐心等待) (其中msse3,msse4.1 mavx等表示cpu支持的指令集,不同機器會有差異,如果你電腦的CPU不支持AVX指令,但在此處卻輸出了--copt=-mavx 最后還是會報錯提示:你的機器不支持此指令,所以在寫這條命令時候,建議大家下載CPU-Z看看本機CPU支持的指令,然后對應(yīng)寫此指令)
第七步: 安裝??命令如下:
??????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??(最后是生成的軟件包名,會有不同,根據(jù)自己生成的包名填寫)
補充:如何查看生成的包名????在/目錄下進入tmp再進入tensorflow_pkg文件???里面只有一個.whl的文件,即可查看包名,用于替換上述第二條命令中的最后一部分即可
完成上述命令后 等待一會下載即可完成
-https://blog.csdn.net/qq_36511757/article/details/77895316
https://www.cnblogs.com/shihuc/p/6609739.html
總結(jié)
以上是生活随笔為你收集整理的TensorFlow CPU环境 SSE/AVX/FMA 指令集编译的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【游戏技术】SourceMod 用法说明
- 下一篇: 警告:Your CPU supports