Search code examples
linuxtensorflowintelbazel

Errors on building Tensorflow on Intel Atom


I build Tensorflow on Intel Atom. Bazel is 0.15. The console command to build is

bazel build --config=mkl --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0 --copt=-march=atom --copt=-mtune=atom //tensorflow/tools/pip_package:build_pip_package

I have

Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux

Two errors are

ERROR: /home/upsquared/tensorflow/tensorflow/BUILD:533:1: Executing genrule //tensorflow:tf_python_api_gen_v1 failed (Exit 1)
Traceback (most recent call last):
ImportError: /home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyClass_Type

The whole error messages are

At global scope:
cc1plus: warning: unrecognized command line option '-Wno-self-assign'
ERROR: /home/upsquared/tensorflow/tensorflow/BUILD:533:1: Executing genrule //tensorflow:tf_python_api_gen_v1 failed (Exit 1)
Traceback (most recent call last):
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/upsquared/venv/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/upsquared/venv/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyClass_Type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/tools/api/generator/create_python_api.py", line 27, in <module>
    from tensorflow.python.tools.api.generator import doc_srcs
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/upsquared/venv/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/upsquared/venv/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: /home/upsquared/.cache/bazel/_bazel_upsquared/64ad7d1d27724ec626c14ec5fee17883/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api_1.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyClass_Type


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
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: 7602.740s, Critical Path: 240.17s
INFO: 5845 processes: 5845 local.
FAILED: Build did NOT complete successfully

Solution

  • Installation instructions:

    1. Ensure numpy, keras-applications, keras-preprocessing, pip, six, wheel, mock packages are installed in the Python environment where TensorFlow is being built and installed.
    2. Clone the TensorFlow source code and checkout 1.12 branch

      git clone https://github.com/tensorflow/tensorflow
      git checkout r1.12
      
    3. Run "./configure" from the TensorFlow source directory

    4. Execute the following commands to create a pip package that can be used to install the optimized TensorFlow build.

      PATH can be changed to point to a specific version of GCC compiler:

        export PATH=/PATH//bin:$PATH
      

      LD_LIBRARY_PATH can also be to new:

        export LD_LIBRARY_PATH=/PATH//lib64:$LD_LIBRARY_PATH
      

      Set the compiler flags support by the GCC on your machine to build TensorFlow with Intel® Math Kernel Library (Intel® MKL). Ensure appropriate "march" and "mtune" flags are set.

        bazel build --config=mkl --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0 --copt=-march=sandybridge --copt=-mtune=ivybridge --copt=-O3 //tensorflow/tools/pip_package:build_pip_package
      

      (or)

      Alternatively, set appropriate "Instruction sets" flags you want to compile the library with:

    Flags set in the command below will add AVX, AVX2 and AVX512 instructions which will result in "illegal instruction" errors when you use older CPUs. If you want to build on older CPUs, set the instruction flags accordingly

           bazel build --config=mkl -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mavx512f --copt=-mavx512pf --copt=-mavx512cd --copt=-mavx512er //tensorflow/tools/pip_package:build_pip_package
    
    1. Install the optimized TensorFlow wheel

      bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/path_to_save_wheel
      
      pip install --upgrade --user ~/path_to_save_wheel/<wheel_name.whl>
      

    For reference, please go through this link: https://software.intel.com/en-us/articles/intel-optimization-for-tensorflow-installation-guide