Skip to content

Commit

Permalink
Optimize update_accumulator_refresh_cache()
Browse files Browse the repository at this point in the history
STC https://tests.stockfishchess.org/tests/view/664105df26ac5f9b286d30e6
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 178528 W: 46235 L: 45750 D: 86543
Ptnml(0-2): 505, 17792, 52142, 18363, 462

Combo of two yellow speedups
https://tests.stockfishchess.org/tests/view/6640abf9d163897c63214f5c
LLR: -2.93 (-2.94,2.94) <0.00,2.00>
Total: 355744 W: 91714 L: 91470 D: 172560
Ptnml(0-2): 913, 36233, 103384, 36381, 961

https://tests.stockfishchess.org/tests/view/6628ce073fe04ce4cefc739c
LLR: -2.93 (-2.94,2.94) <0.00,2.00>
Total: 627040 W: 162001 L: 161339 D: 303700
Ptnml(0-2): 2268, 72379, 163532, 73105, 2236

closes #5239

No functional change
  • Loading branch information
mstembera authored and vondele committed May 13, 2024
1 parent 0b08953 commit e608eab
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/nnue/nnue_feature_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,11 @@ class FeatureTransformer {

for (IndexType j = 0; j < HalfDimensions / TileHeight; ++j)
{
auto entryTile = reinterpret_cast<vec_t*>(&entry.accumulation[j * TileHeight]);
auto accTile =
reinterpret_cast<vec_t*>(&accumulator.accumulation[Perspective][j * TileHeight]);
auto entryTile =
reinterpret_cast<vec_t*>(&entry.accumulation[j * TileHeight]);

for (IndexType k = 0; k < NumRegs; ++k)
acc[k] = entryTile[k];

Expand All @@ -679,7 +683,7 @@ class FeatureTransformer {
auto columnA = reinterpret_cast<const vec_t*>(&weights[offsetA]);

for (unsigned k = 0; k < NumRegs; ++k)
acc[k] = vec_add_16(vec_sub_16(acc[k], columnR[k]), columnA[k]);
acc[k] = vec_add_16(acc[k], vec_sub_16(columnA[k], columnR[k]));
}
for (; i < int(removed.size()); ++i)
{
Expand All @@ -702,12 +706,17 @@ class FeatureTransformer {

for (IndexType k = 0; k < NumRegs; k++)
vec_store(&entryTile[k], acc[k]);
for (IndexType k = 0; k < NumRegs; k++)
vec_store(&accTile[k], acc[k]);
}

for (IndexType j = 0; j < PSQTBuckets / PsqtTileHeight; ++j)
{
auto entryTilePsqt =
reinterpret_cast<psqt_vec_t*>(&entry.psqtAccumulation[j * PsqtTileHeight]);
auto accTilePsqt = reinterpret_cast<psqt_vec_t*>(
&accumulator.psqtAccumulation[Perspective][j * PsqtTileHeight]);
auto entryTilePsqt = reinterpret_cast<psqt_vec_t*>(
&entry.psqtAccumulation[j * PsqtTileHeight]);

for (std::size_t k = 0; k < NumPsqtRegs; ++k)
psqt[k] = entryTilePsqt[k];

Expand All @@ -732,6 +741,8 @@ class FeatureTransformer {

for (std::size_t k = 0; k < NumPsqtRegs; ++k)
vec_store_psqt(&entryTilePsqt[k], psqt[k]);
for (std::size_t k = 0; k < NumPsqtRegs; ++k)
vec_store_psqt(&accTilePsqt[k], psqt[k]);
}

#else
Expand All @@ -755,8 +766,6 @@ class FeatureTransformer {
entry.psqtAccumulation[k] += psqtWeights[index * PSQTBuckets + k];
}

#endif

// The accumulator of the refresh entry has been updated.
// Now copy its content to the actual accumulator we were refreshing

Expand All @@ -765,6 +774,7 @@ class FeatureTransformer {

std::memcpy(accumulator.psqtAccumulation[Perspective], entry.psqtAccumulation,
sizeof(int32_t) * PSQTBuckets);
#endif

for (Color c : {WHITE, BLACK})
entry.byColorBB[c] = pos.pieces(c);
Expand Down

0 comments on commit e608eab

Please sign in to comment.