Giter VIP home page Giter VIP logo

Comments (10)

mstembera avatar mstembera commented on June 12, 2024 2

So -O3 and -O2 crash. -O1 is fine. Disabling lto is also fine. Adding either debug=yes or optimize=no is also fine. The bench position it crashes on is
Position: 3/48 (8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11)
The last position printed at the top of do_probe_table() is
8/8/3K4/1r6/8/8/4k3/2R5 b - - 0 18
These were all non PGO builds using syzygy 6-men.

from stockfish.

MinetaS avatar MinetaS commented on June 12, 2024 1

After a short analysis, this indeed looks like a compiler bug.

At syzygy/tbprobe.cpp:722, r8 register has a weird value and it gets swapped to squares[0].

        std::swap(squares[0], *std::max_element(squares, squares + leadPawnsCnt, pawns_comp));
 ► 0x5555555914ea <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+1530>    mov    dword ptr [rsp + 0x140], r8d

Although it would be better if we can find some workarounds here. (i.e. do not use STL and implement max_element manually for Clang 15)

from stockfish.

Sopel97 avatar Sopel97 commented on June 12, 2024

Could you test if the crash persists after changing the line

int MapPawns[SQUARE_NB];

to

alignas(64) int MapPawns[SQUARE_NB];

on the same version you tested?

from stockfish.

Sopel97 avatar Sopel97 commented on June 12, 2024

My theory is that there's some NNUE buffer before this array, and since we appear to have a defect

using OutputBuffer = OutputType[PaddedOutputDimensions];

where NNUE buffers are only required to be multiples of 32 bytes it's possible that they don't occupy the whole cacheline that's accessed by avx512. So other arrays can be placed directly after and be hit by avx512 writes to nnue buffers.

edit.

upon further inspection this should not be an issue in the current NNUE code (since output buffers for affine are in multiples of 4*32 bytes, and activation layers don't use avx512), but I don't remember how it looked in march. It's also possible that it's an issue in a similar vein somewhere else, or even a compiler bug. Checking what is placed before that array in memory would probably be required, provided the issue is present in the current master.

from stockfish.

MinetaS avatar MinetaS commented on June 12, 2024

I can't test right now as my Linux partition has been corrupted and is not able to boot into. Currently working in fixing driver incompatibility + miscellaneous HW setup.

Before I fully resolve the issue, appreciate if anyone can check this with an AVX-512 supported processor and Clang 15.

from stockfish.

Disservin avatar Disservin commented on June 12, 2024

Can someone check this again?

from stockfish.

MinetaS avatar MinetaS commented on June 12, 2024

The issue still persists.

Reproduce
❯ git rev-parse master
3f7fb5ac1d58e1c90db063053e9f913b9df79994

❯ clang --version
Ubuntu clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

❯ make -j$(nproc) build ARCH=x86-64-vnni512 COMP=clang
Default net: nn-1ee1aba5ed4c.nnue
nn-1ee1aba5ed4c.nnue available : OK
Network validated
...

❯ ./stockfish
Stockfish dev-20230911-3f7fb5ac by the Stockfish developers (see AUTHORS file)
setoption name Hash value 16384
setoption name SyzygyPath value /media/***/Storage/Chess/Tablebases/syzygy/3:/media/***/Storage/Chess/Tablebases/syzygy/4:/media/***/Storage/Chess/Tablebases/syzygy/5:/media/***/Storage/Chess/Tablebases/syzygy/6:/media/***/Storage/Chess/Tablebases/syzygy/7
info string Found 530 tablebases
position fen r3r1k1/2qb1pp1/pp2n1np/2p1P3/2R1N3/1B3N1P/PP1Q1PP1/4R1K1 w - -
go infinite
info string NNUE evaluation using nn-1ee1aba5ed4c.nnue
info depth 1 seldepth 1 multipv 1 score cp 109 nodes 66 nps 66000 hashfull 0 tbhits 0 time 1 pv e4d6
info depth 2 seldepth 2 multipv 1 score cp 109 nodes 117 nps 117000 hashfull 0 tbhits 0 time 1 pv e4d6
info depth 3 seldepth 2 multipv 1 score cp 109 nodes 168 nps 168000 hashfull 0 tbhits 0 time 1 pv e4d6
info depth 4 seldepth 2 multipv 1 score cp 162 nodes 224 nps 224000 hashfull 0 tbhits 0 time 1 pv e4d6
info depth 5 seldepth 3 multipv 1 score cp 162 nodes 304 nps 304000 hashfull 0 tbhits 0 time 1 pv e4d6 e8d8
info depth 6 seldepth 4 multipv 1 score cp 221 nodes 496 nps 496000 hashfull 0 tbhits 0 time 1 pv e4d6 e8d8 c4g4
info depth 7 seldepth 5 multipv 1 score cp 197 nodes 1141 nps 570500 hashfull 0 tbhits 0 time 2 pv e4d6 d7c6 d6e8 a8e8
info depth 8 seldepth 10 multipv 1 score cp 211 nodes 1984 nps 992000 hashfull 0 tbhits 0 time 2 pv e4d6 e8f8 c4g4 a8d8 h3h4 g8h8
info depth 9 seldepth 9 multipv 1 score cp 205 nodes 5333 nps 1333250 hashfull 0 tbhits 0 time 4 pv e4d6 e8e7 d6f5 e7e8 c4g4 d7c6
info depth 10 seldepth 9 multipv 1 score cp 203 nodes 10017 nps 1431000 hashfull 0 tbhits 0 time 7 pv e4d6 b6b5 d6e8 a8e8
info depth 11 seldepth 16 multipv 1 score cp 170 nodes 19561 nps 1630083 hashfull 0 tbhits 0 time 12 pv e4d6 d7c6 f3h4 b6b5 c4g4 g6h4 g4h4 a8d8 h4g4
info depth 12 seldepth 13 multipv 1 score cp 183 nodes 23500 nps 1678571 hashfull 0 tbhits 0 time 14 pv e4d6 d7c6 f3h4 b6b5 c4g4 g6h4 g4h4 a8d8 h4g4 g8f8
info depth 13 seldepth 16 multipv 1 score cp 201 nodes 38450 nps 1747727 hashfull 0 tbhits 0 time 22 pv e4d6 d7c6 f3h4 b6b5 d6e8 a8e8 c4g4 e8d8 d2c3 g6h4 g4h4
info depth 14 seldepth 18 multipv 1 score cp 208 nodes 64451 nps 1790305 hashfull 0 tbhits 0 time 36 pv e4d6 d7c6 f3h4 b6b5 c4g4 g6h4 g4h4 a8d8 d6e8 c6e8 d2c3
info depth 15 seldepth 17 multipv 1 score cp 212 nodes 90288 nps 1805760 hashfull 0 tbhits 0 time 50 pv e4d6 d7c6 f3h4 b6b5 c4g4 g6h4 g4h4 e8e7 h4g4 g8h8 f2f4
info depth 16 seldepth 20 multipv 1 score cp 217 nodes 136168 nps 1815573 hashfull 0 tbhits 0 time 75 pv e4f6 g7f6 d2h6 f6f5 f3h4 d7b5 h4f5 b5c4 b3c4 g6e5 c4e6 e5f3 g2f3 f7e6 e1e6 e8e6 h6e6 g8h7
info depth 17 seldepth 23 multipv 1 score cp 204 nodes 191085 nps 1819857 hashfull 0 tbhits 0 time 105 pv e4d6 e8e7 c4g4 a8d8 d6f5 d7c6 d2e3 c6d5 f5e7 c7e7 b3c2 d5f3 e3f3 h6h5
info depth 18 seldepth 25 multipv 1 score cp 280 nodes 339828 nps 1846891 hashfull 0 tbhits 0 time 184 pv e4f6 g8h8 f6e8 a8e8 f3h4
info depth 19 seldepth 24 multipv 1 score cp 283 nodes 464279 nps 1827870 hashfull 0 tbhits 0 time 254 pv e4f6 g8h8 f3h4 g6e7 f6e8 a8e8 c4c3 h8g8 c3g3 g7g5 f2f4 c5c4 b3c2
info depth 20 seldepth 25 multipv 1 score cp 316 nodes 802870 nps 1820566 hashfull 0 tbhits 0 time 441 pv e4f6 g8h8 f3h4 g6e5 c4e4 e6g5 f6e8 a8e8 e4e3 c5c4 b3c2 e8e6 e1d1 d7c6 d2c3 e5f3 h4f3 c6f3
info depth 21 seldepth 28 multipv 1 score cp 317 nodes 1157152 nps 1825160 hashfull 0 tbhits 0 time 634 pv e4f6 g8h8 f3h4 a8d8 h4g6 f7g6 f6e8 d7e8 d2e3 e6d4 e5e6 c7e7 c4c3 b6b5 c3c1 c5c4 b3d1 h8h7 d1c2 d8d6
info depth 22 seldepth 32 multipv 1 score cp 318 nodes 1523387 nps 1817884 hashfull 0 tbhits 0 time 838 pv e4f6 g8h8 f3h4 e8d8 h4g6 f7g6 c4h4 g6g5 b3e6 d7e6 d2g5 e6g8 f6g8 d8g8 g5g6 c7e7 h4e4 b6b5 f2f4 a8f8 f4f5
info depth 23 seldepth 34 multipv 1 score cp 271 nodes 2318029 nps 1801110 hashfull 0 tbhits 0 time 1287 pv e4f6 g8h8 f3h4 e8d8 h4g6 f7g6 c4h4 g6g5 b3e6 d7e6 d2g5 e6g8 f6g8 d8g8 e5e6 g8e8 f2f4 c7e7 g5e7 e8e7 f4f5 h8g8 h4a4 a6a5 g1f2 a8d8 g2g4 g8f8 a4e4 d8d2 e4e2
info depth 24 seldepth 41 multipv 1 score cp 289 nodes 3092343 nps 1797873 hashfull 0 tbhits 0 time 1720 pv e4f6 g8h8 f6e8 a8e8 f3h4 g6h4 c4h4 h8g8 h4g4 g8f8 b3e6 d7e6 g4g3 a6a5 g3d3 e6a2 d3d7 c7c8 d7d6 c8b7 d2d3 a2e6 d3h7
[1]    12957 segmentation fault (core dumped)  ./stockfish
gdb output
0x0000555555591899 in Stockfish::(anonymous namespace)::do_probe_table<Stockfish::(anonymous namespace)::TBTable<(Stockfish::(anonymous namespace)::TBType)0>, Stockfish::Tablebases::WDLScore> (pos=..., wdl=Stockfish::Tablebases::WDLDraw, entry=<optimized out>, 
    result=<optimized out>) at syzygy/tbprobe.cpp:766
766	        idx = LeadPawnIdx[leadPawnsCnt][squares[0]];
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
───────────────────────────────────────────────────────────────────────────────────────────────────────────[ REGISTERS / show-flags off / show-compact-regs off ]───────────────────────────────────────────────────────────────────────────────────────────────────────────
*RAX  0x804100
*RBX  0x6
*RCX  0x100
*RDX  0x555558832b20 (Stockfish::(anonymous namespace)::LeadPawnIdx+256) ◂— 0x0
*RDI  0x6
*RSI  0x7
*R8   0x20010400804100
*R9   0x1
*R10  0x6
*R11  0x55555891a6b0 ◂— 0x1
 R12  0x0
*R13  0x1
*R14  0x1
 R15  0x0
*RBP  0x5
*RSP  0x7ffff6f78b90 ◂— 0x580300
*RIP  0x555555591899 (Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2473) ◂— movsxd rbp, dword ptr [rdx + rax*4]
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ DISASM / x86-64 / set emulate on ]────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 ► 0x555555591899 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2473>    movsxd rbp, dword ptr [rdx + rax*4]
   0x55555559189d <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2477>    cmp    r13d, 1
   0x5555555918a1 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2481>    jne    Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2536                <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2536>
    ↓
   0x5555555918d8 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2536>    mov    qword ptr [rsp + 0x28], rbp
   0x5555555918dd <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2541>    lea    rax, [r14*4 - 4]
   0x5555555918e5 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2549>    sar    rax, 2
   0x5555555918e9 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2553>    lea    rcx, [rax + 1]
   0x5555555918ed <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2557>    shr    rcx, 0x3f
   0x5555555918f1 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2561>    lea    rbx, [rax + rcx]
   0x5555555918f5 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2565>    inc    rbx
   0x5555555918f8 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2568>    sar    rbx, 1
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ SOURCE (CODE) ]──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
In file: /home/syine/repos/Stockfish/src/syzygy/tbprobe.cpp
   761             squares[i] = flip_file(squares[i]);
   762 
   763     // Encode leading pawns starting with the one with minimum MapPawns[] and
   764     // proceeding in ascending order.
   765     if (entry->hasPawns) {
 ► 766         idx = LeadPawnIdx[leadPawnsCnt][squares[0]];
   767 
   768         std::stable_sort(squares + 1, squares + leadPawnsCnt, pawns_comp);
   769 
   770         for (int i = 1; i < leadPawnsCnt; ++i)
   771             idx += Binomial[i][MapPawns[squares[i]]];
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rsp 0x7ffff6f78b90 ◂— 0x580300
01:0008│     0x7ffff6f78b98 ◂— 0x1000
02:0010│     0x7ffff6f78ba0 —▸ 0x55555891a6b0 ◂— 0x1
03:0018│     0x7ffff6f78ba8 ◂— 0x1
04:0020│     0x7ffff6f78bb0 ◂— 0x20a00
05:0028│     0x7ffff6f78bb8 ◂— 0x0
06:0030│     0x7ffff6f78bc0 ◂— 0xb000000000000
07:0038│     0x7ffff6f78bc8 ◂— 0x0
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 ► 0   0x555555591899 Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2473
   1   0x555555591899 Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2473
   2   0x555555590e95 Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::search<false>(Stockfish::Position&, Stockfish::Tablebases::ProbeState*)+517
   3   0x555555575a02 Stockfish::Value Stockfish::(anonymous namespace)::search<(Stockfish::(anonymous namespace)::NodeType)0>(Stockfish::Position&, Stockfish::Search::Stack*, Stockfish::Value, Stockfish::Value, int, bool)+7922
   4   0x555555575a02 Stockfish::Value Stockfish::(anonymous namespace)::search<(Stockfish::(anonymous namespace)::NodeType)0>(Stockfish::Position&, Stockfish::Search::Stack*, Stockfish::Value, Stockfish::Value, int, bool)+7922
   5   0x5555555752bc Stockfish::Value Stockfish::(anonymous namespace)::search<(Stockfish::(anonymous namespace)::NodeType)0>(Stockfish::Position&, Stockfish::Search::Stack*, Stockfish::Value, Stockfish::Value, int, bool)+6060
   6   0x5555555752bc Stockfish::Value Stockfish::(anonymous namespace)::search<(Stockfish::(anonymous namespace)::NodeType)0>(Stockfish::Position&, Stockfish::Search::Stack*, Stockfish::Value, Stockfish::Value, int, bool)+6060
   7   0x5555555752bc Stockfish::Value Stockfish::(anonymous namespace)::search<(Stockfish::(anonymous namespace)::NodeType)0>(Stockfish::Position&, Stockfish::Search::Stack*, Stockfish::Value, Stockfish::Value, int, bool)+6060
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ THREADS ]─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    1	"stockfish" stopped: 0x7ffff790b97c <read+76> 
  ► 2	"stockfish" stopped: 0x555555591899 <Stockfish::Tablebases::WDLScore Stockfish::(anonymous namespace)::probe_table<(Stockfish::(anonymous namespace)::TBType)0, Stockfish::Tablebases::WDLScore>(Stockfish::Position const&, Stockfish::Tablebases::ProbeState*, Stockfish::Tablebases::WDLScore)+2473> 
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

from stockfish.

mstembera avatar mstembera commented on June 12, 2024

I can also confirm that this crashes for me. I tested w/ syzygy 6-men, then 5-men, then 4-men. They all crash w/ clang 17.0.1 and avx512 but not w/ avx2. gcc and MSVC work fine.

from stockfish.

vondele avatar vondele commented on June 12, 2024

so clang 15 - 17 either expose an issue or miscompile the code. That's actually a problem given we have a number of fishtest workers that use clang, and people might use it by default (macs?). Would be interesting to see what happens if we compile with clang and test optimization level (-O0 .. -O3), profile-use or not (PGO), and LTO.

from stockfish.

Sopel97 avatar Sopel97 commented on June 12, 2024

It would be nice if we knew what position causes the crash exactly. Could be printed at the start of do_probe_table and take the last output.

edit. with clang 13 I'm unable to reproduce.

from stockfish.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.