Optimize?

Discussion of chess software programming and technical issues.

Moderator: Ras

outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Optimize?

Post by outAtime »

I have seen many examples of optimization flags used by different engines, and was wondering what might be the best to use overall to
compile the fastest code.

Some examples I have seen include:

-fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
-09 -march-athlon -funroll-all-loops -fomit-frame-pointer -fno-gsce
-fstrict-aliasing -fssa
(GCP's site which benchmarks different flags)

It seems to me that the -march-athlon flag is a good one for my system since its a AMD chip, and the flag -fomit-frame-pointer seems to get alot
of use in different engines. -fssa is not useful for my system? and I think -fno-rtti is for c++ not c. I can optimize to -03 level, not above, so -04 etc.. I can't use.

Any ideas for a good (best) overall optimization for c code?
outAtime
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimize?

Post by bob »

outAtime wrote:I have seen many examples of optimization flags used by different engines, and was wondering what might be the best to use overall to
compile the fastest code.

Some examples I have seen include:

-fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
-09 -march-athlon -funroll-all-loops -fomit-frame-pointer -fno-gsce
-fstrict-aliasing -fssa
(GCP's site which benchmarks different flags)

It seems to me that the -march-athlon flag is a good one for my system since its a AMD chip, and the flag -fomit-frame-pointer seems to get alot
of use in different engines. -fssa is not useful for my system? and I think -fno-rtti is for c++ not c. I can optimize to -03 level, not above, so -04 etc.. I can't use.

Any ideas for a good (best) overall optimization for c code?
There is only one way to find out. Try each one and do a benchmark run. Each compiler version is different, there are different types of processors that cause optimizations to work differently, etc.
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Optimize?

Post by bhlangonijr »

bob wrote:
outAtime wrote:I have seen many examples of optimization flags used by different engines, and was wondering what might be the best to use overall to
compile the fastest code.

Some examples I have seen include:

-fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
-09 -march-athlon -funroll-all-loops -fomit-frame-pointer -fno-gsce
-fstrict-aliasing -fssa
(GCP's site which benchmarks different flags)

It seems to me that the -march-athlon flag is a good one for my system since its a AMD chip, and the flag -fomit-frame-pointer seems to get alot
of use in different engines. -fssa is not useful for my system? and I think -fno-rtti is for c++ not c. I can optimize to -03 level, not above, so -04 etc.. I can't use.

Any ideas for a good (best) overall optimization for c code?
There is only one way to find out. Try each one and do a benchmark run. Each compiler version is different, there are different types of processors that cause optimizations to work differently, etc.
In addition, you can try a PGO (Profile Guided Optimization) perhaps you can improve your engine's performance a bit. I don't know, maybe the experts here can tell you about the overall results using PGO in their tests.

I have tried PGO only with Intel Compiler for Linux - it's free (see the license). It appears that recent versions of GCC supports PGO.

Regards
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimize?

Post by bob »

bhlangonijr wrote:
bob wrote:
outAtime wrote:I have seen many examples of optimization flags used by different engines, and was wondering what might be the best to use overall to
compile the fastest code.

Some examples I have seen include:

-fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
-09 -march-athlon -funroll-all-loops -fomit-frame-pointer -fno-gsce
-fstrict-aliasing -fssa
(GCP's site which benchmarks different flags)

It seems to me that the -march-athlon flag is a good one for my system since its a AMD chip, and the flag -fomit-frame-pointer seems to get alot
of use in different engines. -fssa is not useful for my system? and I think -fno-rtti is for c++ not c. I can optimize to -03 level, not above, so -04 etc.. I can't use.

Any ideas for a good (best) overall optimization for c code?
There is only one way to find out. Try each one and do a benchmark run. Each compiler version is different, there are different types of processors that cause optimizations to work differently, etc.
In addition, you can try a PGO (Profile Guided Optimization) perhaps you can improve your engine's performance a bit. I don't know, maybe the experts here can tell you about the overall results using PGO in their tests.

I have tried PGO only with Intel Compiler for Linux - it's free (see the license). It appears that recent versions of GCC supports PGO.

Regards
PGO is worth at least 10% to me. GCC sort of supports it. You can't PGO a multi-threaded code, it will run but the second compile complains about corrupted PGO data... Intel works fine with threads...
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 3:08 pm
Location: Canada

Re: Optimize?

Post by outAtime »

Kewl. I did a PGO build, everything worked fine...-fprofile-use worked without complaints. I included the -O3 flag with -frofile-use on the second
make, is that o.k.? Is there a way to view which optimizations the PGO
selected? Also, I ran the engine only once - Should I allow it to play more
games than (one) before re-compile?

Thanks again for a nice suggestion, PGO is new to me and seems to work
fine.
outAtime
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimize?

Post by bob »

outAtime wrote:Kewl. I did a PGO build, everything worked fine...-fprofile-use worked without complaints. I included the -O3 flag with -frofile-use on the second
make, is that o.k.? Is there a way to view which optimizations the PGO
selected? Also, I ran the engine only once - Should I allow it to play more
games than (one) before re-compile?

Thanks again for a nice suggestion, PGO is new to me and seems to work
fine.
I have a set of positions I always use for a PGO run. I wanted to make sure that I include opening positions, middlegame positions, endgame positions, plus I run a couple that use parallel search so that the parallel code also gets profiled and optimized. If you use EGTBs you should also run some positions that beat on EGTBs as well so that the egtb.cpp code gets optimized.

O3 is fine, that is independent of the PGO stuff. I don't know how much you can coax the compiler to give you, but for the most part, the PGO optimizations are all about moving blocks of code around to optimize branches and instruction prefetching.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Optimize?

Post by mcostalba »

outAtime wrote: -fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
Well, -fno-strict-aliasing is actually a pessimization :-) compiler have more constraints to honor so could miss some optmization opportunities.

But I need that because of a very critical function pop_1s_bit() uses type punning when compiled for 32 bit, and is broken without that flag.

Regarding remaining flags I have taken as is from Glaurung, I am not very interested in this because final compilation of release version normally it's up to Jim that knows very well (and much better then me) how to tweak the compiler to get the most out of sources.

So getting the fastest compile is something I (gladly) leave to others.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Optimize?

Post by bob »

mcostalba wrote:
outAtime wrote: -fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
Well, -fno-strict-aliasing is actually a pessimization :-) compiler have more constraints to honor so could miss some optmization opportunities.

But I need that because of a very critical function pop_1s_bit() uses type punning when compiled for 32 bit, and is broken without that flag.

Regarding remaining flags I have taken as is from Glaurung, I am not very interested in this because final compilation of release version normally it's up to Jim that knows very well (and much better then me) how to tweak the compiler to get the most out of sources.

So getting the fastest compile is something I (gladly) leave to others.
If you use egtb.cpp you _must_ use that flag, as Eugene does some cute aliasing that will break if the compiler is not careful..