From d57344ea67b081081b5631dc774a62b30a941528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Tue, 10 Sep 2024 21:59:45 +0200 Subject: [PATCH 1/5] Allocate TT only once --- src/Lynx/Bench.cs | 2 +- src/Lynx/Engine.cs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Lynx/Bench.cs b/src/Lynx/Bench.cs index 723259c32..1865eac27 100644 --- a/src/Lynx/Bench.cs +++ b/src/Lynx/Bench.cs @@ -69,7 +69,7 @@ public partial class Engine "3qr2k/1p3rbp/2p3p1/p7/P2pBNn1/1P3n2/6P1/B1Q1RR1K b - - 1 30", "3qk1b1/1p4r1/1n4r1/2P1b2B/p3N2p/P2Q3P/8/1R3R1K w - - 2 39", - "6RR/4bP2/8/8/5r2/3K4/5p2/4k3 w - -", // SEE test suite - regular promotion + "6RR/4bP2/8/8/5r2/3K4/5p2/4k3 w - - 0 0", // SEE test suite - regular promotion "1n2kb1r/p1P4p/2qb4/5pP1/4n2Q/8/PP1PPP1P/RNB1KBNR w KQk - 0 1", // SEE test suite - promotion with capture "6Q1/8/1kp4P/2q1p3/2PpP3/2nP2P1/p7/5BK1 b - - 1 35", // Fischer vs Petrosian - double promotion "5R2/2k3PK/8/5N2/7P/5q2/8/q7 w - - 0 69", // McShane - Aronian 2012 - knight promotion diff --git a/src/Lynx/Engine.cs b/src/Lynx/Engine.cs index b8d308962..b036ee2d6 100644 --- a/src/Lynx/Engine.cs +++ b/src/Lynx/Engine.cs @@ -73,7 +73,8 @@ public Engine(ChannelWriter engineWriter) _killerMoves[i] = new Move[3]; } - InitializeTT(); + (int ttLength, _ttMask) = TranspositionTableExtensions.CalculateLength(Configuration.EngineSettings.TranspositionTableSize); + _tt = GC.AllocateArray(ttLength, pinned: true); #if !DEBUG // Temporary channel so that no output is generated @@ -81,7 +82,8 @@ public Engine(ChannelWriter engineWriter) WarmupEngine(); _engineWriter = engineWriter; - ResetEngine(); + + // No need for ResetEngine() call here, WarmupEngine -> Bench -> NewGame() calls it #endif #pragma warning disable S1215 // "GC.Collect" should not be called @@ -111,7 +113,7 @@ private void WarmupEngine() private void ResetEngine() { - InitializeTT(); // Attempt to clear instead in https://github.com/lynx-chess/Lynx/pull/960 + Array.Clear(_tt); // Clear histories for (int i = 0; i < 12; ++i) From f18aa0b5f90214998c2b4b3dc8c42b4355565996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Wed, 11 Sep 2024 00:39:31 +0200 Subject: [PATCH 2/5] Revert Array.Clear(_tt), in case that's the issue --- src/Lynx/Engine.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Lynx/Engine.cs b/src/Lynx/Engine.cs index b036ee2d6..67dc1b98d 100644 --- a/src/Lynx/Engine.cs +++ b/src/Lynx/Engine.cs @@ -73,8 +73,7 @@ public Engine(ChannelWriter engineWriter) _killerMoves[i] = new Move[3]; } - (int ttLength, _ttMask) = TranspositionTableExtensions.CalculateLength(Configuration.EngineSettings.TranspositionTableSize); - _tt = GC.AllocateArray(ttLength, pinned: true); + InitializeTT(); #if !DEBUG // Temporary channel so that no output is generated @@ -113,7 +112,7 @@ private void WarmupEngine() private void ResetEngine() { - Array.Clear(_tt); + InitializeTT(); // Clear histories for (int i = 0; i < 12; ++i) From 54fe8b30648cf63acabfb438041b79a45e7995d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Wed, 11 Sep 2024 00:42:10 +0200 Subject: [PATCH 3/5] Revert message --- src/Lynx/Engine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lynx/Engine.cs b/src/Lynx/Engine.cs index 67dc1b98d..57a2555b0 100644 --- a/src/Lynx/Engine.cs +++ b/src/Lynx/Engine.cs @@ -73,7 +73,7 @@ public Engine(ChannelWriter engineWriter) _killerMoves[i] = new Move[3]; } - InitializeTT(); + InitializeTT();// Attempt to clear instead failed in https://github.com/lynx-chess/Lynx/pull/960 #if !DEBUG // Temporary channel so that no output is generated From c861d27ab33315146f37f2106afab4b158d19c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Wed, 11 Sep 2024 00:42:53 +0200 Subject: [PATCH 4/5] Revert "Revert message" This reverts commit 54fe8b30648cf63acabfb438041b79a45e7995d9. --- src/Lynx/Engine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lynx/Engine.cs b/src/Lynx/Engine.cs index 57a2555b0..67dc1b98d 100644 --- a/src/Lynx/Engine.cs +++ b/src/Lynx/Engine.cs @@ -73,7 +73,7 @@ public Engine(ChannelWriter engineWriter) _killerMoves[i] = new Move[3]; } - InitializeTT();// Attempt to clear instead failed in https://github.com/lynx-chess/Lynx/pull/960 + InitializeTT(); #if !DEBUG // Temporary channel so that no output is generated From 8efe1d6d645a46986920af213148708b19564a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20C=C3=A1ceres?= Date: Wed, 11 Sep 2024 00:43:32 +0200 Subject: [PATCH 5/5] Re-add message in the right place --- src/Lynx/Engine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lynx/Engine.cs b/src/Lynx/Engine.cs index 67dc1b98d..696cdec55 100644 --- a/src/Lynx/Engine.cs +++ b/src/Lynx/Engine.cs @@ -112,7 +112,7 @@ private void WarmupEngine() private void ResetEngine() { - InitializeTT(); + InitializeTT(); // Attempt to clear instead in https://github.com/lynx-chess/Lynx/pull/960 // Clear histories for (int i = 0; i < 12; ++i)