Any good positions to test hash tables?

Discussion of chess software programming and technical issues.

Moderator: Ras

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

Re: Any good positions to test hash tables?

Post by bob »

gladius wrote:Wow, Garbochess JS failed miserably on this position, until I tested out your suggestion and moved to always replace. Then it solved it instantly.

Guess I have some work to do on my replacement strategy :).

Code: Select all

Ply:1 Score:840 Nodes:11 NPS:733 Kf7
...
Ply:16 Score:905 Nodes:33211 NPS:203748 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Kc6 Kc8 b6 Kb8 b7
Ply:17 Score:905 Nodes:35258 NPS:208627 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Kc6 Kc8 b6 Kb8 b7
Ply:18 Score:10106 Nodes:75991 NPS:193854 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kd8 Ka7 Kd7 b6 Ke8 b7
...
Ply:30 Score:1999999 Nodes:8727824 NPS:317444 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Ka6 Kc7 b6+ Kc8 Ka7
Here is some important advice that quite a few overlook: "NEVER, and I do mean NEVER fail to store a current position in the hash table. Let me repeat, NEVER. You can do whatever you want to choose what to replace, but you MUST replace something.

That seems counter-intuitive, but it is critical. I use a bucket of 4 entries and choose the best of the 4 (actually the worst, but you get my drift) to replace, and I always store the entry from a fail-high, a fail-low, or an EXACT search.
jacobbl
Posts: 80
Joined: Wed Feb 17, 2010 3:57 pm

Re: Any good positions to test hash tables?

Post by jacobbl »

Thanks for your answer.
When I turn of the hash tables I use about 15 second to reach ply 15. With the hash tables I reach ply 23 (2,5 million nodes) at 15 seconds. So the hash tables are doing some good. I'm thinking it might be the replacement scheme that is bad. I use 2 slots, the first slot I replace if deeper, the second slot I use allways replace.

What replacement scheme would you suggest?
User avatar
hgm
Posts: 28405
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Any good positions to test hash tables?

Post by hgm »

I usually use equidistributed-draft replacement: replace the same position if it is in the bucket, otherwise replace the primary entry if the draft it contains is over-represented in the table, and if not, replace the entry with the lowest draft in the bucket.
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Any good positions to test hash tables?

Post by michiguel »

bob wrote:
gladius wrote:Wow, Garbochess JS failed miserably on this position, until I tested out your suggestion and moved to always replace. Then it solved it instantly.

Guess I have some work to do on my replacement strategy :).

Code: Select all

Ply:1 Score:840 Nodes:11 NPS:733 Kf7
...
Ply:16 Score:905 Nodes:33211 NPS:203748 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Kc6 Kc8 b6 Kb8 b7
Ply:17 Score:905 Nodes:35258 NPS:208627 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Kc6 Kc8 b6 Kb8 b7
Ply:18 Score:10106 Nodes:75991 NPS:193854 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kd8 Ka7 Kd7 b6 Ke8 b7
...
Ply:30 Score:1999999 Nodes:8727824 NPS:317444 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Ka6 Kc7 b6+ Kc8 Ka7
Here is some important advice that quite a few overlook: "NEVER, and I do mean NEVER fail to store a current position in the hash table. Let me repeat, NEVER. You can do whatever you want to choose what to replace, but you MUST replace something.

That seems counter-intuitive, but it is critical. I use a bucket of 4 entries and choose the best of the 4 (actually the worst, but you get my drift) to replace, and I always store the entry from a fail-high, a fail-low, or an EXACT search.
To expand this concept I would say that it should be stored in a way it could be read back immediately. For instance, if you replace w/o checking whether the same position is already there, you could replace another slot, but you read back an old one.

This could test it:

Code: Select all

ht_store(signature, entry);

#if !defined(NDEBUG)
{ 
	struct ENTRY entry_tmp;
	int success = ht_retrieve(signature, &entry_tmp);
	assert(success && entries_are_equal(entry,entry_tmp);)
}
#endif
Miguel
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Any good positions to test hash tables?

Post by bob »

michiguel wrote:
bob wrote:
gladius wrote:Wow, Garbochess JS failed miserably on this position, until I tested out your suggestion and moved to always replace. Then it solved it instantly.

Guess I have some work to do on my replacement strategy :).

Code: Select all

Ply:1 Score:840 Nodes:11 NPS:733 Kf7
...
Ply:16 Score:905 Nodes:33211 NPS:203748 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Kc6 Kc8 b6 Kb8 b7
Ply:17 Score:905 Nodes:35258 NPS:208627 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Kc6 Kc8 b6 Kb8 b7
Ply:18 Score:10106 Nodes:75991 NPS:193854 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kd8 Ka7 Kd7 b6 Ke8 b7
...
Ply:30 Score:1999999 Nodes:8727824 NPS:317444 c7 Kxc7 Ke7 Kc8 Kd6 Kd8 Kc6 Kc8 Kxb6 Kb8 Ka6 Kc7 b6+ Kc8 Ka7
Here is some important advice that quite a few overlook: "NEVER, and I do mean NEVER fail to store a current position in the hash table. Let me repeat, NEVER. You can do whatever you want to choose what to replace, but you MUST replace something.

That seems counter-intuitive, but it is critical. I use a bucket of 4 entries and choose the best of the 4 (actually the worst, but you get my drift) to replace, and I always store the entry from a fail-high, a fail-low, or an EXACT search.
To expand this concept I would say that it should be stored in a way it could be read back immediately. For instance, if you replace w/o checking whether the same position is already there, you could replace another slot, but you read back an old one.

This could test it:

Code: Select all

ht_store(signature, entry);

#if !defined(NDEBUG)
{ 
	struct ENTRY entry_tmp;
	int success = ht_retrieve(signature, &entry_tmp);
	assert(success && entries_are_equal(entry,entry_tmp);)
}
#endif
Miguel
I never considered the idea of storing the same entry twice in a hash table, no more than I would want a cache to store the same memory block twice. As they used to write on old 14th century ocean maps, "here there be dragons..." :)

I would consider two copies of anything to be a bug. And failing to store something at every opportunity is almost as serious...
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Any good positions to test hash tables?

Post by bob »

jacobbl wrote:Thanks for your answer.
When I turn of the hash tables I use about 15 second to reach ply 15. With the hash tables I reach ply 23 (2,5 million nodes) at 15 seconds. So the hash tables are doing some good. I'm thinking it might be the replacement scheme that is bad. I use 2 slots, the first slot I replace if deeper, the second slot I use allways replace.

What replacement scheme would you suggest?
That is commonly called "The Belle hash idea" as developed by Ken Thompson. Works well. But you have to avoid the potential flaw of having the same signature stored twice because the first (depth-preferred entry) has a worthless, but deep-draft entry that is difficult to replace. If you store the same signature in the second entry, but on a probe get a hit on the first entry, then you have a serious flaw...

Ken actually used two hash tables. Depth-preferred entry table was 1/2 the size of the always store table.
User avatar
hgm
Posts: 28405
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Any good positions to test hash tables?

Post by hgm »

bob wrote:I never considered the idea of storing the same entry twice in a hash table, no more than I would want a cache to store the same memory block twice. As they used to write on old 14th century ocean maps, "here there be dragons..." :)

I would consider two copies of anything to be a bug. And failing to store something at every opportunity is almost as serious...
Yet there is a top engine that does exactly that.
jacobbl
Posts: 80
Joined: Wed Feb 17, 2010 3:57 pm

Re: Any good positions to test hash tables?

Post by jacobbl »

Looks like I have a serious flaw...
Nothing is better, then there is hope for an improvement :-)

Is there a lot to gain on more complicated replacement schemes?
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Any good positions to test hash tables?

Post by michiguel »

jacobbl wrote:Looks like I have a serious flaw...
Nothing is better, then there is hope for an improvement :-)

Is there a lot to gain on more complicated replacement schemes?
Not in this type of endgames because not many positions are visited. First, I suggest to debug everything with a simple "replace always" table and a material only eval.

Miguel
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Any good positions to test hash tables?

Post by jwes »

bob wrote: Here is some important advice that quite a few overlook: "NEVER, and I do mean NEVER fail to store a current position in the hash table. Let me repeat, NEVER. You can do whatever you want to choose what to replace, but you MUST replace something.
Quibble: if the hash table causes a cutoff, you don't want to store anything.