Current state of compiler differences STOCKFISH

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Current state of compiler differences STOCKFISH

Post by dangi12012 »

So I took a few hours to compare how well different compilers do for Stockfish in terms of nps:
We are talking about the latest master branch in SF as of 06.12.2021 -> https://github.com/official-stockfish/Stockfish

Also the latest compilers were installed clang-12 and gcc-11 made the default by
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100


Anyways here is the comparison:

Code: Select all

./stockfish bench 128 1 20 default depth

clang: 57488149 - 2562659nps (run in ubuntu)
gcc:   57488149 - 2451102nps (run in ubuntu)
wingw: 57488149 - 2494495nps (run in windows)
msvc:  57488149 - 1999935nps (run in windows)
To compile on MSVC the makfile cannot be used. I created a sln for that I can share for anyone interested. It also has the appropriate macros defined so that BMI and AVX2 are used.
Run to run variance was pretty low for example my second run in windows was 1999949nps. It seems that MSVC cannot find some optimisations that clang and gcc found.

So there we have it. Current Stockfish with current compilers and the difference between gcc and clang is low but clear. Clang comes out ahead far outside of error of margin (at least on ryzen). Oh yeah and disabling AVX2 made performance 10% of what it is with it enabled.

I could not get native clang to work on windows (link time errors) so does anyone have experience? Download and build this: https://github.com/llvm/llvm-project and then build like you would without the makefile in windows.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Sopel
Posts: 389
Joined: Tue Oct 08, 2019 11:39 pm
Full name: Tomasz Sobczyk

Re: Current state of compiler differences STOCKFISH

Post by Sopel »

How many benches did you run for each build? Did you do build or profile-build?
dangi12012 wrote:No one wants to touch anything you have posted. That proves you now have negative reputations since everyone knows already you are a forum troll.

Maybe you copied your stockfish commits from someone else too?
I will look into that.
User avatar
Deberger
Posts: 91
Joined: Sat Nov 02, 2019 6:42 pm
Full name: ɹǝƃɹǝqǝᗡ ǝɔnɹꓭ

Re: Current state of compiler differences STOCKFISH

Post by Deberger »

Are you using profile-build?

Code: Select all

make profile-build ARCH=x86-64-bmi2
Ras
Posts: 2544
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Current state of compiler differences STOCKFISH

Post by Ras »

dangi12012 wrote: Mon Dec 06, 2021 12:49 amI could not get native clang to work on windows (link time errors) so does anyone have experience?
This one works (at least for my engine): https://github.com/mstorsjo/llvm-mingw
Rasmus Althoff
https://www.ct800.net
User avatar
hgm
Posts: 27967
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Current state of compiler differences STOCKFISH

Post by hgm »

[Moderation] Warning to dangi: please refrain from personal attacks on other posters. If you think they posted material that violates the TalkChess starter, use the 'report' button ('!') on those postings to have moderation deal with them.

Note that 'trolling' is a subjective opinion, and not a charter violation to begin with, and that reporting a posting for invalid reasons won't lead to its deletion. Off-topic posting in general will only be acted against when it takes on a magnitude that distracts too much from the original discussion, in which case the discussion will be split to separate the topics.
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Current state of compiler differences STOCKFISH

Post by dangi12012 »

Ras wrote: Mon Dec 06, 2021 7:28 am
dangi12012 wrote: Mon Dec 06, 2021 12:49 amI could not get native clang to work on windows (link time errors) so does anyone have experience?
This one works (at least for my engine): https://github.com/mstorsjo/llvm-mingw
Tried that. Didnt work. I can compile with clang. But i get infinite linker errors afterwards.
I will leave it at that. I suspect native windows clang will be just as fast as linux clang because the code is 99% identical.

So clang is best in beginning of 2022 for chessprogramming.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Sopel
Posts: 389
Joined: Tue Oct 08, 2019 11:39 pm
Full name: Tomasz Sobczyk

Re: Current state of compiler differences STOCKFISH

Post by Sopel »

I still don't see how you come to that conclusion. Without knowing the standard deviation of the performances, and the ways the binaries were produced, we cannot tell which compiler is better.
dangi12012 wrote:No one wants to touch anything you have posted. That proves you now have negative reputations since everyone knows already you are a forum troll.

Maybe you copied your stockfish commits from someone else too?
I will look into that.
Ras
Posts: 2544
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Current state of compiler differences STOCKFISH

Post by Ras »

dangi12012 wrote: Mon Dec 06, 2021 1:51 pmI can compile with clang. But i get infinite linker errors afterwards.
Here the relevant options I'm using for that Clang:
-target x86_64-pc-windows-gnu -O2 -flto -mthreads -mconsole -static -fuse-ld=lld --rtlib=compiler-rt -s -Wl,-s

32 bit Windows: -target x86_64-pc-windows-gnu
64 bit ARM Windows: -target aarch64-pc-windows-gnu
32 bit ARM Windows: -target armv7-pc-windows-gnu

The download zip I tried successfully: llvm-mingw-20210423-msvcrt-x86_64.zip
One caveat is that my engine is in C, not C++.
Rasmus Althoff
https://www.ct800.net
OfekShochat
Posts: 50
Joined: Thu Oct 15, 2020 10:19 am
Full name: Ofek Shochat

Re: Current state of compiler differences STOCKFISH

Post by OfekShochat »

regarding sopel's questions, you cant really draw any conclusions without running multiple benches and specifying the standard deviation/variance...
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Current state of compiler differences STOCKFISH

Post by dangi12012 »

OfekShochat wrote: Mon Dec 06, 2021 8:03 pm regarding sopel's questions, you cant really draw any conclusions without running multiple benches and specifying the standard deviation/variance...
It was remarkably consistent. Tests ran 1min and scores deviated by 1-2% max.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer