I'm learning GCC and Bazel. I want to enable all the optimization for Bazel to build a project which requires the best performance.
Then I found -c opt
which means to set the compilation mode to optimized without debug information.
And --copt=-O3
means set the optimization level to the third one. There are -O2
, -Os
, etc.
I'm confused with these two options.
-c opt
and --copt=-O3
?bazel build
?I want to enable all the optimization for Bazel to build a project which requires the best performance. Then I found -c opt which means to set the compilation mode to optimized without debug information. And - -copt=-O3 means set the optimization level to the third one. There are -O2, -Os, etc. I'm confused with these two options.
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.
But --config is a flexible tool to choose Bazel settings from a .bazelrc file. -c is really just for building code with optimizations. --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.
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.
--copt
is for passing args to to the compiler.
-c
is a short form of --compilation-mode.
Its effect is described in the user-manual:
-c opt
implies -O2 -DNDEBUG
)So usually, -c opt
is enough. If you want the behaviour of -c opt
but with a different optimization level, you combine the two options like in -c opt --copt=-O3
and the compiler will get both options -O2
and -O3
, but the last one will win.
And watch out, there is a third similar option:
--config=configname
is for selecting a configuration. You can have a .bazelrc
which defines default options. Some of them are not always active, but some only if you activate them by the --config=configname
command line option. Now opt
is a popular configname, so if you have a .bazelrc
that contains
build:opt --copt=-O3
then bazel build --config=opt
has the same effect as bazel build --copt=-O3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With