mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
コンパイルエラーを修正した
This commit is contained in:
parent
5c936572e9
commit
33772a0418
4 changed files with 29 additions and 28 deletions
|
@ -35,7 +35,7 @@ namespace {
|
||||||
std::vector<Example> examples;
|
std::vector<Example> examples;
|
||||||
|
|
||||||
// examplesの排他制御をするMutex
|
// examplesの排他制御をするMutex
|
||||||
Mutex examples_mutex;
|
std::mutex examples_mutex;
|
||||||
|
|
||||||
// ミニバッチのサンプル数
|
// ミニバッチのサンプル数
|
||||||
uint64_t batch_size;
|
uint64_t batch_size;
|
||||||
|
@ -158,7 +158,7 @@ void AddExample(Position& pos, Color rootColor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<Mutex> lock(examples_mutex);
|
std::lock_guard<std::mutex> lock(examples_mutex);
|
||||||
examples.push_back(std::move(example));
|
examples.push_back(std::move(example));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ void UpdateParameters(uint64_t epoch) {
|
||||||
const auto learning_rate = static_cast<LearnFloatType>(
|
const auto learning_rate = static_cast<LearnFloatType>(
|
||||||
get_eta() / batch_size);
|
get_eta() / batch_size);
|
||||||
|
|
||||||
std::lock_guard<Mutex> lock(examples_mutex);
|
std::lock_guard<std::mutex> lock(examples_mutex);
|
||||||
std::shuffle(examples.begin(), examples.end(), rng);
|
std::shuffle(examples.begin(), examples.end(), rng);
|
||||||
while (examples.size() >= batch_size) {
|
while (examples.size() >= batch_size) {
|
||||||
std::vector<Example> batch(examples.end() - batch_size, examples.end());
|
std::vector<Example> batch(examples.end() - batch_size, examples.end());
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#if defined(EVAL_LEARN)
|
#if defined(EVAL_LEARN)
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include "learn.h"
|
#include "learn.h"
|
||||||
|
@ -170,7 +171,7 @@ struct SfenWriter
|
||||||
// sfen_buffers_poolに積んでおけばあとはworkerがよきに計らってくれる。
|
// sfen_buffers_poolに積んでおけばあとはworkerがよきに計らってくれる。
|
||||||
|
|
||||||
// sfen_buffers_poolの内容を変更するときはmutexのlockが必要。
|
// sfen_buffers_poolの内容を変更するときはmutexのlockが必要。
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
sfen_buffers_pool.push_back(buf);
|
sfen_buffers_pool.push_back(buf);
|
||||||
|
|
||||||
buf = nullptr;
|
buf = nullptr;
|
||||||
|
@ -181,7 +182,7 @@ struct SfenWriter
|
||||||
// 自分のスレッド用のバッファに残っている分をファイルに書き出すためのバッファに移動させる。
|
// 自分のスレッド用のバッファに残っている分をファイルに書き出すためのバッファに移動させる。
|
||||||
void finalize(size_t thread_id)
|
void finalize(size_t thread_id)
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
|
|
||||||
auto& buf = sfen_buffers[thread_id];
|
auto& buf = sfen_buffers[thread_id];
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ struct SfenWriter
|
||||||
{
|
{
|
||||||
vector<PSVector*> buffers;
|
vector<PSVector*> buffers;
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
|
|
||||||
// まるごとコピー
|
// まるごとコピー
|
||||||
buffers = sfen_buffers_pool;
|
buffers = sfen_buffers_pool;
|
||||||
|
@ -299,7 +300,7 @@ private:
|
||||||
std::vector<PSVector*> sfen_buffers_pool;
|
std::vector<PSVector*> sfen_buffers_pool;
|
||||||
|
|
||||||
// sfen_buffers_poolにアクセスするときに必要なmutex
|
// sfen_buffers_poolにアクセスするときに必要なmutex
|
||||||
Mutex mutex;
|
std::mutex mutex;
|
||||||
|
|
||||||
// 書きだした局面の数
|
// 書きだした局面の数
|
||||||
uint64_t sfen_write_count = 0;
|
uint64_t sfen_write_count = 0;
|
||||||
|
@ -1293,7 +1294,7 @@ struct SfenReader
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
// ファイルバッファから充填できたなら、それで良し。
|
// ファイルバッファから充填できたなら、それで良し。
|
||||||
if (packed_sfens_pool.size() != 0)
|
if (packed_sfens_pool.size() != 0)
|
||||||
{
|
{
|
||||||
|
@ -1410,7 +1411,7 @@ struct SfenReader
|
||||||
|
|
||||||
// sfensの用意が出来たので、折を見てコピー
|
// sfensの用意が出来たので、折を見てコピー
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
|
|
||||||
// ポインタをコピーするだけなのでこの時間は無視できるはず…。
|
// ポインタをコピーするだけなのでこの時間は無視できるはず…。
|
||||||
// packed_sfens_poolの内容を変更するのでmutexのlockが必要。
|
// packed_sfens_poolの内容を変更するのでmutexのlockが必要。
|
||||||
|
@ -1479,7 +1480,7 @@ protected:
|
||||||
std::vector<PSVector*> packed_sfens;
|
std::vector<PSVector*> packed_sfens;
|
||||||
|
|
||||||
// packed_sfens_poolにアクセスするときのmutex
|
// packed_sfens_poolにアクセスするときのmutex
|
||||||
Mutex mutex;
|
std::mutex mutex;
|
||||||
|
|
||||||
// sfenのpool。fileから読み込むworker threadはここに補充する。
|
// sfenのpool。fileから読み込むworker threadはここに補充する。
|
||||||
// 各worker threadはここから自分のpacked_sfens[thread_id]に充填する。
|
// 各worker threadはここから自分のpacked_sfens[thread_id]に充填する。
|
||||||
|
@ -2704,7 +2705,7 @@ void learn(Position&, istringstream& is)
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4996)
|
#pragma warning(disable:4996)
|
||||||
|
|
||||||
namespace sys = std::tr2::sys;
|
namespace sys = std::filesystem;
|
||||||
sys::path p(kif_base_dir); // 列挙の起点
|
sys::path p(kif_base_dir); // 列挙の起点
|
||||||
std::for_each(sys::directory_iterator(p), sys::directory_iterator(),
|
std::for_each(sys::directory_iterator(p), sys::directory_iterator(),
|
||||||
[&](const sys::path& p) {
|
[&](const sys::path& p) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ struct MultiThink
|
||||||
// 局面を生成する場合などは、局面を生成するタイミングでこの関数を呼び出すようにしないと、
|
// 局面を生成する場合などは、局面を生成するタイミングでこの関数を呼び出すようにしないと、
|
||||||
// 生成した局面数と、カウンターの値が一致しなくなってしまうので注意すること。
|
// 生成した局面数と、カウンターの値が一致しなくなってしまうので注意すること。
|
||||||
uint64_t get_next_loop_count() {
|
uint64_t get_next_loop_count() {
|
||||||
std::unique_lock<Mutex> lk(loop_mutex);
|
std::unique_lock<std::mutex> lk(loop_mutex);
|
||||||
if (loop_count >= loop_max)
|
if (loop_count >= loop_max)
|
||||||
return UINT64_MAX;
|
return UINT64_MAX;
|
||||||
return loop_count++;
|
return loop_count++;
|
||||||
|
@ -67,12 +67,12 @@ struct MultiThink
|
||||||
|
|
||||||
// [ASYNC] 処理した個数を返す用。呼び出されるごとにインクリメントされたカウンターが返る。
|
// [ASYNC] 処理した個数を返す用。呼び出されるごとにインクリメントされたカウンターが返る。
|
||||||
uint64_t get_done_count() {
|
uint64_t get_done_count() {
|
||||||
std::unique_lock<Mutex> lk(loop_mutex);
|
std::unique_lock<std::mutex> lk(loop_mutex);
|
||||||
return ++done_count;
|
return ++done_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// worker threadがI/Oにアクセスするときのmutex
|
// worker threadがI/Oにアクセスするときのmutex
|
||||||
Mutex io_mutex;
|
std::mutex io_mutex;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// 乱数発生器本体
|
// 乱数発生器本体
|
||||||
|
@ -87,7 +87,7 @@ private:
|
||||||
std::atomic<uint64_t> done_count;
|
std::atomic<uint64_t> done_count;
|
||||||
|
|
||||||
// ↑の変数を変更するときのmutex
|
// ↑の変数を変更するときのmutex
|
||||||
Mutex loop_mutex;
|
std::mutex loop_mutex;
|
||||||
|
|
||||||
// スレッドの終了フラグ。
|
// スレッドの終了フラグ。
|
||||||
// vector<bool>にすると複数スレッドから書き換えようとしたときに正しく反映されないことがある…はず。
|
// vector<bool>にすると複数スレッドから書き換えようとしたときに正しく反映されないことがある…はず。
|
||||||
|
@ -117,7 +117,7 @@ struct TaskDispatcher
|
||||||
// [ASYNC] taskを一つ積む。
|
// [ASYNC] taskを一つ積む。
|
||||||
void push_task_async(Task task)
|
void push_task_async(Task task)
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(task_mutex);
|
std::unique_lock<std::mutex> lk(task_mutex);
|
||||||
tasks.push_back(task);
|
tasks.push_back(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ protected:
|
||||||
// [ASYNC] taskを一つ取り出す。on_idle()から呼び出される。
|
// [ASYNC] taskを一つ取り出す。on_idle()から呼び出される。
|
||||||
Task get_task_async()
|
Task get_task_async()
|
||||||
{
|
{
|
||||||
std::unique_lock<Mutex> lk(task_mutex);
|
std::unique_lock<std::mutex> lk(task_mutex);
|
||||||
if (tasks.size() == 0)
|
if (tasks.size() == 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
Task task = *tasks.rbegin();
|
Task task = *tasks.rbegin();
|
||||||
|
@ -143,7 +143,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
// tasksにアクセスするとき用のmutex
|
// tasksにアクセスするとき用のmutex
|
||||||
Mutex task_mutex;
|
std::mutex task_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // defined(EVAL_LEARN) && defined(YANEURAOU_2018_OTAFUKU_ENGINE)
|
#endif // defined(EVAL_LEARN) && defined(YANEURAOU_2018_OTAFUKU_ENGINE)
|
||||||
|
|
|
@ -2024,9 +2024,9 @@ namespace Learner
|
||||||
{
|
{
|
||||||
auto th = pos.this_thread();
|
auto th = pos.this_thread();
|
||||||
|
|
||||||
th->completedDepth = DEPTH_ZERO;
|
th->completedDepth = 0;
|
||||||
th->selDepth = 0;
|
th->selDepth = 0;
|
||||||
th->rootDepth = DEPTH_ZERO;
|
th->rootDepth = 0;
|
||||||
|
|
||||||
// 探索ノード数のゼロ初期化
|
// 探索ノード数のゼロ初期化
|
||||||
th->nodes = 0;
|
th->nodes = 0;
|
||||||
|
@ -2050,7 +2050,7 @@ namespace Learner
|
||||||
: -make_score(ct, ct / 2));
|
: -make_score(ct, ct / 2));
|
||||||
|
|
||||||
for (int i = 7; i > 0; i--)
|
for (int i = 7; i > 0; i--)
|
||||||
(ss - i)->continuationHistory = &th->continuationHistory[NO_PIECE][0]; // Use as sentinel
|
(ss - i)->continuationHistory = &th->continuationHistory[0][0][NO_PIECE][0]; // Use as a sentinel
|
||||||
|
|
||||||
// rootMovesの設定
|
// rootMovesの設定
|
||||||
auto& rootMoves = th->rootMoves;
|
auto& rootMoves = th->rootMoves;
|
||||||
|
@ -2109,7 +2109,7 @@ namespace Learner
|
||||||
return { mated_in(/*ss->ply*/ 0 + 1), {} };
|
return { mated_in(/*ss->ply*/ 0 + 1), {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
auto bestValue = ::qsearch<PV>(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, DEPTH_ZERO);
|
auto bestValue = ::qsearch<PV>(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, 0);
|
||||||
|
|
||||||
// 得られたPVを返す。
|
// 得られたPVを返す。
|
||||||
std::vector<Move> pvs;
|
std::vector<Move> pvs;
|
||||||
|
@ -2139,11 +2139,11 @@ namespace Learner
|
||||||
{
|
{
|
||||||
std::vector<Move> pvs;
|
std::vector<Move> pvs;
|
||||||
|
|
||||||
Depth depth = depth_ * ONE_PLY;
|
Depth depth = depth_;
|
||||||
if (depth < DEPTH_ZERO)
|
if (depth < 0)
|
||||||
return std::pair<Value, std::vector<Move>>(Eval::evaluate(pos), std::vector<Move>());
|
return std::pair<Value, std::vector<Move>>(Eval::evaluate(pos), std::vector<Move>());
|
||||||
|
|
||||||
if (depth == DEPTH_ZERO)
|
if (depth == 0)
|
||||||
return qsearch(pos);
|
return qsearch(pos);
|
||||||
|
|
||||||
Stack stack[MAX_PLY + 10], * ss = stack + 7;
|
Stack stack[MAX_PLY + 10], * ss = stack + 7;
|
||||||
|
@ -2176,7 +2176,7 @@ namespace Learner
|
||||||
Value delta = -VALUE_INFINITE;
|
Value delta = -VALUE_INFINITE;
|
||||||
Value bestValue = -VALUE_INFINITE;
|
Value bestValue = -VALUE_INFINITE;
|
||||||
|
|
||||||
while ((rootDepth += ONE_PLY) <= depth
|
while ((rootDepth += 1) <= depth
|
||||||
// node制限を超えた場合もこのループを抜ける
|
// node制限を超えた場合もこのループを抜ける
|
||||||
// 探索ノード数は、この関数の引数で渡されている。
|
// 探索ノード数は、この関数の引数で渡されている。
|
||||||
&& !(nodesLimit /*node制限あり*/ && th->nodes.load(std::memory_order_relaxed) >= nodesLimit)
|
&& !(nodesLimit /*node制限あり*/ && th->nodes.load(std::memory_order_relaxed) >= nodesLimit)
|
||||||
|
@ -2203,7 +2203,7 @@ namespace Learner
|
||||||
selDepth = 0;
|
selDepth = 0;
|
||||||
|
|
||||||
// depth 5以上においてはaspiration searchに切り替える。
|
// depth 5以上においてはaspiration searchに切り替える。
|
||||||
if (rootDepth >= 5 * ONE_PLY)
|
if (rootDepth >= 5 * 1)
|
||||||
{
|
{
|
||||||
delta = Value(20);
|
delta = Value(20);
|
||||||
|
|
||||||
|
@ -2217,7 +2217,7 @@ namespace Learner
|
||||||
int failedHighCnt = 0;
|
int failedHighCnt = 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Depth adjustedDepth = std::max(ONE_PLY, rootDepth - failedHighCnt * ONE_PLY);
|
Depth adjustedDepth = std::max(1, rootDepth - failedHighCnt * 1);
|
||||||
bestValue = ::search<PV>(pos, ss, alpha, beta, adjustedDepth, false);
|
bestValue = ::search<PV>(pos, ss, alpha, beta, adjustedDepth, false);
|
||||||
|
|
||||||
stable_sort(rootMoves.begin() + pvIdx, rootMoves.end());
|
stable_sort(rootMoves.begin() + pvIdx, rootMoves.end());
|
||||||
|
|
Loading…
Add table
Reference in a new issue