Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

I have recently installed tensorflow (Windows CPU version) and received the following message:

Successfully installed tensorflow-1.4.0 tensorflow-tensorboard-0.4.0rc2

Then when I tried to run

import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() sess.run(hello) 'Hello, TensorFlow!' a = tf.constant(10) b = tf.constant(32) sess.run(a + b) 42 sess.close() 

(which I found through https://github.com/tensorflow/tensorflow)

I received the following message:

2017-11-02 01:56:21.698935: I C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

But when I ran

import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello)) 

it ran as it should and output Hello, TensorFlow!, which indicates that the installation was successful indeed but there is something else that is wrong.

Do you know what the problem is and how to fix it?

like image 931
csg Avatar asked Nov 02 '17 06:11

csg


People also ask

How do I know if my CPU supports AVX2?

To know if your CPU supports AVX, hit the Windows key, search for windows system information and look for your CPU model from this pop-up window. Then, go to the manufacturer's website, and with the help of the model number, find out whether your CPU model supports AVX or not.

Does TensorFlow require AVX?

– Does TensorFlow Require AVX2? The default installable TensorFlow does not come with AVX2 enabled. Therefore, to enable it, you must build it from its source code.

What is AVX2 CPU?

AVX2 (also known as Haswell New Instructions) expands most integer commands to 256 bits and introduces new instructions. They were first supported by Intel with the Haswell processor, which shipped in 2013.

How do I turn on AVX2?

Yes, we will add an option to enable AVX2 in the drop-down menu at: Project Property Pages | Configuration Properties | C/C++ | Code Generation | Enable Enhanced Instruction Set.


1 Answers

What is this warning about?

Modern CPUs provide a lot of low-level instructions, besides the usual arithmetic and logic, known as extensions, e.g. SSE2, SSE4, AVX, etc. From the Wikipedia:

Advanced Vector Extensions (AVX) are extensions to the x86 instruction set architecture for microprocessors from Intel and AMD proposed by Intel in March 2008 and first supported by Intel with the Sandy Bridge processor shipping in Q1 2011 and later on by AMD with the Bulldozer processor shipping in Q3 2011. AVX provides new features, new instructions and a new coding scheme.

In particular, AVX introduces fused multiply-accumulate (FMA) operations, which speed up linear algebra computation, namely dot-product, matrix multiply, convolution, etc. Almost every machine-learning training involves a great deal of these operations, hence will be faster on a CPU that supports AVX and FMA (up to 300%). The warning states that your CPU does support AVX (hooray!).

I'd like to stress here: it's all about CPU only.

Why isn't it used then?

Because tensorflow default distribution is built without CPU extensions, such as SSE4.1, SSE4.2, AVX, AVX2, FMA, etc. The default builds (ones from pip install tensorflow) are intended to be compatible with as many CPUs as possible. Another argument is that even with these extensions CPU is a lot slower than a GPU, and it's expected for medium- and large-scale machine-learning training to be performed on a GPU.

What should you do?

If you have a GPU, you shouldn't care about AVX support, because most expensive ops will be dispatched on a GPU device (unless explicitly set not to). In this case, you can simply ignore this warning by

# Just disables the warning, doesn't take advantage of AVX/FMA to run faster import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' 

... or by setting export TF_CPP_MIN_LOG_LEVEL=2 if you're on Unix. Tensorflow is working fine anyway, but you won't see these annoying warnings.


If you don't have a GPU and want to utilize CPU as much as possible, you should build tensorflow from the source optimized for your CPU with AVX, AVX2, and FMA enabled if your CPU supports them. It's been discussed in this question and also this GitHub issue. Tensorflow uses an ad-hoc build system called bazel and building it is not that trivial, but is certainly doable. After this, not only will the warning disappear, tensorflow performance should also improve.

like image 79
Maxim Avatar answered Sep 21 '22 21:09

Maxim