0

I'm using tensorflow (without GPU support) and I'm seeing a fairly significant hit in performance compared to what's expected. So, I figured it was time to pay attention to these warnings:

W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

I've seen some people claim they've gotten close to a 10x improvement in speed, building with these instructions.

The instructions I've found on doing this, though, seem to be related to older versions of TF (v < 1.0). I was wondering if anyone could point me to a correct bazel command for building using a newer version of tf?

Installing for python3 on Mac OSX by following the instructions here: https://www.tensorflow.org/install/install_sources and selecting "No" for CUDA support.

and using the bazel command:

bazel build --linkopt='-lrt' -c opt --copt=-march=native --copt=-mavx --copt=-msse4.2 --copt=-msse4.1 //tensorflow/tools/pip_package:build_pip_package

However, this results in many pages of warrnings/errors... mostly of the form:

target '//tensorflow/contrib/learn:learn' depends on deprecated target '//tensorflow/contrib/session_bundle:exporter': Use SavedModel Builder instead.

and

external/protobuf/python/google/protobuf/pyext/message_factory.cc:78:28: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]

Edit

I will note that I only saw a marginal increase in speed building from source.

Ben
  • 6,986
  • 6
  • 44
  • 71
  • Regarding instructions, the official docs are following the latest updates. The command is the one specified on the docs `bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package`. If you defined SIMD instructions to be default when configuring e.g. `-march=native` you don't need to specify others as `msse4.2`, `mavx` etc as it should compile with the available optimization in your CPU architecture. If you did set specific instructions though you need to define the corresponding flags when building. – Adriano Apr 11 '17 at 16:56
  • Hi @AdrianoCarmezim, Running the basic bazel command `bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package` throws the same errors for me – Ben Apr 11 '17 at 17:01
  • Those you referred are warnings which won't prevent you from building TF, are there error logs being emitted? – Adriano Apr 11 '17 at 17:10
  • I wasn't able to import tensorflow after installing it, but I see now that it was a separate issue. And you're right, building from source with just the `-march=native` correctly optimized the installation. – Ben Apr 12 '17 at 12:36
  • Glad it is working now. For the importing problem feel free to open an issue on Github if you're still facing it or let me know if I can be of any more help :) I will leave an answer in case anyone else happens to be in the same situation. – Adriano Apr 12 '17 at 16:50

1 Answers1

1

As stated in the comments those are warnings that won't prevent TensorFlow to be built.

Regarding the command to build TensorFlow with bazel, if -march=native was set during configuring it is not necessary to explicitly add other optimization flags as TensorFlow will already compile with all SIMD instructions available in your CPU architecture.

After successfully configuring with optimizations defaulted for your architecture (-march=native) the command to build TF is:

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

if you happen to select specific flags instead they need to be added e.g.:

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma //tensorflow/tools/pip_package:build_pip_package

Reference: TensorFlow Docs

Adriano
  • 750
  • 5
  • 9