mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 12:07:43 +00:00
learn -> tools
This commit is contained in:
+8
-8
@@ -57,17 +57,17 @@ SRCS = benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp main.cpp
|
|||||||
nnue/features/a.cpp \
|
nnue/features/a.cpp \
|
||||||
nnue/features/castling_right.cpp \
|
nnue/features/castling_right.cpp \
|
||||||
nnue/features/enpassant.cpp \
|
nnue/features/enpassant.cpp \
|
||||||
learn/sfen_packer.cpp \
|
tools/sfen_packer.cpp \
|
||||||
learn/gensfen.cpp \
|
tools/gensfen.cpp \
|
||||||
learn/gensfen_nonpv.cpp \
|
tools/gensfen_nonpv.cpp \
|
||||||
learn/opening_book.cpp \
|
tools/opening_book.cpp \
|
||||||
learn/convert.cpp \
|
tools/convert.cpp \
|
||||||
learn/transform.cpp \
|
tools/transform.cpp \
|
||||||
learn/stats.cpp
|
tools/stats.cpp
|
||||||
|
|
||||||
OBJS = $(notdir $(SRCS:.cpp=.o))
|
OBJS = $(notdir $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
VPATH = syzygy:nnue:nnue/features:eval:extra:learn
|
VPATH = syzygy:nnue:nnue/features:eval:extra:tools
|
||||||
|
|
||||||
### ==========================================================================
|
### ==========================================================================
|
||||||
### Section 2. High-level Configuration
|
### Section 2. High-level Configuration
|
||||||
|
|||||||
+6
-6
@@ -34,8 +34,8 @@
|
|||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
#include "syzygy/tbprobe.h"
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
#include "learn/packed_sfen.h"
|
#include "tools/packed_sfen.h"
|
||||||
#include "learn/sfen_packer.h"
|
#include "tools/sfen_packer.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
@@ -1373,13 +1373,13 @@ bool Position::pos_is_ok() const {
|
|||||||
// Add a function that directly unpacks for speed. It's pretty tough.
|
// Add a function that directly unpacks for speed. It's pretty tough.
|
||||||
// Write it by combining packer::unpack() and Position::set().
|
// Write it by combining packer::unpack() and Position::set().
|
||||||
// If there is a problem with the passed phase and there is an error, non-zero is returned.
|
// If there is a problem with the passed phase and there is an error, non-zero is returned.
|
||||||
int Position::set_from_packed_sfen(const Learner::PackedSfen& sfen , StateInfo* si, Thread* th)
|
int Position::set_from_packed_sfen(const Tools::PackedSfen& sfen , StateInfo* si, Thread* th)
|
||||||
{
|
{
|
||||||
return Learner::set_from_packed_sfen(*this, sfen, si, th);
|
return Tools::set_from_packed_sfen(*this, sfen, si, th);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the packed sfen. Returns to the buffer specified in the argument.
|
// Get the packed sfen. Returns to the buffer specified in the argument.
|
||||||
void Position::sfen_pack(Learner::PackedSfen& sfen)
|
void Position::sfen_pack(Tools::PackedSfen& sfen)
|
||||||
{
|
{
|
||||||
sfen = Learner::sfen_pack(*this);
|
sfen = Tools::sfen_pack(*this);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
#include "nnue/nnue_accumulator.h"
|
#include "nnue/nnue_accumulator.h"
|
||||||
|
|
||||||
#include "learn/packed_sfen.h"
|
#include "tools/packed_sfen.h"
|
||||||
#include "learn/sfen_packer.h"
|
#include "tools/sfen_packer.h"
|
||||||
|
|
||||||
|
|
||||||
/// StateInfo struct stores information needed to restore a Position object to
|
/// StateInfo struct stores information needed to restore a Position object to
|
||||||
@@ -179,17 +179,17 @@ public:
|
|||||||
|
|
||||||
// --sfenization helper
|
// --sfenization helper
|
||||||
|
|
||||||
friend int Learner::set_from_packed_sfen(Position& pos, const Learner::PackedSfen& sfen, StateInfo* si, Thread* th);
|
friend int Tools::set_from_packed_sfen(Position& pos, const Tools::PackedSfen& sfen, StateInfo* si, Thread* th);
|
||||||
|
|
||||||
// Get the packed sfen. Returns to the buffer specified in the argument.
|
// Get the packed sfen. Returns to the buffer specified in the argument.
|
||||||
// Do not include gamePly in pack.
|
// Do not include gamePly in pack.
|
||||||
void sfen_pack(Learner::PackedSfen& sfen);
|
void sfen_pack(Tools::PackedSfen& sfen);
|
||||||
|
|
||||||
// It is slow to go through sfen, so I made a function to set packed sfen directly.
|
// It is slow to go through sfen, so I made a function to set packed sfen directly.
|
||||||
// Equivalent to pos.set(sfen_unpack(data),si,th);.
|
// Equivalent to pos.set(sfen_unpack(data),si,th);.
|
||||||
// If there is a problem with the passed phase and there is an error, non-zero is returned.
|
// If there is a problem with the passed phase and there is an error, non-zero is returned.
|
||||||
// PackedSfen does not include gamePly so it cannot be restored. If you want to set it, specify it with an argument.
|
// PackedSfen does not include gamePly so it cannot be restored. If you want to set it, specify it with an argument.
|
||||||
int set_from_packed_sfen(const Learner::PackedSfen& sfen, StateInfo* si, Thread* th);
|
int set_from_packed_sfen(const Tools::PackedSfen& sfen, StateInfo* si, Thread* th);
|
||||||
|
|
||||||
void clear() { std::memset(this, 0, sizeof(Position)); }
|
void clear() { std::memset(this, 0, sizeof(Position)); }
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -311,7 +311,7 @@ void Thread::search() {
|
|||||||
|
|
||||||
if (!this->rootMoves.empty())
|
if (!this->rootMoves.empty())
|
||||||
Tablebases::rank_root_moves(this->rootPos, this->rootMoves);
|
Tablebases::rank_root_moves(this->rootPos, this->rootMoves);
|
||||||
|
|
||||||
if (mainThread)
|
if (mainThread)
|
||||||
{
|
{
|
||||||
if (mainThread->bestPreviousScore == VALUE_INFINITE)
|
if (mainThread->bestPreviousScore == VALUE_INFINITE)
|
||||||
@@ -1995,7 +1995,7 @@ namespace Search
|
|||||||
// It might have been good.
|
// It might have been good.
|
||||||
|
|
||||||
// Initialization for learning.
|
// Initialization for learning.
|
||||||
// Called from Learner::search(),Learner::qsearch().
|
// Called from Tools::search(),Tools::qsearch().
|
||||||
static bool init_for_search(Position& pos, Stack* ss)
|
static bool init_for_search(Position& pos, Stack* ss)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -110,7 +110,7 @@ extern LimitsType Limits;
|
|||||||
void init();
|
void init();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// A pair of reader and evaluation value. Returned by Learner::search(),Learner::qsearch().
|
// A pair of reader and evaluation value. Returned by Tools::search(),Tools::qsearch().
|
||||||
using ValueAndPV = std::pair<Value, std::vector<Move>>;
|
using ValueAndPV = std::pair<Value, std::vector<Move>>;
|
||||||
|
|
||||||
ValueAndPV qsearch(Position& pos);
|
ValueAndPV qsearch(Position& pos);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace Learner
|
namespace Tools
|
||||||
{
|
{
|
||||||
bool fen_is_ok(Position& pos, std::string input_fen) {
|
bool fen_is_ok(Position& pos, std::string input_fen) {
|
||||||
std::string pos_fen = pos.fen();
|
std::string pos_fen = pos.fen();
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
void convert(std::istringstream& is);
|
void convert(std::istringstream& is);
|
||||||
|
|
||||||
void convert_bin_from_pgn_extract(std::istringstream& is);
|
void convert_bin_from_pgn_extract(std::istringstream& is);
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace Learner
|
namespace Tools
|
||||||
{
|
{
|
||||||
// Class to generate sfen with multiple threads
|
// Class to generate sfen with multiple threads
|
||||||
struct Gensfen
|
struct Gensfen
|
||||||
@@ -220,7 +220,7 @@ namespace Learner
|
|||||||
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
||||||
limits.nodes = 0;
|
limits.nodes = 0;
|
||||||
|
|
||||||
// depth is also processed by the one passed as an argument of Learner::search().
|
// depth is also processed by the one passed as an argument of Tools::search().
|
||||||
limits.depth = 0;
|
limits.depth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
// Automatic generation of teacher position
|
// Automatic generation of teacher position
|
||||||
void gensfen(std::istringstream& is);
|
void gensfen(std::istringstream& is);
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace Learner
|
namespace Tools
|
||||||
{
|
{
|
||||||
// Class to generate sfen with multiple threads
|
// Class to generate sfen with multiple threads
|
||||||
struct GensfenNonPv
|
struct GensfenNonPv
|
||||||
@@ -163,7 +163,7 @@ namespace Learner
|
|||||||
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
||||||
limits.nodes = 0;
|
limits.nodes = 0;
|
||||||
|
|
||||||
// depth is also processed by the one passed as an argument of Learner::search().
|
// depth is also processed by the one passed as an argument of Tools::search().
|
||||||
limits.depth = 0;
|
limits.depth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
// Automatic generation of teacher position
|
// Automatic generation of teacher position
|
||||||
void gensfen_nonpv(std::istringstream& is);
|
void gensfen_nonpv(std::istringstream& is);
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
EpdOpeningBook::EpdOpeningBook(const std::string& file, PRNG& prng) :
|
EpdOpeningBook::EpdOpeningBook(const std::string& file, PRNG& prng) :
|
||||||
OpeningBook(file)
|
OpeningBook(file)
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
struct OpeningBook {
|
struct OpeningBook {
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
// packed sfen
|
// packed sfen
|
||||||
struct PackedSfen { std::uint8_t data[32]; };
|
struct PackedSfen { std::uint8_t data[32]; };
|
||||||
@@ -17,7 +17,7 @@ namespace Learner {
|
|||||||
// phase
|
// phase
|
||||||
PackedSfen sfen;
|
PackedSfen sfen;
|
||||||
|
|
||||||
// Evaluation value returned from Learner::search()
|
// Evaluation value returned from Tools::search()
|
||||||
std::int16_t score;
|
std::int16_t score;
|
||||||
|
|
||||||
// PV first move
|
// PV first move
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
// Class that handles bitstream
|
// Class that handles bitstream
|
||||||
// useful when doing aspect encoding
|
// useful when doing aspect encoding
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#include "learn/packed_sfen.h"
|
#include "packed_sfen.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ class Position;
|
|||||||
struct StateInfo;
|
struct StateInfo;
|
||||||
class Thread;
|
class Thread;
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
int set_from_packed_sfen(Position& pos, const PackedSfen& sfen, StateInfo* si, Thread* th);
|
int set_from_packed_sfen(Position& pos, const PackedSfen& sfen, StateInfo* si, Thread* th);
|
||||||
PackedSfen sfen_pack(Position& pos);
|
PackedSfen sfen_pack(Position& pos);
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace Learner{
|
namespace Tools{
|
||||||
|
|
||||||
enum struct SfenReaderMode
|
enum struct SfenReaderMode
|
||||||
{
|
{
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
enum struct SfenOutputType
|
enum struct SfenOutputType
|
||||||
{
|
{
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
// Helper class for exporting Sfen
|
// Helper class for exporting Sfen
|
||||||
struct SfenWriter
|
struct SfenWriter
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace Learner::Stats
|
namespace Tools::Stats
|
||||||
{
|
{
|
||||||
struct StatisticGathererBase
|
struct StatisticGathererBase
|
||||||
{
|
{
|
||||||
@@ -566,7 +566,7 @@ namespace Learner::Stats
|
|||||||
Position& pos = th->rootPos;
|
Position& pos = th->rootPos;
|
||||||
StateInfo si;
|
StateInfo si;
|
||||||
|
|
||||||
auto in = Learner::open_sfen_input_file(filename);
|
auto in = Tools::open_sfen_input_file(filename);
|
||||||
|
|
||||||
auto on_move = [&](const Position& position, const Move& move) {
|
auto on_move = [&](const Position& position, const Move& move) {
|
||||||
statistic_gatherers.on_move(position, move);
|
statistic_gatherers.on_move(position, move);
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace Learner::Stats {
|
namespace Tools::Stats {
|
||||||
|
|
||||||
void gather_statistics(std::istringstream& is);
|
void gather_statistics(std::istringstream& is);
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace Learner
|
namespace Tools
|
||||||
{
|
{
|
||||||
using CommandFunc = void(*)(std::istringstream&);
|
using CommandFunc = void(*)(std::istringstream&);
|
||||||
|
|
||||||
@@ -120,8 +120,8 @@ namespace Learner
|
|||||||
Position& pos = th->rootPos;
|
Position& pos = th->rootPos;
|
||||||
StateInfo si;
|
StateInfo si;
|
||||||
|
|
||||||
auto in = Learner::open_sfen_input_file(params.input_filename);
|
auto in = Tools::open_sfen_input_file(params.input_filename);
|
||||||
auto out = Learner::create_new_sfen_output(params.output_filename);
|
auto out = Tools::create_new_sfen_output(params.output_filename);
|
||||||
|
|
||||||
if (in == nullptr)
|
if (in == nullptr)
|
||||||
{
|
{
|
||||||
@@ -261,7 +261,7 @@ namespace Learner
|
|||||||
|
|
||||||
buffer.reserve(batch_size);
|
buffer.reserve(batch_size);
|
||||||
|
|
||||||
auto out = Learner::create_new_sfen_output(params.output_filename);
|
auto out = Tools::create_new_sfen_output(params.output_filename);
|
||||||
|
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
uint64_t num_processed = 0;
|
uint64_t num_processed = 0;
|
||||||
@@ -279,7 +279,7 @@ namespace Learner
|
|||||||
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
||||||
limits.nodes = 0;
|
limits.nodes = 0;
|
||||||
|
|
||||||
// depth is also processed by the one passed as an argument of Learner::search().
|
// depth is also processed by the one passed as an argument of Tools::search().
|
||||||
limits.depth = 0;
|
limits.depth = 0;
|
||||||
|
|
||||||
Threads.execute_with_workers([&](auto& th){
|
Threads.execute_with_workers([&](auto& th){
|
||||||
@@ -343,7 +343,7 @@ namespace Learner
|
|||||||
void do_rescore_data(RescoreParams& params)
|
void do_rescore_data(RescoreParams& params)
|
||||||
{
|
{
|
||||||
// TODO: Use SfenReader once it works correctly in sequential mode. See issue #271
|
// TODO: Use SfenReader once it works correctly in sequential mode. See issue #271
|
||||||
auto in = Learner::open_sfen_input_file(params.input_filename);
|
auto in = Tools::open_sfen_input_file(params.input_filename);
|
||||||
auto readsome = [&in, mutex = std::mutex{}](int n) mutable -> PSVector {
|
auto readsome = [&in, mutex = std::mutex{}](int n) mutable -> PSVector {
|
||||||
|
|
||||||
PSVector psv;
|
PSVector psv;
|
||||||
@@ -388,7 +388,7 @@ namespace Learner
|
|||||||
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
||||||
limits.nodes = 0;
|
limits.nodes = 0;
|
||||||
|
|
||||||
// depth is also processed by the one passed as an argument of Learner::search().
|
// depth is also processed by the one passed as an argument of Tools::search().
|
||||||
limits.depth = 0;
|
limits.depth = 0;
|
||||||
|
|
||||||
std::atomic<std::uint64_t> num_processed = 0;
|
std::atomic<std::uint64_t> num_processed = 0;
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace Learner {
|
namespace Tools {
|
||||||
|
|
||||||
void transform(std::istringstream& is);
|
void transform(std::istringstream& is);
|
||||||
|
|
||||||
+13
-13
@@ -33,11 +33,11 @@
|
|||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
|
||||||
#include "learn/gensfen.h"
|
#include "tools/gensfen.h"
|
||||||
#include "learn/gensfen_nonpv.h"
|
#include "tools/gensfen_nonpv.h"
|
||||||
#include "learn/convert.h"
|
#include "tools/convert.h"
|
||||||
#include "learn/transform.h"
|
#include "tools/transform.h"
|
||||||
#include "learn/stats.h"
|
#include "tools/stats.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -328,14 +328,14 @@ void UCI::loop(int argc, char* argv[]) {
|
|||||||
else if (token == "eval") trace_eval(pos);
|
else if (token == "eval") trace_eval(pos);
|
||||||
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
||||||
|
|
||||||
else if (token == "gensfen") Learner::gensfen(is);
|
else if (token == "gensfen") Tools::gensfen(is);
|
||||||
else if (token == "gensfen_nonpv") Learner::gensfen_nonpv(is);
|
else if (token == "gensfen_nonpv") Tools::gensfen_nonpv(is);
|
||||||
else if (token == "convert") Learner::convert(is);
|
else if (token == "convert") Tools::convert(is);
|
||||||
else if (token == "convert_bin") Learner::convert_bin(is);
|
else if (token == "convert_bin") Tools::convert_bin(is);
|
||||||
else if (token == "convert_plain") Learner::convert_plain(is);
|
else if (token == "convert_plain") Tools::convert_plain(is);
|
||||||
else if (token == "convert_bin_from_pgn_extract") Learner::convert_bin_from_pgn_extract(is);
|
else if (token == "convert_bin_from_pgn_extract") Tools::convert_bin_from_pgn_extract(is);
|
||||||
else if (token == "transform") Learner::transform(is);
|
else if (token == "transform") Tools::transform(is);
|
||||||
else if (token == "gather_statistics") Learner::Stats::gather_statistics(is);
|
else if (token == "gather_statistics") Tools::Stats::gather_statistics(is);
|
||||||
|
|
||||||
// Command to call qsearch(),search() directly for testing
|
// Command to call qsearch(),search() directly for testing
|
||||||
else if (token == "qsearch") qsearch_cmd(pos);
|
else if (token == "qsearch") qsearch_cmd(pos);
|
||||||
|
|||||||
Reference in New Issue
Block a user