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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.