1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

test nnue test_features等の有効化

This commit is contained in:
tttak 2020-06-08 13:57:55 +09:00 committed by nodchip
parent d23f96d156
commit 91a7557ab4
4 changed files with 40 additions and 14 deletions

View file

@ -548,16 +548,16 @@ icc-profile-use:
all
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
$(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
$(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
$(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:
-@$(CXX) $(DEPENDFLAGS) -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null

View file

@ -2,11 +2,16 @@
#if defined(ENABLE_TEST_CMD) && defined(EVAL_NNUE)
#include "../../extra/all.h"
#include "../../thread.h"
#include "../../uci.h"
#include "evaluate_nnue.h"
#include "nnue_test_command.h"
#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 {
@ -18,7 +23,7 @@ namespace {
void TestFeatures(Position& pos) {
const std::uint64_t num_games = 1000;
StateInfo si;
pos.set_hirate(&si,Threads.main());
pos.set(StartFEN, false, &si, Threads.main());
const int MAX_PLY = 256; // 256手までテスト
StateInfo state[MAX_PLY]; // StateInfoを最大手数分だけ
@ -38,7 +43,7 @@ void TestFeatures(Position& pos) {
Features::IndexList active_indices[2];
RawFeatures::AppendActiveIndices(pos, kRefreshTriggers[i],
active_indices);
for (const auto perspective : COLOR) {
for (const auto perspective : Colors) {
for (const auto index : active_indices[perspective]) {
ASSERT(index < RawFeatures::kDimensions);
ASSERT(index_sets[i][perspective].count(index) == 0);
@ -56,7 +61,7 @@ void TestFeatures(Position& pos) {
bool reset[2];
RawFeatures::AppendChangedIndices(pos, kRefreshTriggers[i],
removed_indices, added_indices, reset);
for (const auto perspective : COLOR) {
for (const auto perspective : Colors) {
if (reset[perspective]) {
(*index_sets)[i][perspective].clear();
++num_resets[i];
@ -91,7 +96,7 @@ void TestFeatures(Position& pos) {
for (std::uint64_t i = 0; i < num_games; ++i) {
auto index_sets = make_index_sets(pos);
for (ply = 0; ply < MAX_PLY; ++ply) {
MoveList<LEGAL_ALL> mg(pos); // 全合法手の生成
MoveList<LEGAL> mg(pos); // 全合法手の生成
// 合法な指し手がなかった == 詰み
if (mg.size() == 0)
@ -106,7 +111,7 @@ void TestFeatures(Position& pos) {
ASSERT(index_sets == make_index_sets(pos));
}
pos.set_hirate(&si,Threads.main());
pos.set(StartFEN, false, &si, Threads.main());
// 100回に1回ごとに'.'を出力(進んでいることがわかるように)
if ((i % 100) == 0)
@ -184,8 +189,8 @@ void TestCommand(Position& pos, std::istream& stream) {
PrintInfo(stream);
} else {
std::cout << "usage:" << std::endl;
std::cout << " test nn test_features" << std::endl;
std::cout << " test nn info [path/to/" << kFileName << "...]" << std::endl;
std::cout << " test nnue test_features" << std::endl;
std::cout << " test nnue info [path/to/" << kFileName << "...]" << std::endl;
}
}

View file

@ -3,8 +3,6 @@
#ifndef _NNUE_TEST_COMMAND_H_
#define _NNUE_TEST_COMMAND_H_
#include "../../config.h"
#if defined(ENABLE_TEST_CMD) && defined(EVAL_NNUE)
namespace Eval {

View file

@ -33,6 +33,10 @@
#include "uci.h"
#include "syzygy/tbprobe.h"
#if defined(EVAL_NNUE) && defined(ENABLE_TEST_CMD)
#include "eval/nnue/nnue_test_command.h"
#endif
using namespace std;
extern vector<string> setup_bench(const Position&, istream&);
@ -64,6 +68,19 @@ namespace Learner
}
#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 {
// position() is called when engine receives the "position" UCI command.
// 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);
#endif
#if defined(EVAL_NNUE) && defined(ENABLE_TEST_CMD)
// テストコマンド
else if (token == "test") test_cmd(pos, is);
#endif
else
sync_cout << "Unknown command: " << cmd << sync_endl;