首页 > 解决方案 > “您的 CPU 支持未编译此 TensorFlow 二进制文件以使用的指令:AVX2”错误

问题描述

我在我的机器上安装了 tensorflow gpu。我在我的机器上安装了 CUDA 工具包 9.0 和 cuDNN 7.0。

当我通过https://www.tensorflow.org/install/install_windows中的步骤来测试我的安装时。通过进入程序

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

但我收到以下错误“您的 CPU 支持未编译此 TensorFlow 二进制文件以使用的指令:AVX2”错误。

你能告诉我如何解决吗?

>>> sess = tf.Session()
2018-07-25 23:27:54.477511: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-07-25 23:27:55.607237: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1392] Found device 0 with properties:
name: Quadro M2000 major: 5 minor: 2 memoryClockRate(GHz): 1.1625
pciBusID: 0000:03:00.0
totalMemory: 4.00GiB freeMemory: 3.34GiB
2018-07-25 23:27:55.612178: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1471] Adding visible gpu devices: 0
2018-07-25 23:27:55.977046: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-07-25 23:27:55.980238: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:958]      0
2018-07-25 23:27:55.982308: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:971] 0:   N
2018-07-25 23:27:55.984488: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3069 MB memory) -> physical GPU (device: 0, name: Quadro M2000, pci bus id: 0000:03:00.0, compute capability: 5.2)
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>> print(sess.run(hello))
b'Hello, TensorFlow!'

标签: tensorflow

解决方案


我也一直想知道这个警告是什么意思。在快速浏览之后,我发现了以下内容: Adveance Vector Extensions是将整数运算扩展到浮点数的指令。例如:FUSE MULTIPLY ADD

引用上述来源“融合乘加(有时称为 FMA 或 fmadd)是一步执行的浮点乘加运算,采用单次舍入。也就是说,未融合乘加将计算乘积 b×c,将其舍入到 N 个有效位,将结果加到 a,然后舍入到 N 个有效位,融合乘加将在舍入最终结果之前将整个表达式 a+b×c 计算为其全精度低至 N 个有效位。”

如果您的编译器中未启用 AVX,则操作 a+bxc 将按顺序执行,而 avx 指令将其执行到一个操作单元中。

默认情况下,tensorflow 的构建标志似乎不包括对 AVX 指令的支持,因为配置部分在从源页面安装时指出。

为了能够抑制此警告,您必须从源代码构建 tensorflow,并在配置部分使用额外的这些附加标志

bazel build -c opt --copt=-mavx --copt=-mavx2

我怀疑默认情况下会省略这些标志,因为并非所有 cpus 都支持这些指令。

有关更多详细信息,请参阅此答案和此 github问题

编辑

是您可以使用的构建的详尽列表,具体取决于您收到的警告,包括这个。


推荐阅读