Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ Remove option to disable TT #720

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/Lynx/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;

namespace Lynx;
Expand Down Expand Up @@ -66,14 +65,7 @@ public static bool IsPonder
public static int Hash
{
get => EngineSettings.TranspositionTableSize;
set
{
EngineSettings.TranspositionTableSize = value;
if (value == 0)
{
EngineSettings.TranspositionTableEnabled = false;
}
}
set => EngineSettings.TranspositionTableSize = value;
}
}

Expand All @@ -97,8 +89,6 @@ public sealed class EngineSettings
/// </summary>
public int TranspositionTableSize { get; set; } = 256;

public bool TranspositionTableEnabled { get; set; } = true;

public bool UseOnlineTablebaseInRootPositions { get; set; } = false;

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Lynx/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ public static class Constants
/// </summary>
public const int AbsoluteMaxTTSize = 8192;

public const int AbsoluteMinTTSize = 2;

/// <summary>
/// 218 or 224 seems to be the known limit
/// https://www.reddit.com/r/chess/comments/9j70dc/position_with_the_most_number_of_legal_moves/
Expand Down
7 changes: 2 additions & 5 deletions src/Lynx/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,8 @@ public void StopSearching()

private void InitializeTT()
{
if (Configuration.EngineSettings.TranspositionTableEnabled)
{
(int ttLength, _ttMask) = TranspositionTableExtensions.CalculateLength(Configuration.EngineSettings.TranspositionTableSize);
_tt = GC.AllocateArray<TranspositionTableElement>(ttLength, pinned: true);
}
(int ttLength, _ttMask) = TranspositionTableExtensions.CalculateLength(Configuration.EngineSettings.TranspositionTableSize);
_tt = GC.AllocateArray<TranspositionTableElement>(ttLength, pinned: true);
}

private static void InitializeStaticClasses()
Expand Down
10 changes: 0 additions & 10 deletions src/Lynx/Model/TranspositionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ public static void ClearTranspositionTable(this TranspositionTable transposition
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (int Evaluation, ShortMove BestMove, NodeType NodeType, int score) ProbeHash(this TranspositionTable tt, int ttMask, Position position, int depth, int ply, int alpha, int beta)
{
if (!Configuration.EngineSettings.TranspositionTableEnabled)
{
return (EvaluationConstants.NoHashEntry, default, default, default);
}

ref var entry = ref tt[position.UniqueIdentifier & ttMask];

if ((position.UniqueIdentifier >> 48) != entry.Key)
Expand Down Expand Up @@ -163,11 +158,6 @@ public static (int Evaluation, ShortMove BestMove, NodeType NodeType, int score)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RecordHash(this TranspositionTable tt, int ttMask, Position position, int depth, int ply, int eval, NodeType nodeType, Move? move = null)
{
if (!Configuration.EngineSettings.TranspositionTableEnabled)
{
return;
}

ref var entry = ref tt[position.UniqueIdentifier & ttMask];

//if (entry.Key != default && entry.Key != position.UniqueIdentifier)
Expand Down
2 changes: 1 addition & 1 deletion src/Lynx/UCI/Commands/Engine/OptionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public sealed class OptionCommand : EngineBaseCommand
"option name UCI_Opponent type string",
$"option name UCI_EngineAbout type string default {IdCommand.EngineName} by {IdCommand.EngineAuthor}, see https://github.com/lynx-chess/Lynx",
$"option name UCI_ShowWDL type check default {Configuration.EngineSettings.ShowWDL}",
$"option name Hash type spin default {Configuration.EngineSettings.TranspositionTableSize} min 0 max {Constants.AbsoluteMaxTTSize}",
$"option name Hash type spin default {Configuration.EngineSettings.TranspositionTableSize} min {Constants.AbsoluteMinTTSize} max {Constants.AbsoluteMaxTTSize}",
$"option name OnlineTablebaseInRootPositions type check default {Configuration.EngineSettings.UseOnlineTablebaseInRootPositions}",
"option name Threads type spin default 1 min 1 max 1",

Expand Down
2 changes: 1 addition & 1 deletion src/Lynx/UCIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void HandleSetOption(ReadOnlySpan<char> command)
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.Hash = Math.Clamp(value, 0, Constants.AbsoluteMaxTTSize);
Configuration.Hash = Math.Clamp(value, Constants.AbsoluteMinTTSize, Constants.AbsoluteMaxTTSize);
}
break;
}
Expand Down
Loading