mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 19:46:55 +08:00
Fixed compile errors.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
// NNUE評価関数の計算に関するコード
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "../../evaluate.h"
|
||||
#include "../../position.h"
|
||||
#include "../../misc.h"
|
||||
#include "../../uci.h"
|
||||
|
||||
#include "evaluate_nnue.h"
|
||||
|
||||
@@ -263,7 +265,7 @@ Value compute_eval(const Position& pos) {
|
||||
}
|
||||
|
||||
// 評価関数
|
||||
Value evaluate(const Position& pos) {
|
||||
Value NNUE::evaluate(const Position& pos) {
|
||||
const auto& accumulator = pos.state()->accumulator;
|
||||
if (accumulator.computed_score) {
|
||||
return accumulator.score;
|
||||
|
||||
@@ -55,6 +55,8 @@ bool ReadParameters(std::istream& stream);
|
||||
// 評価関数パラメータを書き込む
|
||||
bool WriteParameters(std::ostream& stream);
|
||||
|
||||
Value evaluate(const Position& pos);
|
||||
|
||||
} // namespace NNUE
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
@@ -71,7 +71,7 @@ class FeatureSetBase {
|
||||
template <typename IndexListType>
|
||||
static void AppendActiveIndices(
|
||||
const Position& pos, TriggerEvent trigger, IndexListType active[2]) {
|
||||
for (const auto perspective : COLOR) {
|
||||
for (const auto perspective : Colors) {
|
||||
Derived::CollectActiveIndices(
|
||||
pos, trigger, perspective, &active[perspective]);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class FeatureSetBase {
|
||||
const auto& dp = pos.state()->dirtyPiece;
|
||||
if (dp.dirty_num == 0) return;
|
||||
|
||||
for (const auto perspective : COLOR) {
|
||||
for (const auto perspective : Colors) {
|
||||
reset[perspective] = false;
|
||||
switch (trigger) {
|
||||
case TriggerEvent::kNone:
|
||||
@@ -105,7 +105,7 @@ class FeatureSetBase {
|
||||
reset[perspective] = true;
|
||||
break;
|
||||
default:
|
||||
ASSERT_LV5(false);
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
if (reset[perspective]) {
|
||||
|
||||
@@ -28,7 +28,7 @@ inline void HalfKP<AssociatedKing>::GetPieces(
|
||||
const PieceNumber target = (AssociatedKing == Side::kFriend) ?
|
||||
static_cast<PieceNumber>(PIECE_NUMBER_KING + perspective) :
|
||||
static_cast<PieceNumber>(PIECE_NUMBER_KING + ~perspective);
|
||||
*sq_target_k = static_cast<Square>(((*pieces)[target] - f_king) % SQ_NB);
|
||||
*sq_target_k = static_cast<Square>(((*pieces)[target] - f_king) % SQUARE_NB);
|
||||
}
|
||||
|
||||
// 特徴量のうち、値が1であるインデックスのリストを取得する
|
||||
|
||||
@@ -26,7 +26,7 @@ class HalfKP {
|
||||
0x5D69D5B9u ^ (AssociatedKing == Side::kFriend);
|
||||
// 特徴量の次元数
|
||||
static constexpr IndexType kDimensions =
|
||||
static_cast<IndexType>(SQ_NB) * static_cast<IndexType>(fe_end);
|
||||
static_cast<IndexType>(SQUARE_NB) * static_cast<IndexType>(fe_end);
|
||||
// 特徴量のうち、同時に値が1となるインデックスの数の最大値
|
||||
static constexpr IndexType kMaxActiveDimensions = PIECE_NUMBER_KING;
|
||||
// 差分計算の代わりに全計算を行うタイミング
|
||||
|
||||
@@ -17,8 +17,8 @@ inline IndexType HalfRelativeKP<AssociatedKing>::MakeIndex(
|
||||
Square sq_k, BonaPiece p) {
|
||||
constexpr IndexType W = kBoardWidth;
|
||||
constexpr IndexType H = kBoardHeight;
|
||||
const IndexType piece_index = (p - fe_hand_end) / SQ_NB;
|
||||
const Square sq_p = static_cast<Square>((p - fe_hand_end) % SQ_NB);
|
||||
const IndexType piece_index = (p - fe_hand_end) / SQUARE_NB;
|
||||
const Square sq_p = static_cast<Square>((p - fe_hand_end) % SQUARE_NB);
|
||||
const IndexType relative_file = file_of(sq_p) - file_of(sq_k) + (W / 2);
|
||||
const IndexType relative_rank = rank_of(sq_p) - rank_of(sq_k) + (H / 2);
|
||||
return H * W * piece_index + H * relative_file + relative_rank;
|
||||
@@ -35,7 +35,7 @@ inline void HalfRelativeKP<AssociatedKing>::GetPieces(
|
||||
const PieceNumber target = (AssociatedKing == Side::kFriend) ?
|
||||
static_cast<PieceNumber>(PIECE_NUMBER_KING + perspective) :
|
||||
static_cast<PieceNumber>(PIECE_NUMBER_KING + ~perspective);
|
||||
*sq_target_k = static_cast<Square>(((*pieces)[target] - f_king) % SQ_NB);
|
||||
*sq_target_k = static_cast<Square>(((*pieces)[target] - f_king) % SQUARE_NB);
|
||||
}
|
||||
|
||||
// 特徴量のうち、値が1であるインデックスのリストを取得する
|
||||
|
||||
@@ -25,7 +25,7 @@ class HalfRelativeKP {
|
||||
static constexpr std::uint32_t kHashValue =
|
||||
0xF9180919u ^ (AssociatedKing == Side::kFriend);
|
||||
// 玉を除いた駒種
|
||||
static constexpr IndexType kNumPieceKinds = (fe_end - fe_hand_end) / SQ_NB;
|
||||
static constexpr IndexType kNumPieceKinds = (fe_end - fe_hand_end) / SQUARE_NB;
|
||||
// 玉を中央に置いた仮想的な盤の幅
|
||||
static constexpr IndexType kBoardWidth = FILE_NB * 2 - 1;
|
||||
// 玉を中央に置いた仮想的な盤の高さ
|
||||
|
||||
@@ -20,8 +20,8 @@ void K::AppendActiveIndices(
|
||||
const BonaPiece* pieces = (perspective == BLACK) ?
|
||||
pos.eval_list()->piece_list_fb() :
|
||||
pos.eval_list()->piece_list_fw();
|
||||
ASSERT_LV5(pieces[PIECE_NUMBER_BKING] != BONA_PIECE_ZERO);
|
||||
ASSERT_LV5(pieces[PIECE_NUMBER_WKING] != BONA_PIECE_ZERO);
|
||||
assert(pieces[PIECE_NUMBER_BKING] != BONA_PIECE_ZERO);
|
||||
assert(pieces[PIECE_NUMBER_WKING] != BONA_PIECE_ZERO);
|
||||
for (PieceNumber i = PIECE_NUMBER_KING; i < PIECE_NUMBER_NB; ++i) {
|
||||
active->push_back(pieces[i] - fe_end);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class K {
|
||||
// 評価関数ファイルに埋め込むハッシュ値
|
||||
static constexpr std::uint32_t kHashValue = 0xD3CEE169u;
|
||||
// 特徴量の次元数
|
||||
static constexpr IndexType kDimensions = SQ_NB * 2;
|
||||
static constexpr IndexType kDimensions = SQUARE_NB * 2;
|
||||
// 特徴量のうち、同時に値が1となるインデックスの数の最大値
|
||||
static constexpr IndexType kMaxActiveDimensions = 2;
|
||||
// 差分計算の代わりに全計算を行うタイミング
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#ifndef _NNUE_ACCUMULATOR_H_
|
||||
#define _NNUE_ACCUMULATOR_H_
|
||||
|
||||
#include "../../config.h"
|
||||
|
||||
#if defined(EVAL_NNUE)
|
||||
|
||||
#include "nnue_architecture.h"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
// 入力特徴量とネットワーク構造が定義されたヘッダをincludeする
|
||||
|
||||
// KP256型を使いたいときは、これを事前にdefineする。
|
||||
#define EVAL_NNUE_KP256
|
||||
#if defined(EVAL_NNUE_KP256)
|
||||
#include "architectures/k-p_256x2-32-32.h"
|
||||
#else // #if defined(EVAL_NNUE_HALFKP256)
|
||||
|
||||
@@ -142,9 +142,9 @@ class FeatureTransformer {
|
||||
}
|
||||
#else
|
||||
for (IndexType j = 0; j < kHalfDimensions; ++j) {
|
||||
BiasType sum = accumulation[perspectives[p]][0][j];
|
||||
BiasType sum = accumulation[static_cast<int>(perspectives[p])][0][j];
|
||||
for (IndexType i = 1; i < kRefreshTriggers.size(); ++i) {
|
||||
sum += accumulation[perspectives[p]][i][j];
|
||||
sum += accumulation[static_cast<int>(perspectives[p])][i][j];
|
||||
}
|
||||
output[offset + j] = static_cast<OutputType>(
|
||||
std::max<int>(0, std::min<int>(127, sum)));
|
||||
@@ -161,7 +161,7 @@ class FeatureTransformer {
|
||||
Features::IndexList active_indices[2];
|
||||
RawFeatures::AppendActiveIndices(pos, kRefreshTriggers[i],
|
||||
active_indices);
|
||||
for (const auto perspective : COLOR) {
|
||||
for (const auto perspective : Colors) {
|
||||
if (i == 0) {
|
||||
std::memcpy(accumulator.accumulation[perspective][i], biases_,
|
||||
kHalfDimensions * sizeof(BiasType));
|
||||
@@ -217,7 +217,7 @@ class FeatureTransformer {
|
||||
bool reset[2];
|
||||
RawFeatures::AppendChangedIndices(pos, kRefreshTriggers[i],
|
||||
removed_indices, added_indices, reset);
|
||||
for (const auto perspective : COLOR) {
|
||||
for (const auto perspective : Colors) {
|
||||
#if defined(USE_AVX2)
|
||||
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
|
||||
auto accumulation = reinterpret_cast<__m256i*>(
|
||||
|
||||
@@ -43,7 +43,7 @@ class Factorizer<HalfKP<AssociatedKing>> {
|
||||
// kFeaturesHalfKP
|
||||
{true, FeatureType::kDimensions},
|
||||
// kFeaturesHalfK
|
||||
{true, SQ_NB},
|
||||
{true, SQUARE_NB},
|
||||
// kFeaturesP
|
||||
{true, Factorizer<P>::GetDimensions()},
|
||||
// kFeaturesHalfRelativeKP
|
||||
|
||||
Reference in New Issue
Block a user