ubuntu解決tensorflow C++提速警告SSE4.1 SSE4.2 AVX AVX2 FMA XLA

看過前幾篇的應該知道每次tensorflow c++預測時都會報警如下圖所示:

即:

2019-07-16 10:33:52.057179: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-07-16 10:33:52.082548: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3407965000 Hz
2019-07-16 10:33:52.082883: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x44d56d0 executing computations on platform Host. Devices:
2019-07-16 10:33:52.082903: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2019-07-16 10:33:52.557067: I tensorflow/core/common_runtime/optimization_registry.cc:35] Running all optimization passes in grouping 0. If you see this a lot, you might be extending the graph too many times (which means you modify the graph many times before execution). Try reducing graph modifications or using SavedModel to avoid any graph modification
2019-07-16 10:33:52.694202: I tensorflow/core/common_runtime/optimization_registry.cc:35] Running all optimization passes in grouping 1. If you see this a lot, you might be extending the graph too many times (which means you modify the graph many times before execution). Try reducing graph modifications or using SavedModel to avoid any graph modification
2019-07-16 10:33:53.157970: I tensorflow/core/common_runtime/optimization_registry.cc:35] Running all optimization passes in grouping 2. If you see this a lot, you might be extending the graph too many times (which means you modify the graph many times before execution). Try reducing graph modifications or using SavedModel to avoid any graph modification
2019-07-16 10:33:53.228415: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1337] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.

雖然很多人說這些只是提速警告不用管,但是傳說會有很大的性能提升,所以還是想解決。

一、解決AVX AVX2 SSE4.1 SSE4.2 FMA

我查了一些資料想解決這個警告 


https://stackoverflow.com/questions/57049454/tensorflows-warningextending-the-graph-too-many-times-which-means-you-modify  (翻牆找的)

https://stackoverflow.com/questions/47068709/your-cpu-supports-instructions-that-this-tensorflow-binary-was-not-compiled-to-u


https://github.com/lakshayg/tensorflow-build

https://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions

https://www.tensorflow.org/install/source

https://blog.csdn.net/edisonleeee/article/details/89503365

https://github.com/lakshayg/tensorflow-build

 

有人說 直接 pip install --ignore-installed --upgrade "Download URL" 或者

pip --upgrade tensorflow

pip unistall tensorflow

pip list

pip install tensorflow-1.9.0-cp36-cp36m-win_amd64.whl

但是還是不行。

root@rootwd-Default-string:/media/root/Ubuntu311/projects/Ecology_projects/copy/ThirdParty/tensorflow-master# ./configure
WARNING: Running Bazel server needs to be killed, because the startup options are different.
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.24.1 installed.
Please specify the location of python. [Default is /usr/bin/python]: bazel shutdown


Invalid python path: bazel shutdown cannot be found.
Please specify the location of python. [Default is /usr/bin/python]: 


Found possible Python library paths:
  /usr/lib/python3/dist-packages
  /usr/local/lib/python3.5/dist-packages
Please input the desired Python library path to use.  Default is [/usr/lib/python3/dist-packages]

Do you wish to build TensorFlow with XLA JIT support? [Y/n]: Y
XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: 
No OpenCL SYCL support will be enabled for TensorFlow.

Do you wish to build TensorFlow with ROCm support? [y/N]: 
No ROCm support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: 
No CUDA support will be enabled for TensorFlow.

Do you wish to download a fresh release of clang? (Experimental) [y/N]: 
Clang will not be downloaded.

Do you wish to build TensorFlow with MPI support? [y/N]: 
No MPI support will be enabled for TensorFlow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: 
Not configuring the WORKSPACE for Android builds.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
	--config=mkl         	# Build with MKL support.
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=gdr         	# Build with GDR support.
	--config=verbs       	# Build with libverbs support.
	--config=ngraph      	# Build with Intel nGraph support.
	--config=numa        	# Build with NUMA support.
	--config=dynamic_kernels	# (Experimental) Build kernels into separate shared objects.
Preconfigured Bazel build configs to DISABLE default on features:
	--config=noaws       	# Disable AWS S3 filesystem support.
	--config=nogcp       	# Disable GCP support.
	--config=nohdfs      	# Disable HDFS support.
	--config=noignite    	# Disable Apache Ignite support.
	--config=nokafka     	# Disable Apache Kafka support.
	--config=nonccl      	# Disable NVIDIA NCCL support.
Configuration finished
root@rootwd-Default-string:/media/root/Ubuntu311/projects/Ecology_projects/copy/ThirdParty/tensorflow-master# bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2 -k
Starting local Bazel server and connecting to it...
WARNING: Usage: bazel build <options> <targets>.
Invoke `bazel help build` for full description of usage and options.
Your request is correct, but requested an empty set of targets. Nothing will be built.
INFO: Analysed 0 targets (0 packages loaded, 0 targets configured).
INFO: Found 0 targets...
INFO: Elapsed time: 1.805s, Critical Path: 0.01s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
root@rootwd-Default-string:/media/root/Ubuntu311/projects/Ecology_projects/copy/ThirdParty/tensorflow-master# 

後來又看到有人說升級到2.0就可以了 pip install tensorflow==2.0.0-beta1 但是還是不行!

root@rootwd-Default-string:/media/root/Ubuntu311/projects/Ecology_projects/copy/ThirdParty# pip install tensorflow-2.0.0b1-cp35-cp35m-manylinux1_x86_64.whl
Processing ./tensorflow-2.0.0b1-cp35-cp35m-manylinux1_x86_64.whl
Requirement already satisfied: keras-applications>=1.0.6 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (1.0.8)
Requirement already satisfied: astor>=0.6.0 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (0.8.0)
Requirement already satisfied: numpy<2.0,>=1.14.5 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (1.16.4)
Requirement already satisfied: tb-nightly<1.14.0a20190604,>=1.14.0a20190603 in /usr/local/lib/python3.5/dist-packages (from tensorflow==2.0.0b1) (1.14.0a20190603)
Requirement already satisfied: keras-preprocessing>=1.0.5 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (1.1.0)
Requirement already satisfied: gast>=0.2.0 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (0.2.2)
Requirement already satisfied: google-pasta>=0.1.6 in /usr/local/lib/python3.5/dist-packages (from tensorflow==2.0.0b1) (0.1.7)
Requirement already satisfied: tf-estimator-nightly<1.14.0.dev2019060502,>=1.14.0.dev2019060501 in /usr/local/lib/python3.5/dist-packages (from tensorflow==2.0.0b1) (1.14.0.dev2019060501)
Requirement already satisfied: wheel>=0.26 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (0.33.4)
Collecting protobuf>=3.6.1 (from tensorflow==2.0.0b1)
  Using cached https://files.pythonhosted.org/packages/55/34/7158a5ec978f12307eb361a8c4fdd867a8e2a0ab63fac99e5f555ee796d2/protobuf-3.9.0-cp35-cp35m-manylinux1_x86_64.whl
Requirement already satisfied: grpcio>=1.8.6 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (1.22.0)
Requirement already satisfied: six>=1.10.0 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (1.12.0)
Requirement already satisfied: absl-py>=0.7.0 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (0.7.1)
Requirement already satisfied: termcolor>=1.1.0 in /root/.local/lib/python3.5/site-packages (from tensorflow==2.0.0b1) (1.1.0)
Requirement already satisfied: wrapt>=1.11.1 in /usr/local/lib/python3.5/dist-packages (from tensorflow==2.0.0b1) (1.11.2)
Requirement already satisfied: h5py in /root/.local/lib/python3.5/site-packages (from keras-applications>=1.0.6->tensorflow==2.0.0b1) (2.9.0)
Requirement already satisfied: werkzeug>=0.11.15 in /root/.local/lib/python3.5/site-packages (from tb-nightly<1.14.0a20190604,>=1.14.0a20190603->tensorflow==2.0.0b1) (0.15.4)
Requirement already satisfied: setuptools>=41.0.0 in /root/.local/lib/python3.5/site-packages (from tb-nightly<1.14.0a20190604,>=1.14.0a20190603->tensorflow==2.0.0b1) (41.0.1)
Requirement already satisfied: markdown>=2.6.8 in /root/.local/lib/python3.5/site-packages (from tb-nightly<1.14.0a20190604,>=1.14.0a20190603->tensorflow==2.0.0b1) (3.1.1)
Installing collected packages: protobuf, tensorflow
Successfully installed protobuf-3.9.0 tensorflow-2.0.0b1
root@rootwd-Default-string:/media/root/Ubuntu311/projects/Ecology_projects/copy/ThirdParty# 

我在tensorflow的issue和stackoverflow以及別的網站上都有提問。

後來還是完完全全徹底卸載了所有的tensorflow(不止命令行,將所有相關的文件夾都刪掉了),然後試着下載tensorflow-2.0.0-alpha0.tar然後:



./configure
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2 //tensorflow:libtensorflow_cc.so

但是不行。

https://github.com/tensorflow/tensorflow/releases/tag/v2.0.0-alpha0

http://mirror.tensorflow.org/www.sqlite.org/2019/sqlite-amalgamation-3280000.zip 
https://www.sqlite.org/2019/sqlite-amalgamation-3280000.zip


Executing genrule //tensorflow/cc:nn_ops_genrule failed (Exit 127)
bazel-out/host/bin/tensorflow/cc/ops/nn_ops_gen_cc: symbol lookup error: bazel-out/host/bin/tensorflow/cc/ops/nn_ops_gen_cc: undefined symbol: _ZN10tensorflow15shape_inference21FusedBatchNormV3ShapeEPNS0_16InferenceContextE
Target //tensorflow:libtensorflow_cc.so failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2612.253s, Critical Path: 100.09s
INFO: 6033 processes: 6033 local.
FAILED: Build did NOT complete successfully

然後我將之前的又刪掉卸載掉,然後下載了tensorflow-2.0.0-beta1.tar 

./configure
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2 //tensorflow:libtensorflow_cc.so

然後我發現警告已經消失了很多!!!!

同時我發現 這次的tensorflow不再需要-Wl,--no-as-needed 這些flag了。

現在只剩下下面這些警告了:

2019-07-25 15:47:02.775473: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3406455000 Hz
2019-07-25 15:47:02.775793: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2f59c70 executing computations on platform Host. Devices:
2019-07-25 15:47:02.775812: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
Session successfully created.
2019-07-25 15:47:02.858641: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1483] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

依舊放上小不點的美照

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章