Acovea tutorial

From MerlinWiki
Jump to: navigation, search

What is Acovea?

ACOVEA (Analysis of Compiler Options via Evolutionary Algorithm) implements a genetic algorithm to find the "best" options for compiling programs with the GNU Compiler Collection (GCC) C and C++ compilers. "Best", in this context, is defined as those options that produce the fastest executable program from a given source code. Acovea is a C++ framework that can be extended to test other programming languages and non-GCC compilers.

I envision Acovea as an optimization tool, similar in purpose to profiling. Traditional function-level profiling identifies the algorithms most influential in a program's performance; Acovea is then applied to those algorithms to find the compiler flags and options that generate the fastest code. Acovea is also useful for testing combinations of flags for pessimistic interactions, and for testing the reliability of the compiler.

Acovea overview copied from Acovea homepage

The tutorial

download these files:


for each file do:

tar -xvzf libXY.tar.gz
cd libXY
make install

look into /usr/local/share/libacovea/config for a configuration file which fits your processor's architecture

...and try this:

runacovea -config gcc34_pentium4.acovea -input /usr/local/share/libacovea/benchmarks/fftbench.c

Acovea is now going to find the options for gcc which produce the fastest code. After few hours :o) You will get something like this:

Optimistic options:

                       -fstrength-reduce  (2.002)
                       -fstrict-aliasing  (2.668)
                  -fprefetch-loop-arrays  (2.412)

Pessimistic options:

                      -fno-loop-optimize  (-2.297)
               -momit-leaf-frame-pointer  (-1.632)
                      -funroll-all-loops  (-1.785)
           -fbranch-target-load-optimize  (-2.093)
          -fbranch-target-load-optimize2  (-1.581)
                            -mfpmath=sse  (-2.144)
                        -mfpmath=sse,387  (-2.349)

Acovea's Best-of-the-Best:
gcc -lrt -lm -std=gnu99 -O1 -march=pentium4 -fno-defer-pop -fno-thread-jumps -fno-cprop-registers -fno-if-conversion -fno-crossjumping 
-foptimize-sibling-calls -fgcse -fexpensive-optimizations -fstrength-reduce -frerun-cse-after-loop -frerun-loop-opt -fregmove -fstrict-aliasing 
-freorder-blocks -fsched-spec -freorder-functions -falign-loops -funit-at-a-time -finline-functions -frename-registers -momit-leaf-frame-pointer 
-fprefetch-loop-arrays -fno-inline -fpeel-loops -ftracer -funroll-loops -fbranch-target-load-optimize -mieee-fp -maccumulate-outgoing-args 
-minline-all-stringops -mfpmath=387 -fno-math-errno -funsafe-math-optimizations -fno-signaling-nans -finline-limit=500 -o /tmp/ACOVEA39075E11 

Acovea's Common Options:
gcc -lrt -lm -std=gnu99 -O1 -march=pentium4 -fstrength-reduce -fstrict-aliasing -momit-leaf-frame-pointer -fprefetch-loop-arrays -funroll-loops 
-minline-all-stringops -o /tmp/ACOVEAF32579BD fftbench.c 

gcc -lrt -lm -std=gnu99 -O1 -march=pentium4 -o /tmp/ACOVEA55F5DA64 fftbench.c 

gcc -lrt -lm -std=gnu99 -O2 -march=pentium4 -o /tmp/ACOVEA65539F21 fftbench.c 

gcc -lrt -lm -std=gnu99 -O3 -march=pentium4 -o /tmp/ACOVEA0702B24D fftbench.c 

-O3 -ffast-math:
gcc -lrt -lm -std=gnu99 -O3 -march=pentium4 -ffast-math -o /tmp/ACOVEAE9697299 fftbench.c 

gcc -lrt -lm -std=gnu99 -Os -march=pentium4 -o /tmp/ACOVEADBBA8A28 fftbench.c 

A relative graph of fitnesses:

     Acovea's Best-of-the-Best: ********************************                      (0.98771)
       Acovea's Common Options: ********************************                      (0.985864)
                           -O1: **************************************************    (1.52045)
                           -O2: ***********************************                   (1.0821)
                           -O3: *********************************                     (1.02044)
               -O3 -ffast-math: *********************************                     (1.00544)
                           -Os: **********************************                    (1.03491)

Acovea is done.


The benchmark file is a program in a language appropriate for the chosen configuration file; it must write its fitness value to standard output, where it will be read via pipe by the Acovea framework.

A sample set of C benchmark programs is located (by default) in /usr/local/share/acovea/benchmarks.