c++ class or a c wrapper for the syzygy egtb

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
flok

Re: c++ class or a c wrapper for the syzygy egtb

Post by flok » Fri Nov 20, 2015 11:14 pm

Seems to work pretty nice!
Thanks a lot!

flok

Re: c++ class or a c wrapper for the syzygy egtb

Post by flok » Sat Nov 21, 2015 12:35 am

So when do you query it?
Do you check every node if total piece_count < x and then check it?

basil00
Posts: 55
Joined: Thu Oct 22, 2015 12:14 am

Re: c++ class or a c wrapper for the syzygy egtb

Post by basil00 » Sat Nov 21, 2015 1:25 am

flok wrote:So when do you query it?
Do you check every node if total piece_count < x and then check it?
Basically, except for qsearch. Also the result is stored in the TT to help minimize the TB queries. See the Gull Syzygy Patch. There are probably more optimal ways of doing it too.

syzygy
Posts: 5000
Joined: Tue Feb 28, 2012 10:56 pm

Re: c++ class or a c wrapper for the syzygy egtb

Post by syzygy » Sat Nov 21, 2015 7:42 pm

flok wrote:So when do you query it?
Do you check every node if total piece_count < x and then check it?
If you want to limit the number of probes, it is best to do that by only probing if remaining_depth >= y (and piece_count <= x), where y is the "probe depth" parameter.

flok

Re: c++ class or a c wrapper for the syzygy egtb

Post by flok » Sun Nov 22, 2015 12:13 pm

I sometimes get a segfault in the syzygy code:

Code: Select all

#0  0x000000000042bf06 in decompress_pairs &#40;d=0x10738b0, idx=<optimized out>) at tbcore.c&#58;1481
#1  0x00000000004306e9 in probe_wdl_table &#40;success=0x7fff50b0633c, pos=<optimized out>) at tbprobe.c&#58;757
#2  probe_ab &#40;pos=pos@entry=0x7fff50b05e90, alpha=alpha@entry=-2, beta=beta@entry=2, success=success@entry=0x7fff50b0633c&#41; at tbprobe.c&#58;1376
#3  0x000000000042ff44 in probe_ab &#40;pos=pos@entry=0x7fff50b068c0, alpha=alpha@entry=-2, beta=beta@entry=2, success=success@entry=0x7fff50b0633c&#41; at tbprobe.c&#58;1362
#4  0x0000000000434161 in probe_dtz_no_ep &#40;success=0x7fff50b0633c, pos=0x7fff50b068c0&#41; at tbprobe.c&#58;1451
#5  probe_dtz &#40;pos=pos@entry=0x7fff50b068c0, success=success@entry=0x7fff50b0633c&#41; at tbprobe.c&#58;1573
#6  0x0000000000435c3e in probe_root &#40;pos=pos@entry=0x7fff50b068c0, score=score@entry=0x7fff50b068bc, results=results@entry=0x7fff50b06990&#41; at tbprobe.c&#58;1660
#7  0x0000000000437a05 in tb_probe_root_impl &#40;white=white@entry=281474977234944, black=black@entry=9024792111874048, kings=kings@entry=9007199255265280, 
    queens=queens@entry=536870912, rooks=rooks@entry=0, bishops=bishops@entry=0, knights=134217728, pawns=299067162755072, rule50=10, ep=0, turn=true, 
    results=0x7fff50b06990&#41; at tbprobe.c&#58;1861
#8  0x000000000042a287 in tb_probe_root (_results=0x7fff50b06990, _turn=<optimized out>, _ep=0, _castling=0, _rule50=10, _pawns=299067162755072, 
    _knights=134217728, _bishops=0, _rooks=0, _queens=536870912, _kings=9007199255265280, _black=9024792111874048, _white=281474977234944&#41; at tbprobe.h&#58;278
#9  query_syzygy_etb &#40;fen=0xfaf270 "8/P4k2/4p3/8/3n1q2/3K4/8/8 w - - 10 1") at fathom.c&#58;809
I've compiled it in a static library with only -DTB_NO_HW_POP_COUNT so it should use the thread-safe code?[/code]

basil00
Posts: 55
Joined: Thu Oct 22, 2015 12:14 am

Re: c++ class or a c wrapper for the syzygy egtb

Post by basil00 » Mon Nov 23, 2015 1:47 am

flok wrote:I sometimes get a segfault in the syzygy code:
There is possibly some issue with 6-man (I could not test 6-man). Try recompiling with -fsanitize=address and see what it says if anything.

I could not guess the problem from the stack trace.

User avatar
Daniel Mehrmann
Posts: 857
Joined: Wed Mar 08, 2006 8:24 pm
Location: Germany
Full name: Daniel Mehrmann

Re: c++ class or a c wrapper for the syzygy egtb

Post by Daniel Mehrmann » Thu Nov 26, 2015 9:13 pm

Dann Corbit wrote: The published API has nothing to do with stockfish.
I agree with you, but i wouldn't call it a API. It's more or less a "proof of concept" and the code breaks a lot of "design" rules.

However, it's not so difficult to use syzygy tablebase support. The upcoming Fruit reloaded version will support Roland's tablebases (at first array board engine?). :D

Regards,
Daniel

PS: I strongly recommend to use Roland's interface code: https://github.com/syzygy1/tb/tree/master/interface

flok

Re: c++ class or a c wrapper for the syzygy egtb

Post by flok » Thu Dec 03, 2015 9:53 am

basil00 wrote:
flok wrote:I sometimes get a segfault in the syzygy code:
There is possibly some issue with 6-man (I could not test 6-man). Try recompiling with -fsanitize=address and see what it says if anything.

I could not guess the problem from the stack trace.
I wrote a bit of code to trigger the problem.
My wrapper creates random fen-strings (well not entirely random; they're all (supposed to be-) valid but their position is random) and after only a couple of iterations it'll crash because of an assertion or a segfault.

The code is here: http://vanheusden.com/Embla/fathom-crash.tgz
Compile it with: make test
Run it with: ./test (assuming a unix environment here)
You may want to adjust the table base path; look for the line 'init_syzygy_etb("/data/syzygy_egtb/syzygy");' in the main-function at the bottom.

Sofar I found that it crashes with an assert or a segfault:

Code: Select all

test&#58; tbprobe.c&#58;1504&#58; probe_dtz_no_ep&#58; Assertion `best != 0xFFFF' failed.

#0  0x00007ffff7a68107 in __GI_raise &#40;sig=sig@entry=6&#41; at ../nptl/sysdeps/unix/sysv/linux/raise.c&#58;56
#1  0x00007ffff7a694e8 in __GI_abort () at abort.c&#58;89
#2  0x00007ffff7a61226 in __assert_fail_base &#40;fmt=0x7ffff7b97d08 "%s%s%s&#58;%u&#58; %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x40fef0 "best != 0xFFFF", file=file@entry=0x40fee6 "tbprobe.c", line=line@entry=1504, 
    function=function@entry=0x40f3a0 <__PRETTY_FUNCTION__.31539> "probe_dtz_no_ep") at assert.c&#58;92
#3  0x00007ffff7a612d2 in __GI___assert_fail &#40;assertion=assertion@entry=0x40fef0 "best != 0xFFFF", file=file@entry=0x40fee6 "tbprobe.c", line=line@entry=1504, 
    function=function@entry=0x40f3a0 <__PRETTY_FUNCTION__.31539> "probe_dtz_no_ep") at assert.c&#58;101
#4  0x000000000040cde6 in probe_dtz_no_ep &#40;success=0x7fffffffd16c, pos=0x7fffffffd170&#41; at tbprobe.c&#58;1504
#5  probe_dtz &#40;pos=pos@entry=0x7fffffffd170, success=success@entry=0x7fffffffd16c&#41; at tbprobe.c&#58;1573
#6  0x000000000040d0f3 in probe_root &#40;pos=pos@entry=0x7fffffffd6f0, score=score@entry=0x7fffffffd6ec, results=results@entry=0x7fffffffd800&#41; at tbprobe.c&#58;1686
#7  0x000000000040ec05 in tb_probe_root_impl &#40;white=white@entry=4503599660925184, black=black@entry=4755801206503243776, kings=kings@entry=144115188075856128, 
    queens=queens@entry=0, rooks=rooks@entry=0, bishops=bishops@entry=0, knights=4503599627370496, pawns=4611686018460942336, rule50=10, ep=0, turn=true, 
    results=0x7fffffffd800&#41; at tbprobe.c&#58;1861
#8  0x0000000000401446 in tb_probe_root (_results=0x7fffffffd800, _turn=<optimized out>, _ep=0, _castling=0, _rule50=10, _pawns=4611686018460942336, 
    _knights=4503599627370496, _bishops=0, _rooks=0, _queens=0, _kings=144115188075856128, _black=4755801206503243776, _white=4503599660925184&#41; at tbprobe.h&#58;278
#9  query_syzygy_etb &#40;fen=fen@entry=0x7fffffffe0a0 "1k4p1/4N3/8/8/1P6/8/K7/8 w - - 10 1") at fathom.c&#58;776
#10 0x0000000000400edf in main &#40;argc=<optimized out>, argv=<optimized out>) at fathom.c&#58;927
and:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
decompress_pairs &#40;d=0x722000, idx=<optimized out>) at tbcore.c&#58;1515
1515	  uint32 code = __builtin_bswap32&#40;*ptr++);
&#40;gdb&#41; bt
#0  decompress_pairs &#40;d=0x722000, idx=<optimized out>) at tbcore.c&#58;1515
#1  0x00000000004078e9 in probe_wdl_table &#40;success=0x7fffffffd16c, pos=<optimized out>) at tbprobe.c&#58;757
#2  probe_ab &#40;pos=pos@entry=0x7fffffffd6f0, alpha=alpha@entry=-2, beta=beta@entry=2, success=success@entry=0x7fffffffd16c&#41; at tbprobe.c&#58;1376
#3  0x000000000040b361 in probe_dtz_no_ep &#40;success=0x7fffffffd16c, pos=0x7fffffffd6f0&#41; at tbprobe.c&#58;1451
#4  probe_dtz &#40;pos=pos@entry=0x7fffffffd6f0, success=success@entry=0x7fffffffd16c&#41; at tbprobe.c&#58;1573
#5  0x000000000040ce3e in probe_root &#40;pos=pos@entry=0x7fffffffd6f0, score=score@entry=0x7fffffffd6ec, results=results@entry=0x7fffffffd800&#41; at tbprobe.c&#58;1660
#6  0x000000000040ec05 in tb_probe_root_impl &#40;white=white@entry=9241386435364261888, black=black@entry=320, kings=kings@entry=18014398509482240, 
    queens=queens@entry=0, rooks=rooks@entry=0, bishops=bishops@entry=0, knights=4096, pawns=9223372036854775872, rule50=10, ep=0, turn=false, 
    results=0x7fffffffd800&#41; at tbprobe.c&#58;1861
#7  0x0000000000401446 in tb_probe_root (_results=0x7fffffffd800, _turn=<optimized out>, _ep=0, _castling=0, _rule50=10, _pawns=9223372036854775872, 
    _knights=4096, _bishops=0, _rooks=0, _queens=0, _kings=18014398509482240, _black=320, _white=9241386435364261888&#41; at tbprobe.h&#58;278
#8  query_syzygy_etb &#40;fen=fen@entry=0x7fffffffe0a0 "7P/6K1/8/8/8/8/k3N3/6p1 b - - 10 1") at fathom.c&#58;776
#9  0x0000000000400edf in main &#40;argc=<optimized out>, argv=<optimized out>) at fathom.c&#58;927

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x0000000000403106 in decompress_pairs &#40;d=0x6a6fe0, idx=<optimized out>) at tbcore.c&#58;1481
1481	      litidx += d->sizetable&#91;--block&#93; + 1;
&#40;gdb&#41; bt
#0  0x0000000000403106 in decompress_pairs &#40;d=0x6a6fe0, idx=<optimized out>) at tbcore.c&#58;1481
#1  0x00000000004078e9 in probe_wdl_table &#40;success=0x7fffffffd16c, pos=<optimized out>) at tbprobe.c&#58;757
#2  probe_ab &#40;pos=pos@entry=0x7fffffffd6f0, alpha=alpha@entry=-2, beta=beta@entry=2, success=success@entry=0x7fffffffd16c&#41; at tbprobe.c&#58;1376
#3  0x000000000040b361 in probe_dtz_no_ep &#40;success=0x7fffffffd16c, pos=0x7fffffffd6f0&#41; at tbprobe.c&#58;1451
#4  probe_dtz &#40;pos=pos@entry=0x7fffffffd6f0, success=success@entry=0x7fffffffd16c&#41; at tbprobe.c&#58;1573
#5  0x000000000040ce3e in probe_root &#40;pos=pos@entry=0x7fffffffd6f0, score=score@entry=0x7fffffffd6ec, results=results@entry=0x7fffffffd800&#41; at tbprobe.c&#58;1660
#6  0x000000000040ec05 in tb_probe_root_impl &#40;white=white@entry=9232379236109516800, black=black@entry=537395232, kings=kings@entry=9007199254741024, 
    queens=queens@entry=536870912, rooks=rooks@entry=0, bishops=bishops@entry=0, knights=0, pawns=9223372036855300096, rule50=10, ep=0, turn=true, 
    results=0x7fffffffd800&#41; at tbprobe.c&#58;1861
#7  0x0000000000401446 in tb_probe_root (_results=0x7fffffffd800, _turn=<optimized out>, _ep=0, _castling=0, _rule50=10, _pawns=9223372036855300096, 
    _knights=0, _bishops=0, _rooks=0, _queens=536870912, _kings=9007199254741024, _black=537395232, _white=9232379236109516800&#41; at tbprobe.h&#58;278
#8  query_syzygy_etb &#40;fen=fen@entry=0x7fffffffe0a0 "7P/5K2/8/8/5q2/3p4/8/5k2 w - - 10 1") at fathom.c&#58;776
#9  0x0000000000400edf in main &#40;argc=<optimized out>, argv=<optimized out>) at fathom.c&#58;927

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
decompress_pairs &#40;d=0x7534b0, idx=<optimized out>) at tbcore.c&#58;1515
1515	  uint32 code = __builtin_bswap32&#40;*ptr++);
&#40;gdb&#41; bt
#0  decompress_pairs &#40;d=0x7534b0, idx=<optimized out>) at tbcore.c&#58;1515
#1  0x00000000004078e9 in probe_wdl_table &#40;success=0x7fffffffd16c, pos=<optimized out>) at tbprobe.c&#58;757
#2  probe_ab &#40;pos=pos@entry=0x7fffffffd170, alpha=alpha@entry=-2, beta=beta@entry=2, success=success@entry=0x7fffffffd16c&#41; at tbprobe.c&#58;1376
#3  0x000000000040b361 in probe_dtz_no_ep &#40;success=0x7fffffffd16c, pos=0x7fffffffd170&#41; at tbprobe.c&#58;1451
#4  probe_dtz &#40;pos=pos@entry=0x7fffffffd170, success=success@entry=0x7fffffffd16c&#41; at tbprobe.c&#58;1573
#5  0x000000000040d0f3 in probe_root &#40;pos=pos@entry=0x7fffffffd6f0, score=score@entry=0x7fffffffd6ec, results=results@entry=0x7fffffffd800&#41; at tbprobe.c&#58;1686
#6  0x000000000040ec05 in tb_probe_root_impl &#40;white=white@entry=33554512, black=black@entry=32772, kings=kings@entry=68, queens=queens@entry=0, 
    rooks=rooks@entry=0, bishops=bishops@entry=0, knights=33554432, pawns=32784, rule50=10, ep=0, turn=true, results=0x7fffffffd800&#41; at tbprobe.c&#58;1861
#7  0x0000000000401446 in tb_probe_root (_results=0x7fffffffd800, _turn=<optimized out>, _ep=0, _castling=0, _rule50=10, _pawns=32784, _knights=33554432, 
    _bishops=0, _rooks=0, _queens=0, _kings=68, _black=32772, _white=33554512&#41; at tbprobe.h&#58;278
#8  query_syzygy_etb &#40;fen=fen@entry=0x7fffffffe0a0 "8/8/8/8/1N6/8/7p/2k1P1K1 w - - 10 1") at fathom.c&#58;776
#9  0x0000000000400edf in main &#40;argc=<optimized out>, argv=<optimized out>) at fathom.c&#58;927

flok

Re: c++ class or a c wrapper for the syzygy egtb

Post by flok » Thu Dec 03, 2015 10:35 am

Some failing FEN-strings:

segfault:
8/R7/P4k2/8/8/8/8/2KP4 w - - 10 1
2K1P3/8/6b1/8/3p1k2/8/8/8 w - - 10 1
8/1k6/7K/7P/8/8/6Q1/7p b - - 10 1
3p2R1/7k/p7/8/8/8/8/6K1 w - - 10 1
8/4K3/8/4P3/7k/8/8/p2B4 b - - 10 1

assertion failed:
p7/8/2P1K3/8/8/8/N7/3k4 b - - 10 1
4P3/1K6/8/1r6/8/7k/B7/8 w - - 10 1
2P1p3/R7/8/2k5/7K/8/8/8 w - - 10 1
8/8/K2k4/8/8/2p5/N7/3P4 w - - 10 1
3p4/2N5/7K/8/1P6/8/3k4/8 w - - 10 1

mar
Posts: 2392
Joined: Fri Nov 26, 2010 1:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: c++ class or a c wrapper for the syzygy egtb

Post by mar » Thu Dec 03, 2015 10:44 am

flok wrote:Some failing FEN-strings:

segfault:
8/R7/P4k2/8/8/8/8/2KP4 w - - 10 1
Well this is invalid position with pawn on rank 1 :)
Edit: in fact, all of those positions you posted are invalid/illegal

Post Reply