Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between -c opt and --config=opt when building TensorFlow from source?

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?

like image 516
Carl Thomé Avatar asked Sep 20 '17 10:09

Carl Thomé


2 Answers

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.

like image 74
zlalanne Avatar answered Nov 18 '22 20:11

zlalanne


--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).

like image 28
Damien Martin-Guillerez Avatar answered Nov 18 '22 19:11

Damien Martin-Guillerez