从源码构建Tensorflow时出现非法指令错误 [英] illegal instruction error when building Tensorflow from source

查看:1437
本文介绍了从源码构建Tensorflow时出现非法指令错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用bazel从源代码构建tensorflow,如下所述:
https://www.tensorflow.org/install/install_sources



继安装文档后,我成功编译了以下代码:

  bazel build -c opt --copt = -mavx --copt = -mavx2 --copt = -mfma --copt = -mfpmath = both \ 
--cxxopt = - D_GLIBCXX_USE_CXX11_ABI = 0 - config = cuda \
-k // tensorflow / tools / pip_package:build_pip_package

接受的答案此处和注释安装文档,将 - cxxopt = - D_GLIBCXX_USE_CXX11_ABI = 0添加到gcc 5及更高版本的build命令中。



但是,导入tensorflow为tf 导致错误

 非法指令(核心转储),退出python。 

我另外尝试过: conda update libgcc 没有用。



如何使用gcc 5.0从源代码构建tensorflow?

解决方案

这个错误消息告诉我你的程序是用你的处理器没有的指令编译的,看看你的构建字符串让我怀疑 -mavx2 -mfma 哪个AFAIK只在最近的(和高端的)CPU中实现。
请注意, gcc将会在你的CPU不支持的指令标志下正常编译,但程序不会在你的机器上运行。



为确保您的CPU支持这些标志,请在bash中运行 gcc -march = native -Q --help = target | grep enabled 并检查输出是否包含您要使用的所有构建标志(除 -mfpmath >不显示为已启用或禁用,因为它允许输出列表。为此,您需要检查完整的 gcc -march = ... 命令输出)。



要回答你的最终评论,没有办法启用这些指令,它们是用硬件实现的,可以在你的CPU上使用,或者它们不是。


I'm building tensorflow from source with bazel, as described here: https://www.tensorflow.org/install/install_sources

Following the installation doc, I successfully compile with the following:

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both \
--cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"--config=cuda \
-k //tensorflow/tools/pip_package:build_pip_package

a combination of the accepted answer here and a note in the installation documentation "to add --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" to the build command for gcc 5 and later".

however, import tensorflow as tf results in the error

illegal instruction (core dumped), exiting python.

I have additionally tried: conda update libgcc to no avail.

How can I build tensorflow from source with gcc 5.0?

解决方案

The error message tells me your program was compiled with instructions your processor doesn't have and a look at your build string makes me suspect of -mavx2 and -mfma which AFAIK are implemented only in rather recent (and high-end) CPUs. Please note, gcc will compile just fine with flags for instructions your CPU doesn't support, but the program won't run on your machine.

To make sure your CPU supports those flags, run in bash gcc -march=native -Q --help=target | grep enabled and check that the output contains all the build flags you want to use (with the exception of -mfpmath which doesn't show as enabled or disabled since it allows a list of output. For that you'll need to check the full gcc -march=... command output).

To answer to your final comment, there is no way to "enable" these instructions, they are implemented in hardware and either they are available on your CPU, or they aren't.

这篇关于从源码构建Tensorflow时出现非法指令错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆