Skip to content

Commit

Permalink
Adress single bench and PGO build issues. (Rebased)
Browse files Browse the repository at this point in the history
bench: 4471333
  • Loading branch information
mstembera authored and mstembera committed Aug 3, 2020
1 parent 1d01b27 commit f3bacae
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ vector<string> setup_bench(const Position& current, istream& is) {
string limit = (is >> token) ? token : "13";
string fenFile = (is >> token) ? token : "default";
string limitType = (is >> token) ? token : "depth";
string evType = (is >> token) ? token : "Blend";

go = limitType == "eval" ? "eval" : "go " + limitType + " " + limit;

Expand Down Expand Up @@ -146,6 +147,7 @@ vector<string> setup_bench(const Position& current, istream& is) {

list.emplace_back("setoption name Threads value " + threads);
list.emplace_back("setoption name Hash value " + ttSize);
list.emplace_back("setoption name Eval Type value " + evType);
list.emplace_back("ucinewgame");

for (const string& fen : fens)
Expand Down
20 changes: 12 additions & 8 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,33 @@

namespace Eval {

bool useNNUE;
EvalType evalType = ET_CLASSIC;
std::string eval_file_loaded="None";

void init_NNUE() {

useNNUE = Options["Use NNUE"];
evalType = Options["Eval Type"] == "NNUE" ? ET_NNUE : Options["Eval Type"] == "Blend" ? ET_BLEND : ET_CLASSIC;
std::string eval_file = std::string(Options["EvalFile"]);
if (useNNUE && eval_file_loaded != eval_file)
if (evalType != ET_CLASSIC && eval_file_loaded != eval_file)
if (Eval::NNUE::load_eval_file(eval_file))
eval_file_loaded = eval_file;
}

void verify_NNUE() {

std::string eval_file = std::string(Options["EvalFile"]);
if (useNNUE && eval_file_loaded != eval_file)
if (evalType != ET_CLASSIC && eval_file_loaded != eval_file)
{
std::cerr << "Use of NNUE evaluation, but the file " << eval_file << " was not loaded successfully. "
<< "These network evaluation parameters must be available, compatible with this version of the code. "
<< "The UCI option EvalFile might need to specify the full path, including the directory/folder name, to the file." << std::endl;
std::exit(EXIT_FAILURE);
}

if (useNNUE)
if (evalType == ET_NNUE)
sync_cout << "info string NNUE evaluation using " << eval_file << " enabled." << sync_endl;
else if (evalType == ET_BLEND)
sync_cout << "info string blended evaluation using " << eval_file << " enabled." << sync_endl;
else
sync_cout << "info string classical evaluation enabled." << sync_endl;
}
Expand Down Expand Up @@ -936,10 +938,12 @@ namespace {

Value Eval::evaluate(const Position& pos) {

if (Eval::useNNUE)
if (Eval::evalType == ET_NNUE)
return NNUE::evaluate(pos);
else
else if(Eval::evalType == ET_CLASSIC)
return Evaluation<NO_TRACE>(pos).value();
else // ET_BLEND
return (NNUE::evaluate(pos) + Evaluation<NO_TRACE>(pos).value()) / 2;
}

/// trace() is like evaluate(), but instead of returning a value, it returns
Expand All @@ -957,7 +961,7 @@ std::string Eval::trace(const Position& pos) {

Value v;

if (Eval::useNNUE)
if (Eval::evalType == ET_NNUE)
{
v = NNUE::evaluate(pos);
}
Expand Down
8 changes: 7 additions & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@

class Position;

enum EvalType {
ET_CLASSIC,
ET_NNUE,
ET_BLEND
};

namespace Eval {

std::string trace(const Position& pos);
Value evaluate(const Position& pos);

extern bool useNNUE;
extern EvalType evalType;
extern std::string eval_file_loaded;
void init_NNUE();
void verify_NNUE();
Expand Down
16 changes: 8 additions & 8 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Th
auto pc = Piece(idx);
put_piece(pc, sq);

if (Eval::useNNUE)
if (Eval::evalType != ET_CLASSIC)
{
// Kings get a fixed ID, other pieces get ID in order of placement
piece_id =
Expand Down Expand Up @@ -775,7 +775,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
else
st->nonPawnMaterial[them] -= PieceValue[MG][captured];

if (Eval::useNNUE)
if (Eval::evalType != ET_CLASSIC)
{
dp.dirty_num = 2; // 2 pieces moved
dp1 = piece_id_on(capsq);
Expand Down Expand Up @@ -821,7 +821,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
// Move the piece. The tricky Chess960 castling is handled earlier
if (type_of(m) != CASTLING)
{
if (Eval::useNNUE)
if (Eval::evalType != ET_CLASSIC)
{
dp0 = piece_id_on(from);
dp.pieceId[0] = dp0;
Expand Down Expand Up @@ -854,7 +854,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
remove_piece(to);
put_piece(promotion, to);

if (Eval::useNNUE)
if (Eval::evalType != ET_CLASSIC)
{
dp0 = piece_id_on(to);
evalList.put_piece(dp0, to, promotion);
Expand Down Expand Up @@ -952,7 +952,7 @@ void Position::undo_move(Move m) {
{
move_piece(to, from); // Put the piece back at the source square

if (Eval::useNNUE)
if (Eval::evalType != ET_CLASSIC)
{
PieceId dp0 = st->dirtyPiece.pieceId[0];
evalList.put_piece(dp0, from, pc);
Expand All @@ -975,7 +975,7 @@ void Position::undo_move(Move m) {

put_piece(st->capturedPiece, capsq); // Restore the captured piece

if (Eval::useNNUE)
if (Eval::evalType != ET_CLASSIC)
{
PieceId dp1 = st->dirtyPiece.pieceId[1];
assert(evalList.piece_with_id(dp1).from[WHITE] == PS_NONE);
Expand Down Expand Up @@ -1003,7 +1003,7 @@ void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Squ
rto = relative_square(us, kingSide ? SQ_F1 : SQ_D1);
to = relative_square(us, kingSide ? SQ_G1 : SQ_C1);

if (Eval::useNNUE)
if (Eval::evalType != ET_CLASSIC)
{
PieceId dp0, dp1;
auto& dp = st->dirtyPiece;
Expand Down Expand Up @@ -1048,7 +1048,7 @@ void Position::do_null_move(StateInfo& newSt) {
assert(!checkers());
assert(&newSt != st);

if (Eval::useNNUE)
if (Eval::evalType != ET_CLASSIC)
{
std::memcpy(&newSt, st, sizeof(StateInfo));
st->accumulator.computed_score = false;
Expand Down
4 changes: 2 additions & 2 deletions src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void on_hash_size(const Option& o) { TT.resize(size_t(o)); }
void on_logger(const Option& o) { start_logger(o); }
void on_threads(const Option& o) { Threads.set(size_t(o)); }
void on_tb_path(const Option& o) { Tablebases::init(o); }
void on_use_NNUE(const Option& ) { Eval::init_NNUE(); }
void on_eval_type(const Option& ) { Eval::init_NNUE(); }
void on_eval_file(const Option& ) { Eval::init_NNUE(); }

/// Our case insensitive less() function as required by UCI protocol
Expand Down Expand Up @@ -80,7 +80,7 @@ void init(OptionsMap& o) {
o["SyzygyProbeDepth"] << Option(1, 1, 100);
o["Syzygy50MoveRule"] << Option(true);
o["SyzygyProbeLimit"] << Option(7, 0, 7);
o["Use NNUE"] << Option(false, on_use_NNUE);
o["Eval Type"] << Option("Classic var Classic var NNUE var Blend", "Classic", on_eval_type);
o["EvalFile"] << Option("nn-c157e0a5755b.nnue", on_eval_file);
}

Expand Down

0 comments on commit f3bacae

Please sign in to comment.