mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 01:29:36 +00:00
test nnue test_features等の有効化
This commit is contained in:
parent
d23f96d156
commit
91a7557ab4
4 changed files with 40 additions and 14 deletions
|
@ -548,16 +548,16 @@ icc-profile-use:
|
||||||
all
|
all
|
||||||
|
|
||||||
nnue: config-sanity
|
nnue: config-sanity
|
||||||
$(MAKE) CXXFLAGS='$(CXXFLAGS) -DEVAL_NNUE -DUSE_EVAL_HASH -DUSE_AVX2 -DUSE_SSE2 -fopenmp' LDFLAGS='$(LDFLAGS) -fopenmp' build
|
$(MAKE) CXXFLAGS='$(CXXFLAGS) -DEVAL_NNUE -DUSE_EVAL_HASH -DUSE_AVX2 -DUSE_SSE2 -DENABLE_TEST_CMD -fopenmp' LDFLAGS='$(LDFLAGS) -fopenmp' build
|
||||||
|
|
||||||
nnue-gen-sfen-from-original-eval: config-sanity
|
nnue-gen-sfen-from-original-eval: config-sanity
|
||||||
$(MAKE) CXXFLAGS='$(CXXFLAGS) -DEVAL_LEARN -DUSE_EVAL_HASH -DUSE_AVX2 -DUSE_SSE2 -fopenmp' LDFLAGS='$(LDFLAGS) -fopenmp' build
|
$(MAKE) CXXFLAGS='$(CXXFLAGS) -DEVAL_LEARN -DUSE_EVAL_HASH -DUSE_AVX2 -DUSE_SSE2 -DENABLE_TEST_CMD -fopenmp' LDFLAGS='$(LDFLAGS) -fopenmp' build
|
||||||
|
|
||||||
nnue-learn: config-sanity
|
nnue-learn: config-sanity
|
||||||
$(MAKE) CXXFLAGS='$(CXXFLAGS) -DEVAL_LEARN -DEVAL_NNUE -DUSE_EVAL_HASH -DUSE_AVX2 -DUSE_SSE2 -fopenmp' LDFLAGS='$(LDFLAGS) -fopenmp' build
|
$(MAKE) CXXFLAGS='$(CXXFLAGS) -DEVAL_LEARN -DEVAL_NNUE -DUSE_EVAL_HASH -DUSE_AVX2 -DUSE_SSE2 -DENABLE_TEST_CMD -fopenmp' LDFLAGS='$(LDFLAGS) -fopenmp' build
|
||||||
|
|
||||||
nnue-learn-use-blas: config-sanity
|
nnue-learn-use-blas: config-sanity
|
||||||
$(MAKE) CXXFLAGS='$(CXXFLAGS) -DEVAL_LEARN -DEVAL_NNUE -DUSE_EVAL_HASH -DUSE_AVX2 -DUSE_SSE2 -DUSE_BLAS -I/mingw64/include/OpenBLAS -fopenmp' LDFLAGS='$(LDFLAGS) -lopenblas -fopenmp' build
|
$(MAKE) CXXFLAGS='$(CXXFLAGS) -DEVAL_LEARN -DEVAL_NNUE -DUSE_EVAL_HASH -DUSE_AVX2 -DUSE_SSE2 -DENABLE_TEST_CMD -DUSE_BLAS -I/mingw64/include/OpenBLAS -fopenmp' LDFLAGS='$(LDFLAGS) -lopenblas -fopenmp' build
|
||||||
|
|
||||||
.depend:
|
.depend:
|
||||||
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
|
||||||
|
|
|
@ -2,11 +2,16 @@
|
||||||
|
|
||||||
#if defined(ENABLE_TEST_CMD) && defined(EVAL_NNUE)
|
#if defined(ENABLE_TEST_CMD) && defined(EVAL_NNUE)
|
||||||
|
|
||||||
#include "../../extra/all.h"
|
#include "../../thread.h"
|
||||||
|
#include "../../uci.h"
|
||||||
#include "evaluate_nnue.h"
|
#include "evaluate_nnue.h"
|
||||||
#include "nnue_test_command.h"
|
#include "nnue_test_command.h"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#define ASSERT(X) { if (!(X)) { std::cout << "\nError : ASSERT(" << #X << "), " << __FILE__ << "(" << __LINE__ << "): " << __func__ << std::endl; \
|
||||||
|
std::this_thread::sleep_for(std::chrono::microseconds(3000)); *(int*)1 =0;} }
|
||||||
|
|
||||||
namespace Eval {
|
namespace Eval {
|
||||||
|
|
||||||
|
@ -18,7 +23,7 @@ namespace {
|
||||||
void TestFeatures(Position& pos) {
|
void TestFeatures(Position& pos) {
|
||||||
const std::uint64_t num_games = 1000;
|
const std::uint64_t num_games = 1000;
|
||||||
StateInfo si;
|
StateInfo si;
|
||||||
pos.set_hirate(&si,Threads.main());
|
pos.set(StartFEN, false, &si, Threads.main());
|
||||||
const int MAX_PLY = 256; // 256手までテスト
|
const int MAX_PLY = 256; // 256手までテスト
|
||||||
|
|
||||||
StateInfo state[MAX_PLY]; // StateInfoを最大手数分だけ
|
StateInfo state[MAX_PLY]; // StateInfoを最大手数分だけ
|
||||||
|
@ -38,7 +43,7 @@ void TestFeatures(Position& pos) {
|
||||||
Features::IndexList active_indices[2];
|
Features::IndexList active_indices[2];
|
||||||
RawFeatures::AppendActiveIndices(pos, kRefreshTriggers[i],
|
RawFeatures::AppendActiveIndices(pos, kRefreshTriggers[i],
|
||||||
active_indices);
|
active_indices);
|
||||||
for (const auto perspective : COLOR) {
|
for (const auto perspective : Colors) {
|
||||||
for (const auto index : active_indices[perspective]) {
|
for (const auto index : active_indices[perspective]) {
|
||||||
ASSERT(index < RawFeatures::kDimensions);
|
ASSERT(index < RawFeatures::kDimensions);
|
||||||
ASSERT(index_sets[i][perspective].count(index) == 0);
|
ASSERT(index_sets[i][perspective].count(index) == 0);
|
||||||
|
@ -56,7 +61,7 @@ void TestFeatures(Position& pos) {
|
||||||
bool reset[2];
|
bool reset[2];
|
||||||
RawFeatures::AppendChangedIndices(pos, kRefreshTriggers[i],
|
RawFeatures::AppendChangedIndices(pos, kRefreshTriggers[i],
|
||||||
removed_indices, added_indices, reset);
|
removed_indices, added_indices, reset);
|
||||||
for (const auto perspective : COLOR) {
|
for (const auto perspective : Colors) {
|
||||||
if (reset[perspective]) {
|
if (reset[perspective]) {
|
||||||
(*index_sets)[i][perspective].clear();
|
(*index_sets)[i][perspective].clear();
|
||||||
++num_resets[i];
|
++num_resets[i];
|
||||||
|
@ -91,7 +96,7 @@ void TestFeatures(Position& pos) {
|
||||||
for (std::uint64_t i = 0; i < num_games; ++i) {
|
for (std::uint64_t i = 0; i < num_games; ++i) {
|
||||||
auto index_sets = make_index_sets(pos);
|
auto index_sets = make_index_sets(pos);
|
||||||
for (ply = 0; ply < MAX_PLY; ++ply) {
|
for (ply = 0; ply < MAX_PLY; ++ply) {
|
||||||
MoveList<LEGAL_ALL> mg(pos); // 全合法手の生成
|
MoveList<LEGAL> mg(pos); // 全合法手の生成
|
||||||
|
|
||||||
// 合法な指し手がなかった == 詰み
|
// 合法な指し手がなかった == 詰み
|
||||||
if (mg.size() == 0)
|
if (mg.size() == 0)
|
||||||
|
@ -106,7 +111,7 @@ void TestFeatures(Position& pos) {
|
||||||
ASSERT(index_sets == make_index_sets(pos));
|
ASSERT(index_sets == make_index_sets(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
pos.set_hirate(&si,Threads.main());
|
pos.set(StartFEN, false, &si, Threads.main());
|
||||||
|
|
||||||
// 100回に1回ごとに'.'を出力(進んでいることがわかるように)
|
// 100回に1回ごとに'.'を出力(進んでいることがわかるように)
|
||||||
if ((i % 100) == 0)
|
if ((i % 100) == 0)
|
||||||
|
@ -184,8 +189,8 @@ void TestCommand(Position& pos, std::istream& stream) {
|
||||||
PrintInfo(stream);
|
PrintInfo(stream);
|
||||||
} else {
|
} else {
|
||||||
std::cout << "usage:" << std::endl;
|
std::cout << "usage:" << std::endl;
|
||||||
std::cout << " test nn test_features" << std::endl;
|
std::cout << " test nnue test_features" << std::endl;
|
||||||
std::cout << " test nn info [path/to/" << kFileName << "...]" << std::endl;
|
std::cout << " test nnue info [path/to/" << kFileName << "...]" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
#ifndef _NNUE_TEST_COMMAND_H_
|
#ifndef _NNUE_TEST_COMMAND_H_
|
||||||
#define _NNUE_TEST_COMMAND_H_
|
#define _NNUE_TEST_COMMAND_H_
|
||||||
|
|
||||||
#include "../../config.h"
|
|
||||||
|
|
||||||
#if defined(ENABLE_TEST_CMD) && defined(EVAL_NNUE)
|
#if defined(ENABLE_TEST_CMD) && defined(EVAL_NNUE)
|
||||||
|
|
||||||
namespace Eval {
|
namespace Eval {
|
||||||
|
|
23
src/uci.cpp
23
src/uci.cpp
|
@ -33,6 +33,10 @@
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
#include "syzygy/tbprobe.h"
|
#include "syzygy/tbprobe.h"
|
||||||
|
|
||||||
|
#if defined(EVAL_NNUE) && defined(ENABLE_TEST_CMD)
|
||||||
|
#include "eval/nnue/nnue_test_command.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
extern vector<string> setup_bench(const Position&, istream&);
|
extern vector<string> setup_bench(const Position&, istream&);
|
||||||
|
@ -64,6 +68,19 @@ namespace Learner
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(EVAL_NNUE) && defined(ENABLE_TEST_CMD)
|
||||||
|
void test_cmd(Position& pos, istringstream& is)
|
||||||
|
{
|
||||||
|
// 探索をするかも知れないので初期化しておく。
|
||||||
|
is_ready();
|
||||||
|
|
||||||
|
std::string param;
|
||||||
|
is >> param;
|
||||||
|
|
||||||
|
if (param == "nnue") Eval::NNUE::TestCommand(pos, is);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// position() is called when engine receives the "position" UCI command.
|
// position() is called when engine receives the "position" UCI command.
|
||||||
// The function sets up the position described in the given FEN string ("fen")
|
// The function sets up the position described in the given FEN string ("fen")
|
||||||
|
@ -376,6 +393,12 @@ void UCI::loop(int argc, char* argv[]) {
|
||||||
else if (token == "search") search_cmd(pos, is);
|
else if (token == "search") search_cmd(pos, is);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(EVAL_NNUE) && defined(ENABLE_TEST_CMD)
|
||||||
|
// テストコマンド
|
||||||
|
else if (token == "test") test_cmd(pos, is);
|
||||||
|
#endif
|
||||||
|
|
||||||
else
|
else
|
||||||
sync_cout << "Unknown command: " << cmd << sync_endl;
|
sync_cout << "Unknown command: " << cmd << sync_endl;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue