Revert evaluation cache

And return on using TT as backing store for position
evaluations.

Tests (even on single thread) show eval cache was a regression.
In multi thread result should be even worst because eval cache
is a per-thread struct, while TT is shared.

After 4957 games at 15"+0.05 (single thread)
eval cache vs master 969 - 1093 - 2895  -9 ELO

So previous reported result of +18 ELO was probably due to an
issue in the testing framework (a bug in cutechess-cli) that
has been fixed in the meanwhile.

bench: 5386711
This commit is contained in:
Marco Costalba
2012-12-27 12:13:31 +01:00
parent f78b68b7ff
commit 3cf6471738
6 changed files with 61 additions and 57 deletions

View File

@@ -575,17 +575,31 @@ namespace {
// Step 5. Evaluate the position statically and update parent's gain statistics
if (inCheck)
ss->staticEval = ss->evalMargin = eval = VALUE_NONE;
else
else if (tte)
{
eval = ss->staticEval = evaluate(pos, ss->evalMargin);
// Following asserts are valid only in single thread condition because
// TT access is always racy and its contents cannot be trusted.
assert(tte->static_value() != VALUE_NONE || Threads.size() > 1);
assert(ttValue != VALUE_NONE || tte->type() == BOUND_NONE || Threads.size() > 1);
ss->staticEval = eval = tte->static_value();
ss->evalMargin = tte->static_value_margin();
if (eval == VALUE_NONE || ss->evalMargin == VALUE_NONE) // Due to a race
eval = ss->staticEval = evaluate(pos, ss->evalMargin);
// Can ttValue be used as a better position evaluation?
if (tte && ttValue != VALUE_NONE)
{
if (ttValue != VALUE_NONE)
if ( ((tte->type() & BOUND_LOWER) && ttValue > eval)
|| ((tte->type() & BOUND_UPPER) && ttValue < eval))
eval = ttValue;
}
}
else
{
eval = ss->staticEval = evaluate(pos, ss->evalMargin);
TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE,
ss->staticEval, ss->evalMargin);
}
// Update gain for the parent non-capture move given the static position
@@ -1041,7 +1055,8 @@ split_point_start: // At split points actual search starts from here
if (bestValue >= beta) // Failed high
{
TT.store(posKey, value_to_tt(bestValue, ss->ply), BOUND_LOWER, depth, bestMove);
TT.store(posKey, value_to_tt(bestValue, ss->ply), BOUND_LOWER, depth,
bestMove, ss->staticEval, ss->evalMargin);
if (!pos.is_capture_or_promotion(bestMove) && !inCheck)
{
@@ -1066,7 +1081,7 @@ split_point_start: // At split points actual search starts from here
else // Failed low or PV search
TT.store(posKey, value_to_tt(bestValue, ss->ply),
PvNode && bestMove != MOVE_NONE ? BOUND_EXACT : BOUND_UPPER,
depth, bestMove);
depth, bestMove, ss->staticEval, ss->evalMargin);
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
@@ -1147,6 +1162,16 @@ split_point_start: // At split points actual search starts from here
ss->staticEval = bestValue = -(ss-1)->staticEval;
ss->evalMargin = VALUE_ZERO;
}
else if (tte)
{
assert(tte->static_value() != VALUE_NONE || Threads.size() > 1);
ss->staticEval = bestValue = tte->static_value();
ss->evalMargin = tte->static_value_margin();
if (ss->staticEval == VALUE_NONE || ss->evalMargin == VALUE_NONE) // Due to a race
ss->staticEval = bestValue = evaluate(pos, ss->evalMargin);
}
else
ss->staticEval = bestValue = evaluate(pos, ss->evalMargin);
@@ -1154,7 +1179,8 @@ split_point_start: // At split points actual search starts from here
if (bestValue >= beta)
{
if (!tte)
TT.store(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER, DEPTH_NONE, MOVE_NONE);
TT.store(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER,
DEPTH_NONE, MOVE_NONE, ss->staticEval, ss->evalMargin);
return bestValue;
}
@@ -1263,7 +1289,9 @@ split_point_start: // At split points actual search starts from here
}
else // Fail high
{
TT.store(posKey, value_to_tt(value, ss->ply), BOUND_LOWER, ttDepth, move);
TT.store(posKey, value_to_tt(value, ss->ply), BOUND_LOWER,
ttDepth, move, ss->staticEval, ss->evalMargin);
return value;
}
}
@@ -1277,7 +1305,7 @@ split_point_start: // At split points actual search starts from here
TT.store(posKey, value_to_tt(bestValue, ss->ply),
PvNode && bestValue > oldAlpha ? BOUND_EXACT : BOUND_UPPER,
ttDepth, bestMove);
ttDepth, bestMove, ss->staticEval, ss->evalMargin);
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
@@ -1574,7 +1602,7 @@ void RootMove::insert_pv_in_tt(Position& pos) {
tte = TT.probe(pos.key());
if (!tte || tte->move() != pv[ply]) // Don't overwrite correct entries
TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply]);
TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply], VALUE_NONE, VALUE_NONE);
assert(MoveList<LEGAL>(pos).contains(pv[ply]));