Skip to content

Commit

Permalink
AVX-512でクラッシュする問題を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
KazApps committed Sep 13, 2024
1 parent 2266fb6 commit f35ef20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/eval/nnue/nnue_accumulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace NNUE {

// 入力特徴量をアフィン変換した結果を保持するクラス
// 最終的な出力である評価値も一緒に持たせておく
struct alignas(32) Accumulator {
// AVX-512命令を使用する場合に64bytesのアライメントが要求される。
struct alignas(64) Accumulator {
std::int16_t
accumulation[2][kRefreshTriggers.size()][kTransformedFeatureDimensions];
Value score = VALUE_ZERO;
Expand Down
8 changes: 8 additions & 0 deletions source/eval/nnue/nnue_feature_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ class FeatureTransformer {
const IndexType offset = kHalfDimensions * index;
auto accumulation = reinterpret_cast<vec_t*>(&accumulator.accumulation[perspective][i][0]);
auto column = reinterpret_cast<const vec_t*>(&weights_[offset]);
#if defined(USE_AVX512)
constexpr IndexType kNumChunks = kHalfDimensions / kSimdWidth;
#else
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
#endif
for (IndexType j = 0; j < kNumChunks; ++j) {
accumulation[j] = vec_add_16(accumulation[j], column[j]);
}
Expand Down Expand Up @@ -327,7 +331,11 @@ class FeatureTransformer {
RawFeatures::AppendChangedIndices(pos, kRefreshTriggers[i], removed_indices, added_indices, reset);
for (Color perspective : {BLACK, WHITE}) {
#if defined(VECTOR)
#if defined(USE_AVX512)
constexpr IndexType kNumChunks = kHalfDimensions / kSimdWidth;
#else
constexpr IndexType kNumChunks = kHalfDimensions / (kSimdWidth / 2);
#endif
auto accumulation = reinterpret_cast<vec_t*>(&accumulator.accumulation[perspective][i][0]);
#endif
if (reset[perspective]) {
Expand Down

0 comments on commit f35ef20

Please sign in to comment.