首页 > 解决方案 > 编译错误,在没有 avx2 支持的情况下构建 tensorflow v1.14.0

问题描述

使用 Debian 10 Buster,Python v2.7。我尝试在没有 avx2 支持的情况下构建特定的 tensorflow v1.14.0,因为我收到以下错误:

11 月 4 日 17:12:32 moodle37 内核:[9773297.574293] 陷阱:python2.7 [4570] 陷阱无效操作码 ip:7fb9b74bca59 sp:7ffdb7605e10 错误:libtensorflow_framework.so.1 [7fb9b6d97000+18f8000] 中的 0

1)我用 git 克隆了 tensorflow

2) 签出 v1.14.0。

>git status
HEAD detached at v1.14.0

3)

gcc -Q -march=native --help=target | grep march
  -march=                               nehalem

所以 CPU 代号是 nehalem。

4)我./configure 与构建选项一起使用:

-march=nehalem mavx -msse4.1 -msse4.2 -mpclmul -mpopcnt -maes -mno-avx2

5) 执行

bazel build //tensorflow/tools/pip_package:build_pip_package

但我得到了构建错误:

ERROR: /root/inst/tensorflow_src/tensorflow/core/kernels/BUILD:3255:1: C++ compilation of rule '//tensorflow/core/kernels:matrix_square_root_op' failed (Exit 1)
gcc: fatal error: Killed signal terminated program cc1plus
compilation terminated.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 18990.253s, Critical Path: 381.93s
INFO: 2372 processes: 2372 local.
FAILED: Build did NOT complete successfully

6) 执行

bazel build --verbose_failures //tensorflow/tools/pip_package:build_pip_package  

出现以下错误:

ERROR: /root/inst/tensorflow_src/tensorflow/core/kernels/BUILD:3255:1: C++ compilation of rule '//tensorflow/core/kernels:matrix_square_root_op' failed (Exit 1): gcc failed: error executing command
  (cd /root/.cache/bazel/_bazel_root/d7c6443e63bbc3c61de28c70992e7b9c/execroot/org_tensorflow && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/usr/bin/python \
    PYTHON_LIB_PATH=/usr/local/lib/python2.7/dist-packages \
    TF_CONFIGURE_IOS=0 \
    TF_DOWNLOAD_CLANG=0 \
    TF_NEED_CUDA=0 \
    TF_NEED_OPENCL_SYCL=0 \
    TF_NEED_ROCM=0 \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF bazel-out/k8-py2-opt/bin/tensorflow/core/kernels/_objs/matrix_square_root_op/matrix_square_root_op.pic.d '-frandom-seed=bazel-out/k8-py2-opt/bin/tensorflow/core/kernels/_objs/matrix_square_root_op/matrix_square_root_op.pic.o' -fPIC -D__CLANG_SUPPORT_DYN_ANNOTATION__ -DEIGEN_MPL2_ONLY '-DEIGEN_MAX_ALIGN_BYTES=64' '-DEIGEN_HAS_TYPE_TRAITS=0' -DTF_USE_SNAPPY -iquote . -iquote bazel-out/k8-py2-opt/bin -iquote external/com_google_absl -iquote bazel-out/k8-py2-opt/bin/external/com_google_absl -iquote external/eigen_archive -iquote bazel-out/k8-py2-opt/bin/external/eigen_archive -iquote external/local_config_sycl -iquote bazel-out/k8-py2-opt/bin/external/local_config_sycl -iquote external/nsync -iquote bazel-out/k8-py2-opt/bin/external/nsync -iquote external/gif_archive -iquote bazel-out/k8-py2-opt/bin/external/gif_archive -iquote external/jpeg -iquote bazel-out/k8-py2-opt/bin/external/jpeg -iquote external/protobuf_archive -iquote bazel-out/k8-py2-opt/bin/external/protobuf_archive -iquote external/com_googlesource_code_re2 -iquote bazel-out/k8-py2-opt/bin/external/com_googlesource_code_re2 -iquote external/farmhash_archive -iquote bazel-out/k8-py2-opt/bin/external/farmhash_archive -iquote external/fft2d -iquote bazel-out/k8-py2-opt/bin/external/fft2d -iquote external/highwayhash -iquote bazel-out/k8-py2-opt/bin/external/highwayhash -iquote external/zlib_archive -iquote bazel-out/k8-py2-opt/bin/external/zlib_archive -isystem external/eigen_archive -isystem bazel-out/k8-py2-opt/bin/external/eigen_archive -isystem external/nsync/public -isystem bazel-out/k8-py2-opt/bin/external/nsync/public -isystem external/gif_archive/lib -isystem bazel-out/k8-py2-opt/bin/external/gif_archive/lib -isystem external/protobuf_archive/src -isystem bazel-out/k8-py2-opt/bin/external/protobuf_archive/src -isystem external/farmhash_archive/src -isystem bazel-out/k8-py2-opt/bin/external/farmhash_archive/src -isystem external/zlib_archive -isystem bazel-out/k8-py2-opt/bin/external/zlib_archive -DEIGEN_AVOID_STL_ARRAY -Iexternal/gemmlowp -Wno-sign-compare -fno-exceptions '-ftemplate-depth=900' -msse3 -pthread -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c tensorflow/core/kernels/matrix_square_root_op.cc -o bazel-out/k8-py2-opt/bin/tensorflow/core/kernels/_objs/matrix_square_root_op/matrix_square_root_op.pic.o)
Execution platform: @bazel_tools//platforms:host_platform
gcc: fatal error: Killed signal terminated program cc1plus
compilation terminated.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 3559.068s, Critical Path: 448.60s
INFO: 397 processes: 397 local.
FAILED: Build did NOT complete successfully

编辑1:

191105 20:22:26.151:I 1354 [com.google.devtools.build.lib.exec.local.LocalSpawnRunner$SubprocessHandler.start] starting local subprocess #314, argv: /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 -D_FORTIFY_SOURCE=1 -DNDEBUG -ffunction-sections -fdata-sections -std=c++0x -MD -MF bazel-out/k8-py2-opt/bin/te...tin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -c tensorflow/core/kernels/matrix_square_root_op.cc -o bazel-out/k8-py2-opt/bin/tensorflow/core/kernels/_objs/matrix_square_root_op/matrix_square_root_op.pic.o
191105 20:22:26.151:I 1354 [com.google.devtools.build.lib.exec.local.LocalSpawnRunner$SubprocessHandler.stepLog] prefetching inputs for local execution (#314 Compiling tensorflow/core/kernels/matrix_square_root_op.cc)
191105 20:22:26.151:I 1354 [com.google.devtools.build.lib.exec.local.LocalSpawnRunner$SubprocessHandler.setState] Step #314 time: 0.001 delta: 0.001 state: PARSING --> PREFETCHING_LOCAL_INPUTS
191105 20:22:26.152:I 1354 [com.google.devtools.build.lib.exec.local.LocalSpawnRunner$SubprocessHandler.stepLog] running locally (#314 Compiling tensorflow/core/kernels/matrix_square_root_op.cc)
191105 20:22:26.152:I 1354 [com.google.devtools.build.lib.exec.local.LocalSpawnRunner$SubprocessHandler.setState] Step #314 time: 0.002 delta: 0.001 state: PREFETCHING_LOCAL_INPUTS --> LOCAL_ACTION_RUNNING
191105 20:29:22.020:I 1354 [com.google.devtools.build.lib.exec.local.LocalSpawnRunner$SubprocessHandler.setState] Step #314 time: 415.868 delta: 415.866 state: LOCAL_ACTION_RUNNING --> SUCCESS
191105 20:29:22.363:W 1354 [com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run] Aborting evaluation due to com.google.devtools.build.lib.skyframe.ActionExecutionFunction$ActionExecutionFunctionException: com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException: C++ compilation of rule '//tensorflow/core/kernels:matrix_square_root_op' failed (Exit 1): gcc failed: error executing command
  (cd /moodledata/inst/.cache/bazel/_bazel_root/ebeb582d6679e454bd341748991b8998/execroot/org_tensorflow && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/usr/bin/python \
    PYTHON_LIB_PATH=/usr/local/lib/python2.7/dist-packages \
    TF_CONFIGURE_IOS=0 \
    TF_DOWNLOAD_CLANG=0 \
    TF_NEED_CUDA=0 \
    TF_NEED_OPENCL_SYCL=0 \
    TF_NEED_ROCM=0 \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF bazel-out/k8-py2-opt/bin/tensorflow/core/kernels/_objs/matrix_square_root_op/matrix_square_root_op.pic.d '-frandom-seed=bazel-out/k8-py2-opt/bin/tensorflow/core/kernels/_objs/matrix_square_root_op/matrix_square_root_op.pic.o' -fPIC -D__CLANG_SUPPORT_DYN_ANNOTATION__ -DEIGEN_MPL2_ONLY '-DEIGEN_MAX_ALIGN_BYTES=64' '-DEIGEN_HAS_TYPE_TRAITS=0' -DTF_USE_SNAPPY -iquote . -iquote bazel-out/k8-py2-opt/bin -iquote external/com_google_absl -iquote bazel-out/k8-py2-opt/bin/external/com_google_absl -iquote external/eigen_archive -iquote bazel-out/k8-py2-opt/bin/external/eigen_archive -iquote external/local_config_sycl -iquote bazel-out/k8-py2-opt/bin/external/local_config_sycl -iquote external/nsync -iquote bazel-out/k8-py2-opt/bin/external/nsync -iquote external/gif_archive -iquote bazel-out/k8-py2-opt/bin/external/gif_archive -iquote external/jpeg -iquote bazel-out/k8-py2-opt/bin/external/jpeg -iquote external/protobuf_archive -iquote bazel-out/k8-py2-opt/bin/external/protobuf_archive -iquote external/com_googlesource_code_re2 -iquote bazel-out/k8-py2-opt/bin/external/com_googlesource_code_re2 -iquote external/farmhash_archive -iquote bazel-out/k8-py2-opt/bin/external/farmhash_archive -iquote external/fft2d -iquote bazel-out/k8-py2-opt/bin/external/fft2d -iquote external/highwayhash -iquote bazel-out/k8-py2-opt/bin/external/highwayhash -iquote external/zlib_archive -iquote bazel-out/k8-py2-opt/bin/external/zlib_archive -isystem external/eigen_archive -isystem bazel-out/k8-py2-opt/bin/external/eigen_archive -isystem external/nsync/public -isystem bazel-out/k8-py2-opt/bin/external/nsync/public -isystem external/gif_archive/lib -isystem bazel-out/k8-py2-opt/bin/external/gif_archive/lib -isystem external/protobuf_archive/src -isystem bazel-out/k8-py2-opt/bin/external/protobuf_archive/src -isystem external/farmhash_archive/src -isystem bazel-out/k8-py2-opt/bin/external/farmhash_archive/src -isystem external/zlib_archive -isystem bazel-out/k8-py2-opt/bin/external/zlib_archive -DEIGEN_AVOID_STL_ARRAY -Iexternal/gemmlowp -Wno-sign-compare -fno-exceptions '-ftemplate-depth=900' -msse3 -pthread -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c tensorflow/core/kernels/matrix_square_root_op.cc -o bazel-out/k8-py2-opt/bin/tensorflow/core/kernels/_objs/matrix_square_root_op/matrix_square_root_op.pic.o)
Execution platform: @bazel_tools//platforms:host_platform while evaluating ActionLookupData{actionLookupKey=//tensorflow/core/kernels:matrix_square_root_op BuildConfigurationValue.Key[06916201e0a2e3a731dd7c8fca228a97] false, actionIndex=1}

我怎样才能解决这个问题?

- 解决方案:

我有 2 GB RAM 用于虚拟机。将 RAM 增加到 8 GB 后,构建成功完成。

标签: python-2.7tensorflowgccbuildbazel

解决方案


在这里提到解决方案(回答部分),即使它出现在评论部分(感谢 Laszlo 和 jdehesa)和 Questoin,为了社区的利益

当尝试使用Bazelwithout构建 Tensorflow 时AVX2 Support,错误,

Nov 4 17:12:32 moodle37 kernel: [9773297.574293] traps: python2.7[4570] trap invalid opcode ip:7fb9b74bca59 sp:7ffdb7605e10 error:0 in libtensorflow_framework.so.1[7fb9b6d97000+18f8000]

FAILED: Build did NOT complete successfully

将通过将机器的 RAM 从 2GB RAM 增加到 8GB来解决。

快乐学习!


推荐阅读