Compilation of SSE/AVX/FMA instruction set in tensorflow CPU environment

TensorFlow CPU environment SSE/AVX/FMA instruction set compilation

sess.run() gives the following 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.

# Installing tf via pip install tensorflow may cause a problem when sess.run()
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.

This means that your machine supports these instruction sets, but tensorflow does not add these instruction sets when compiling. You need to compile manually to get involved in these instruction sets

# 1. Download the latest TensorFlow
$ git clone https://github.com/tensorflow/tensorflow

# 2. Install 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
# If you are using Anaconda, you can skip the

# mac os
$ pip install six numpy wheel 
$ brew install coreutils # install 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. Start compiling TensorFlow

# 4.1 configure
$ cd tensorflow # cd to the top-level directory created
# configure when you want to choose whether something is supported, here it is recommended to choose N, otherwise the package will be wrong later, if the graphics card is supported, choose y when cuda
$ ./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.3Generate whl files
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

# 5 Install the just-compiled pip package
# The official documentation here uses the sudo command for the installation, if it is a personal computer, it is not recommended to use sudo, just pip directly.
$ pip install /tmp/tensorflow_pkg/tensorflow-{version}-none-any.whl

# 6 The next step is to verify that you've installed it successfully
$ python -c "import tensorflow as tf; print(tf.Session().run(tf.constant('Hello, TensorFlow')))"
# Then you'll see the following output
b'Hello, TensorFlow'

# Congratulations, you have successfully compiled tensorflow and Warning is all solved!

Error report solution

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
# Here MKL does not support Darwin (MAC), so you have to select N

ERROR: /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'

# This is because some packages are not supported during configure but y is selected, so remember to select n for all of them

 

Similar Posts: