Mailboxes to bitboards transition

Discussion of chess software programming and technical issues.

Moderator: Ras

Chessnut1071
Posts: 313
Joined: Tue Aug 03, 2021 2:41 pm
Full name: Bill Beame

Mailboxes to bitboards transition

Post by Chessnut1071 »

Got my bit boards routine working and surprised by the results compared to my mailboxes. I was expecting very little reduction in speed, thinking my mailbox engine was pretty efficient. Results as follows:

Average over 10,000,000 runs.
Mailboxes = 2,272,507 nodes per second
bitboards = 13,843,647 nodes per second

I don't think I have a standard bitboard since I only use bit operations on the sliding pieces. I kept the king, pawns and knights in mailbox from.
I think the speed of mailboxes is primarily related to two operands, bitscanforward and bitscanreverse (trailing and leading zeros in C#). Bitboards eliminate the looping and apparently save significant time; however, there is no looping on the non-sliding pieces so there is no time savings there. Al least I couldn't find it.

System: 64-bit Intel i7 6500U CPU, 2.59 GHz 16 GB RAM. C# Net 6.0

I know there are programmers on this board who have engines 100s of times faster than mine. So how did you get there and what am I missing.

P.S. I really don't have time for this stuff, but, I can't seem to stop.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Mailboxes to bitboards transition

Post by Sven »

Average over 10 million runs of what?
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
JVMerlino
Posts: 1397
Joined: Wed Mar 08, 2006 10:15 pm
Location: San Francisco, California

Re: Mailboxes to bitboards transition

Post by JVMerlino »

Sven's question is pretty important. :)

But 13M nodes per second does seem very slow ASSUMING you were running perft or something like that. If you were playing 10M games at 1 core (since you don't mention multiple cores in your hardware spec), then an average of 13M NPS is more than acceptable.

For comparison, my mediocre engine has a very slow move generation, but even then my perft gets about 40M NPS on 1 core. But if I just analyze the root position for a while with the same hardware, I only get about 1.9M NPS. (this also demonstrates that the movegen is only a very small percentage of an engine's total CPU usage during gameplay - so don't stress about tweaking every last little bit of speed out of your movegen if your ultimate goal is to make a strong engine).

But, yeah, we need to know what you were testing.
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Mailboxes to bitboards transition

Post by dangi12012 »

JVMerlino wrote: Tue Dec 21, 2021 6:19 pm Sven's question is pretty important. :)

But 13M nodes per second does seem very slow ASSUMING you were running perft or something like that. If you were playing 10M games at 1 core (since you don't mention multiple cores in your hardware spec), then an average of 13M NPS is more than acceptable.

For comparison, my mediocre engine has a very slow move generation, but even then my perft gets about 40M NPS on 1 core. But if I just analyze the root position for a while with the same hardware, I only get about 1.9M NPS. (this also demonstrates that the movegen is only a very small percentage of an engine's total CPU usage during gameplay - so don't stress about tweaking every last little bit of speed out of your movegen if your ultimate goal is to make a strong engine).

But, yeah, we need to know what you were testing.
Well if he sets out for a monte carlo engine then movegen speed is everything.
That would also have the advantage to being game agnostic. Meaning that only the outcome of +1 0 -1 is important.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Chessnut1071
Posts: 313
Joined: Tue Aug 03, 2021 2:41 pm
Full name: Bill Beame

Re: Mailboxes to bitboards transition

Post by Chessnut1071 »

JVMerlino wrote: Tue Dec 21, 2021 6:19 pm Sven's question is pretty important. :)

But 13M nodes per second does seem very slow ASSUMING you were running perft or something like that. If you were playing 10M games at 1 core (since you don't mention multiple cores in your hardware spec), then an average of 13M NPS is more than acceptable.

For comparison, my mediocre engine has a very slow move generation, but even then my perft gets about 40M NPS on 1 core. But if I just analyze the root position for a while with the same hardware, I only get about 1.9M NPS. (this also demonstrates that the movegen is only a very small percentage of an engine's total CPU usage during gameplay - so don't stress about tweaking every last little bit of speed out of your movegen if your ultimate goal is to make a strong engine).

But, yeah, we need to know what you were testing.
I used 10,000,000 runs on 300 puzzle mates from 4 - 18 ply to insure accuracy of the engine, averaging about 59 pseudo moves per game. My 5 year old i7 has 1 core running at 2.59 GHz. The 10,000,000 runs were needed to eliminate noise from the OS.

When I joined this board about 4 months ago, my engine speed was approximately 885,000/nps. After reading the merits of mailboxes it more than doubled to 2,2 million per second. My first attempt at bitboards moved it up to 13.8 million per second.

To be fair, my pseudo moves not only include piece and square, it also includes check, double check, discovered check, pin, ent passant and pawn promotion, along with move direction attacker, defender and target. Those of you who report speeds 10x and 100x of my 14 million nps, are you capturing that information as well? You need that information sooner or later don't you?

Also, I just learned of a way to increase the speed by applying bitboards to the pawns. I wasn't sure how to do that on my first pass.
federico
Posts: 32
Joined: Sun Oct 22, 2017 4:36 am
Location: Canada
Full name: Federico Rojo

Re: Mailboxes to bitboards transition

Post by federico »

dangi12012 wrote: Tue Dec 21, 2021 8:26 pm
JVMerlino wrote: Tue Dec 21, 2021 6:19 pm Sven's question is pretty important. :)

But 13M nodes per second does seem very slow ASSUMING you were running perft or something like that. If you were playing 10M games at 1 core (since you don't mention multiple cores in your hardware spec), then an average of 13M NPS is more than acceptable.

For comparison, my mediocre engine has a very slow move generation, but even then my perft gets about 40M NPS on 1 core. But if I just analyze the root position for a while with the same hardware, I only get about 1.9M NPS. (this also demonstrates that the movegen is only a very small percentage of an engine's total CPU usage during gameplay - so don't stress about tweaking every last little bit of speed out of your movegen if your ultimate goal is to make a strong engine).

But, yeah, we need to know what you were testing.
Well if he sets out for a monte carlo engine then movegen speed is everything.
That would also have the advantage to being game agnostic. Meaning that only the outcome of +1 0 -1 is important.

Movegen is tiny piece of a chess engine. At best 8 to 10% of cpu time.
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Mailboxes to bitboards transition

Post by dangi12012 »

federico wrote: Wed Dec 22, 2021 12:56 am Movegen is tiny piece of a chess engine. At best 8 to 10% of cpu time.
https://www.chessprogramming.org/Monte- ... ree_Search
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Chessnut1071
Posts: 313
Joined: Tue Aug 03, 2021 2:41 pm
Full name: Bill Beame

Re: Mailboxes to bitboards transition

Post by Chessnut1071 »

federico wrote: Wed Dec 22, 2021 12:56 am
dangi12012 wrote: Tue Dec 21, 2021 8:26 pm
JVMerlino wrote: Tue Dec 21, 2021 6:19 pm Sven's question is pretty important. :)

But 13M nodes per second does seem very slow ASSUMING you were running perft or something like that. If you were playing 10M games at 1 core (since you don't mention multiple cores in your hardware spec), then an average of 13M NPS is more than acceptable.

For comparison, my mediocre engine has a very slow move generation, but even then my perft gets about 40M NPS on 1 core. But if I just analyze the root position for a while with the same hardware, I only get about 1.9M NPS. (this also demonstrates that the movegen is only a very small percentage of an engine's total CPU usage during gameplay - so don't stress about tweaking every last little bit of speed out of your movegen if your ultimate goal is to make a strong engine).

But, yeah, we need to know what you were testing.
Well if he sets out for a monte carlo engine then movegen speed is everything.
That would also have the advantage to being game agnostic. Meaning that only the outcome of +1 0 -1 is important.

Movegen is tiny piece of a chess engine. At best 8 to 10% of cpu time.
"'''Movegen is tiny piece of a chess engine. At best 8 to 10% of cpu time'''"

That depends on your evaluation algorithm. The better it is the more the movegen percentage.
federico
Posts: 32
Joined: Sun Oct 22, 2017 4:36 am
Location: Canada
Full name: Federico Rojo

Re: Mailboxes to bitboards transition

Post by federico »

dangi12012 wrote: Wed Dec 22, 2021 1:30 am
federico wrote: Wed Dec 22, 2021 12:56 am Movegen is tiny piece of a chess engine. At best 8 to 10% of cpu time.
https://www.chessprogramming.org/Monte- ... ree_Search
I understand you have put on lots of efforts to create a fast movegen. Kudos to you for that. However, thinking that in any kind of engine , "movegen speed is everything", is not realistic.

Profile any engine you want, and you'll find it is not as you believe.
federico
Posts: 32
Joined: Sun Oct 22, 2017 4:36 am
Location: Canada
Full name: Federico Rojo

Re: Mailboxes to bitboards transition

Post by federico »

Chessnut1071 wrote: Wed Dec 22, 2021 2:03 am
federico wrote: Wed Dec 22, 2021 12:56 am
dangi12012 wrote: Tue Dec 21, 2021 8:26 pm
JVMerlino wrote: Tue Dec 21, 2021 6:19 pm Sven's question is pretty important. :)

But 13M nodes per second does seem very slow ASSUMING you were running perft or something like that. If you were playing 10M games at 1 core (since you don't mention multiple cores in your hardware spec), then an average of 13M NPS is more than acceptable.

For comparison, my mediocre engine has a very slow move generation, but even then my perft gets about 40M NPS on 1 core. But if I just analyze the root position for a while with the same hardware, I only get about 1.9M NPS. (this also demonstrates that the movegen is only a very small percentage of an engine's total CPU usage during gameplay - so don't stress about tweaking every last little bit of speed out of your movegen if your ultimate goal is to make a strong engine).

But, yeah, we need to know what you were testing.
Well if he sets out for a monte carlo engine then movegen speed is everything.
That would also have the advantage to being game agnostic. Meaning that only the outcome of +1 0 -1 is important.

Movegen is tiny piece of a chess engine. At best 8 to 10% of cpu time.
"'''Movegen is tiny piece of a chess engine. At best 8 to 10% of cpu time'''"

That depends on your evaluation algorithm. The better it is the more the movegen percentage.
Most of the time is spent on search and evaluation. Better search and/or eval, less cpu time will be spent on movegen. Movegen is minor piece on any decent engine. More so with staged movegens, where most moves aren't even generated, or engines that simply try the move from TT without generating any moves at all.

This is not a novelty. Bob Hyatt said it long ago:

"Speed here is not so important. I doubt anyone's move generator takes more than 10% of total search time, which means a 20% improvement in perft numbers is only a 2% overall speed gain. I would not worry about anything but matching the node counts exactly..."
https://www.chessprogramming.org/Perft#Quotes