some minor changes to NNUE interference | bench 1136338
This commit is contained in:
1 parent
d73ed3b98d
commit
0a8d7ca2f5
5 files changed
+46
-42
No files matched your search
+18
-18
@@ -23,11 +23,11 @@ void AccumulatorPair::addSub(bool stm, int add, int addPT, int sub, int subPT) {
|
|||||||
int subB = CalculateIndex(Black, stm, subPT, sub);
|
int subB = CalculateIndex(Black, stm, subPT, sub);
|
||||||
|
|
||||||
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
||||||
white.values[i] += NNUE::net.accumulator_weights[addW * NNUE::HL_SIZE + i];
|
white[i] += NNUE::net.accumulator_weights[addW * NNUE::HL_SIZE + i];
|
||||||
black.values[i] += NNUE::net.accumulator_weights[addB * NNUE::HL_SIZE + i];
|
black[i] += NNUE::net.accumulator_weights[addB * NNUE::HL_SIZE + i];
|
||||||
|
|
||||||
white.values[i] -= NNUE::net.accumulator_weights[subW * NNUE::HL_SIZE + i];
|
white[i] -= NNUE::net.accumulator_weights[subW * NNUE::HL_SIZE + i];
|
||||||
black.values[i] -= NNUE::net.accumulator_weights[subB * NNUE::HL_SIZE + i];
|
black[i] -= NNUE::net.accumulator_weights[subB * NNUE::HL_SIZE + i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,14 +43,14 @@ void AccumulatorPair::addSubSub(bool stm, int add, int addPT, int sub1, int subP
|
|||||||
int subB2 = CalculateIndex(Black, !stm, subPT2, sub2);
|
int subB2 = CalculateIndex(Black, !stm, subPT2, sub2);
|
||||||
|
|
||||||
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
||||||
white.values[i] += NNUE::net.accumulator_weights[addW * NNUE::HL_SIZE + i];
|
white[i] += NNUE::net.accumulator_weights[addW * NNUE::HL_SIZE + i];
|
||||||
black.values[i] += NNUE::net.accumulator_weights[addB * NNUE::HL_SIZE + i];
|
black[i] += NNUE::net.accumulator_weights[addB * NNUE::HL_SIZE + i];
|
||||||
|
|
||||||
white.values[i] -= NNUE::net.accumulator_weights[subW1 * NNUE::HL_SIZE + i];
|
white[i] -= NNUE::net.accumulator_weights[subW1 * NNUE::HL_SIZE + i];
|
||||||
black.values[i] -= NNUE::net.accumulator_weights[subB1 * NNUE::HL_SIZE + i];
|
black[i] -= NNUE::net.accumulator_weights[subB1 * NNUE::HL_SIZE + i];
|
||||||
|
|
||||||
white.values[i] -= NNUE::net.accumulator_weights[subW2 * NNUE::HL_SIZE + i];
|
white[i] -= NNUE::net.accumulator_weights[subW2 * NNUE::HL_SIZE + i];
|
||||||
black.values[i] -= NNUE::net.accumulator_weights[subB2 * NNUE::HL_SIZE + i];
|
black[i] -= NNUE::net.accumulator_weights[subB2 * NNUE::HL_SIZE + i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,17 +69,17 @@ void AccumulatorPair::addAddSubSub(bool stm, int add1, int addPT1, int add2, int
|
|||||||
int subB2 = CalculateIndex(Black, stm, subPT2, sub2);
|
int subB2 = CalculateIndex(Black, stm, subPT2, sub2);
|
||||||
|
|
||||||
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
||||||
white.values[i] += NNUE::net.accumulator_weights[addW1 * NNUE::HL_SIZE + i];
|
white[i] += NNUE::net.accumulator_weights[addW1 * NNUE::HL_SIZE + i];
|
||||||
black.values[i] += NNUE::net.accumulator_weights[addB1 * NNUE::HL_SIZE + i];
|
black[i] += NNUE::net.accumulator_weights[addB1 * NNUE::HL_SIZE + i];
|
||||||
|
|
||||||
white.values[i] += NNUE::net.accumulator_weights[addW2 * NNUE::HL_SIZE + i];
|
white[i] += NNUE::net.accumulator_weights[addW2 * NNUE::HL_SIZE + i];
|
||||||
black.values[i] += NNUE::net.accumulator_weights[addB2 * NNUE::HL_SIZE + i];
|
black[i] += NNUE::net.accumulator_weights[addB2 * NNUE::HL_SIZE + i];
|
||||||
|
|
||||||
white.values[i] -= NNUE::net.accumulator_weights[subW1 * NNUE::HL_SIZE + i];
|
white[i] -= NNUE::net.accumulator_weights[subW1 * NNUE::HL_SIZE + i];
|
||||||
black.values[i] -= NNUE::net.accumulator_weights[subB1 * NNUE::HL_SIZE + i];
|
black[i] -= NNUE::net.accumulator_weights[subB1 * NNUE::HL_SIZE + i];
|
||||||
|
|
||||||
white.values[i] -= NNUE::net.accumulator_weights[subW2 * NNUE::HL_SIZE + i];
|
white[i] -= NNUE::net.accumulator_weights[subW2 * NNUE::HL_SIZE + i];
|
||||||
black.values[i] -= NNUE::net.accumulator_weights[subB2 * NNUE::HL_SIZE + i];
|
black[i] -= NNUE::net.accumulator_weights[subB2 * NNUE::HL_SIZE + i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
namespace ACC {
|
namespace ACC {
|
||||||
|
|
||||||
struct Accumulator {
|
using Accumulator = std::array<int16_t, NNUE::HL_SIZE>;
|
||||||
alignas(32) std::array<int16_t, NNUE::HL_SIZE> values;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AccumulatorPair {
|
struct AccumulatorPair {
|
||||||
alignas(32) Accumulator white;
|
alignas(32) Accumulator white;
|
||||||
|
|||||||
+8
-8
@@ -231,8 +231,8 @@ void Board::PrintNNUE() {
|
|||||||
std::cout << "First 16 accumulator values (pre-activation)[white] ";
|
std::cout << "First 16 accumulator values (pre-activation)[white] ";
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (accPair.white.values[i] != 0) {
|
if (accPair.white[i] != 0) {
|
||||||
std::cout << accPair.white.values[i] << ' ';
|
std::cout << accPair.white[i] << ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,8 +491,8 @@ void Board::ResetAccPair() {
|
|||||||
Bitboard whitePieces = colors[White];
|
Bitboard whitePieces = colors[White];
|
||||||
Bitboard blackPieces = colors[Black];
|
Bitboard blackPieces = colors[Black];
|
||||||
|
|
||||||
accPair.white.values = NNUE::net.accumulator_biases;
|
accPair.white = NNUE::net.accumulator_biases;
|
||||||
accPair.black.values = NNUE::net.accumulator_biases;
|
accPair.black = NNUE::net.accumulator_biases;
|
||||||
|
|
||||||
while (whitePieces) {
|
while (whitePieces) {
|
||||||
int square = whitePieces.getLS1BIndex();
|
int square = whitePieces.getLS1BIndex();
|
||||||
@@ -501,8 +501,8 @@ void Board::ResetAccPair() {
|
|||||||
int bInput = ACC::CalculateIndex(Black, White, GetPieceType(square), square);
|
int bInput = ACC::CalculateIndex(Black, White, GetPieceType(square), square);
|
||||||
|
|
||||||
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
||||||
accPair.white.values[i] += NNUE::net.accumulator_weights[wInput * NNUE::HL_SIZE + i];
|
accPair.white[i] += NNUE::net.accumulator_weights[wInput * NNUE::HL_SIZE + i];
|
||||||
accPair.black.values[i] += NNUE::net.accumulator_weights[bInput * NNUE::HL_SIZE + i];
|
accPair.black[i] += NNUE::net.accumulator_weights[bInput * NNUE::HL_SIZE + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
whitePieces.PopBit(square);
|
whitePieces.PopBit(square);
|
||||||
@@ -515,8 +515,8 @@ void Board::ResetAccPair() {
|
|||||||
int bInput = ACC::CalculateIndex(Black, Black, GetPieceType(square), square);
|
int bInput = ACC::CalculateIndex(Black, Black, GetPieceType(square), square);
|
||||||
|
|
||||||
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
for (int i = 0; i < NNUE::HL_SIZE; i++) {
|
||||||
accPair.white.values[i] += NNUE::net.accumulator_weights[wInput * NNUE::HL_SIZE + i];
|
accPair.white[i] += NNUE::net.accumulator_weights[wInput * NNUE::HL_SIZE + i];
|
||||||
accPair.black.values[i] += NNUE::net.accumulator_weights[bInput * NNUE::HL_SIZE + i];
|
accPair.black[i] += NNUE::net.accumulator_weights[bInput * NNUE::HL_SIZE + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
blackPieces.PopBit(square);
|
blackPieces.PopBit(square);
|
||||||
|
|||||||
+5
-5
@@ -16,17 +16,17 @@ void Network::Load(const std::string& path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HL weights
|
// HL weights
|
||||||
for (int i = 0; i < accumulator_weights.size(); i++) {
|
for (size_t i = 0; i < accumulator_weights.size(); i++) {
|
||||||
file.read(reinterpret_cast<char*>(&accumulator_weights[i]), sizeof(int16_t));
|
file.read(reinterpret_cast<char*>(&accumulator_weights[i]), sizeof(int16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
// HL biases
|
// HL biases
|
||||||
for (int i = 0; i < accumulator_biases.size(); i++) {
|
for (size_t i = 0; i < accumulator_biases.size(); i++) {
|
||||||
file.read(reinterpret_cast<char*>(&accumulator_biases[i]), sizeof(int16_t));
|
file.read(reinterpret_cast<char*>(&accumulator_biases[i]), sizeof(int16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output weights
|
// Output weights
|
||||||
for (int i = 0; i < output_weights.size(); i++) {
|
for (size_t i = 0; i < output_weights.size(); i++) {
|
||||||
file.read(reinterpret_cast<char*>(&output_weights[i]), sizeof(int16_t));
|
file.read(reinterpret_cast<char*>(&output_weights[i]), sizeof(int16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +103,8 @@ static int32_t VectorizedSCReLU(const Board& board, const Network& net) {
|
|||||||
|
|
||||||
for (int i = 0; i < HL_SIZE; i += VECTOR_SIZE) {
|
for (int i = 0; i < HL_SIZE; i += VECTOR_SIZE) {
|
||||||
// Load accumulators
|
// Load accumulators
|
||||||
const nativeVector stmAccumValues = load_epi16(reinterpret_cast<const nativeVector*>(&stmAcc.values[i]));
|
const nativeVector stmAccumValues = load_epi16(reinterpret_cast<const nativeVector*>(&stmAcc[i]));
|
||||||
const nativeVector nstmAccumValues = load_epi16(reinterpret_cast<const nativeVector*>(&nstmAcc.values[i]));
|
const nativeVector nstmAccumValues = load_epi16(reinterpret_cast<const nativeVector*>(&nstmAcc[i]));
|
||||||
|
|
||||||
// Clamp values
|
// Clamp values
|
||||||
const nativeVector stmClamped = min_epi16(VEC_QA, max_epi16(stmAccumValues, VEC_ZERO));
|
const nativeVector stmClamped = min_epi16(VEC_QA, max_epi16(stmAccumValues, VEC_ZERO));
|
||||||
|
|||||||
+14
-8
@@ -7,19 +7,25 @@
|
|||||||
|
|
||||||
class Board;
|
class Board;
|
||||||
|
|
||||||
|
#ifdef __AVX512F__
|
||||||
|
constexpr usize ALIGNMENT = 64;
|
||||||
|
#else
|
||||||
|
constexpr size_t ALIGNMENT = 32;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace NNUE {
|
namespace NNUE {
|
||||||
|
|
||||||
constexpr int INPUT_SIZE = 768;
|
constexpr size_t INPUT_SIZE = 768;
|
||||||
constexpr int HL_SIZE = 128;
|
constexpr size_t HL_SIZE = 128;
|
||||||
|
|
||||||
constexpr int SCALE = 400;
|
constexpr int16_t SCALE = 400;
|
||||||
constexpr int QA = 255;
|
constexpr int16_t QA = 255;
|
||||||
constexpr int QB = 64;
|
constexpr int16_t QB = 64;
|
||||||
|
|
||||||
struct Network {
|
struct Network {
|
||||||
alignas(32) std::array<int16_t, HL_SIZE * INPUT_SIZE> accumulator_weights;
|
alignas(ALIGNMENT) std::array<int16_t, HL_SIZE * INPUT_SIZE> accumulator_weights;
|
||||||
alignas(32) std::array<int16_t, HL_SIZE> accumulator_biases;
|
alignas(ALIGNMENT) std::array<int16_t, HL_SIZE> accumulator_biases;
|
||||||
alignas(32) std::array<int16_t, 2 * HL_SIZE> output_weights;
|
alignas(ALIGNMENT) std::array<int16_t, 2 * HL_SIZE> output_weights;
|
||||||
int16_t output_bias;
|
int16_t output_bias;
|
||||||
|
|
||||||
void Load(const std::string& path);
|
void Load(const std::string& path);
|
||||||
|
|||||||
Reference in new issue
Block a user