Stockfish patch with 10% speed up

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Fabio Gobbato
Posts: 219
Joined: Fri Apr 11, 2014 10:45 am
Full name: Fabio Gobbato

Stockfish patch with 10% speed up

Post by Fabio Gobbato »

I've seen in the development version of Stockfish that the developers have added this patch https://github.com/official-stockfish/S ... 149c4b7729 that gives about a 10% speed up on some architectures.
I'm not familiar with stockfish code but it seems that it works on layer 1 of nnue weights and it expects a size of 16 for layer 2.
Can someone explain the idea behind this patch and if it is useful only for stockfish or can be used with other nnue engines with different net architectures?
Thank you!
chrisw
Posts: 4624
Joined: Tue Apr 03, 2012 4:28 pm
Location: Midi-Pyrénées
Full name: Christopher Whittington

Re: Stockfish patch with 10% speed up

Post by chrisw »

yup, the idea is that your L1 layer (uint8's) is sparse (I did a quick test on mine and found only about 60 or so were ever actually nz in any one position). The cells that were nz also tended to be the same set of cells each time.

So: if you were to sort your L1 layer in descending order, you'ld end up with most early cells nz, and the later cells z. Split into int32 blocks, that gives a good chance that many of those blocks are z, and don't need to participate in the onwards calculation.

I assume this would require doing stats on your NNUE, discovering the popular populated cells over a large range of input positions, getting an index sort, permuting the weights according to the index sort, etc.

Maybe I'm being random, of course.