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