11

When building TensorFlow from source, we're asked to set --config=opt (which by default will enable the gcc flag -march=native) but across the web I see a lot of people using -c opt instead, but according to Bazel's documentation -c is actually shorthand for --compilation_mode and not --config!

Confusingly, --compilation_mode also takes 'opt' as a value, but I assume that's just coincidental? Could someone clarify the difference between -c opt and --config=opt when executing bazel build during TensorFlow compilation?

Carl Thomé
  • 2,703
  • 3
  • 19
  • 41

2 Answers2

16

The -c opt flag is for telling Bazel to build with optimization settings enabled and no debug information. Like you mentioned --compilation_mode opt. This is related to the flags used to compile any code.

The --config=opt is telling Bazel, to look in the .bazelrc file during compilation and read any settings that match the opt configuration. After you run your configure script with tensorflow, you should have a .bazelrc file sitting in the root of your workspace which defines settings for multiple configurations. For the opt configuration, it adds the extra -march-native for compilation.

So it is a bit coincidental that they are named the same way. But --config is a flexible tool to choose Bazel settings from a .bazelrc file. -c is really just for building code with optimizations.

zlalanne
  • 894
  • 5
  • 11
  • 1
    in addition to a `.bazelrc` file at the root of the workspace, there are other locations on disk where such a file may reside: https://bazel.build/designs/2016/06/21/environment.html#list-of-rc-files-read-by-bazel – pestophagous Jul 31 '19 at 20:03
5

--config set a configuration that expands in a set of flag defined in a .rc file. E.g. if the rc file contains build:opt -c opt, setting --config opt on the command line will expand to -c opt. The tensorflow rc file set -c opt but does not defined any opt configuration. So setting --config opt will do nothing.

ADDENDUM: ./configure of TensorFlow add some C++ options on the .bazelrc on the opt configuration (so it will expand into those C++ options).