[英]illegal instruction error when building Tensorflow from source
I'm building tensorflow from source with bazel, as described here: https://www.tensorflow.org/install/install_sources
我正在使用bazel从源代码构建tensorflow,如下所述:
https://www.tensorflow.org/install/install_sources
://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". 这里接受的答案和安装文档中的注释“将
--cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
到gcc 5及更高版本的构建命令中”。
however, import tensorflow as tf
results in the error 但是,
import tensorflow as tf
导致错误
illegal instruction (core dumped), exiting python.
I have additionally tried: conda update libgcc
to no avail. 我还试过:
conda update libgcc
无济于事。
How can I build tensorflow from source with gcc 5.0? 如何使用gcc 5.0从源代码构建tensorflow?
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. 错误消息告诉我你的程序是用你的处理器没有的指令编译的,看看你的构建字符串让我怀疑
-mavx2
和-mfma
哪个AFAIK只在最近(和高端)的CPU中实现。 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 . 请注意, gcc将使用标志进行编译,以获得CPU不支持的指令,但程序将无法在您的计算机上运行 。
To make sure your CPU supports those flags, run in bash gcc -march=native -Q --help=target | grep enabled
要确保您的CPU支持这些标志,请在bash中运行
gcc -march=native -Q --help=target | grep enabled
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). gcc -march=native -Q --help=target | grep enabled
并检查输出是否包含您要使用的所有构建标志( -mfpmath
除外,它不显示为启用或禁用,因为它允许输出列表。为此,您需要检查完整gcc -march=...
命令输出)。
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. 为了回答你的最终评论,没有办法“启用”这些指令,它们是用硬件实现的,它们可以在你的CPU上使用,或者它们不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.