]> git.sesse.net Git - stockfish/blob - src/nnue/nnue_feature_transformer.h
10b226b31130d802155ef34a273807b28470bd34
[stockfish] / src / nnue / nnue_feature_transformer.h
1 /*
2   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3   Copyright (C) 2004-2021 The Stockfish developers (see AUTHORS file)
4
5   Stockfish is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9
10   Stockfish is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // A class that converts the input features of the NNUE evaluation function
20
21 #ifndef NNUE_FEATURE_TRANSFORMER_H_INCLUDED
22 #define NNUE_FEATURE_TRANSFORMER_H_INCLUDED
23
24 #include "nnue_common.h"
25 #include "nnue_architecture.h"
26
27 #include "../misc.h"
28
29 #include <cstring> // std::memset()
30
31 namespace Stockfish::Eval::NNUE {
32
33   // If vector instructions are enabled, we update and refresh the
34   // accumulator tile by tile such that each tile fits in the CPU's
35   // vector registers.
36   #define VECTOR
37
38   static_assert(PSQTBuckets == 8, "Assumed by the current choice of constants.");
39
40   #ifdef USE_AVX512
41   typedef __m512i vec_t;
42   typedef __m256i psqt_vec_t;
43   #define vec_load(a) _mm512_load_si512(a)
44   #define vec_store(a,b) _mm512_store_si512(a,b)
45   #define vec_add_16(a,b) _mm512_add_epi16(a,b)
46   #define vec_sub_16(a,b) _mm512_sub_epi16(a,b)
47   #define vec_load_psqt(a) _mm256_load_si256(a)
48   #define vec_store_psqt(a,b) _mm256_store_si256(a,b)
49   #define vec_add_psqt_32(a,b) _mm256_add_epi32(a,b)
50   #define vec_sub_psqt_32(a,b) _mm256_sub_epi32(a,b)
51   #define vec_zero_psqt() _mm256_setzero_si256()
52   static constexpr IndexType NumRegs = 8; // only 8 are needed
53   static constexpr IndexType NumPsqtRegs = 1;
54
55   #elif USE_AVX2
56   typedef __m256i vec_t;
57   typedef __m256i psqt_vec_t;
58   #define vec_load(a) _mm256_load_si256(a)
59   #define vec_store(a,b) _mm256_store_si256(a,b)
60   #define vec_add_16(a,b) _mm256_add_epi16(a,b)
61   #define vec_sub_16(a,b) _mm256_sub_epi16(a,b)
62   #define vec_load_psqt(a) _mm256_load_si256(a)
63   #define vec_store_psqt(a,b) _mm256_store_si256(a,b)
64   #define vec_add_psqt_32(a,b) _mm256_add_epi32(a,b)
65   #define vec_sub_psqt_32(a,b) _mm256_sub_epi32(a,b)
66   #define vec_zero_psqt() _mm256_setzero_si256()
67   static constexpr IndexType NumRegs = 16;
68   static constexpr IndexType NumPsqtRegs = 1;
69
70   #elif USE_SSE2
71   typedef __m128i vec_t;
72   typedef __m128i psqt_vec_t;
73   #define vec_load(a) (*(a))
74   #define vec_store(a,b) *(a)=(b)
75   #define vec_add_16(a,b) _mm_add_epi16(a,b)
76   #define vec_sub_16(a,b) _mm_sub_epi16(a,b)
77   #define vec_load_psqt(a) (*(a))
78   #define vec_store_psqt(a,b) *(a)=(b)
79   #define vec_add_psqt_32(a,b) _mm_add_epi32(a,b)
80   #define vec_sub_psqt_32(a,b) _mm_sub_epi32(a,b)
81   #define vec_zero_psqt() _mm_setzero_si128()
82   static constexpr IndexType NumRegs = Is64Bit ? 16 : 8;
83   static constexpr IndexType NumPsqtRegs = 2;
84
85   #elif USE_MMX
86   typedef __m64 vec_t;
87   typedef __m64 psqt_vec_t;
88   #define vec_load(a) (*(a))
89   #define vec_store(a,b) *(a)=(b)
90   #define vec_add_16(a,b) _mm_add_pi16(a,b)
91   #define vec_sub_16(a,b) _mm_sub_pi16(a,b)
92   #define vec_load_psqt(a) (*(a))
93   #define vec_store_psqt(a,b) *(a)=(b)
94   #define vec_add_psqt_32(a,b) _mm_add_pi32(a,b)
95   #define vec_sub_psqt_32(a,b) _mm_sub_pi32(a,b)
96   #define vec_zero_psqt() _mm_setzero_si64()
97   static constexpr IndexType NumRegs = 8;
98   static constexpr IndexType NumPsqtRegs = 4;
99
100   #elif USE_NEON
101   typedef int16x8_t vec_t;
102   typedef int32x4_t psqt_vec_t;
103   #define vec_load(a) (*(a))
104   #define vec_store(a,b) *(a)=(b)
105   #define vec_add_16(a,b) vaddq_s16(a,b)
106   #define vec_sub_16(a,b) vsubq_s16(a,b)
107   #define vec_load_psqt(a) (*(a))
108   #define vec_store_psqt(a,b) *(a)=(b)
109   #define vec_add_psqt_32(a,b) vaddq_s32(a,b)
110   #define vec_sub_psqt_32(a,b) vsubq_s32(a,b)
111   #define vec_zero_psqt() psqt_vec_t{0}
112   static constexpr IndexType NumRegs = 16;
113   static constexpr IndexType NumPsqtRegs = 2;
114
115   #else
116   #undef VECTOR
117
118   #endif
119
120   // Input feature converter
121   class FeatureTransformer {
122
123    private:
124     // Number of output dimensions for one side
125     static constexpr IndexType HalfDimensions = TransformedFeatureDimensions;
126
127     #ifdef VECTOR
128     static constexpr IndexType TileHeight = NumRegs * sizeof(vec_t) / 2;
129     static constexpr IndexType PsqtTileHeight = NumPsqtRegs * sizeof(psqt_vec_t) / 4;
130     static_assert(HalfDimensions % TileHeight == 0, "TileHeight must divide HalfDimensions");
131     static_assert(PSQTBuckets % PsqtTileHeight == 0, "PsqtTileHeight must divide PSQTBuckets");
132     #endif
133
134    public:
135     // Output type
136     using OutputType = TransformedFeatureType;
137
138     // Number of input/output dimensions
139     static constexpr IndexType InputDimensions = FeatureSet::Dimensions;
140     static constexpr IndexType OutputDimensions = HalfDimensions * 2;
141
142     // Size of forward propagation buffer
143     static constexpr std::size_t BufferSize =
144         OutputDimensions * sizeof(OutputType);
145
146     // Hash value embedded in the evaluation file
147     static constexpr std::uint32_t get_hash_value() {
148       return FeatureSet::HashValue ^ OutputDimensions;
149     }
150
151     // Read network parameters
152     bool read_parameters(std::istream& stream) {
153       for (std::size_t i = 0; i < HalfDimensions; ++i)
154         biases[i] = read_little_endian<BiasType>(stream);
155       for (std::size_t i = 0; i < HalfDimensions * InputDimensions; ++i)
156         weights[i] = read_little_endian<WeightType>(stream);
157       for (std::size_t i = 0; i < PSQTBuckets * InputDimensions; ++i)
158         psqtWeights[i] = read_little_endian<PSQTWeightType>(stream);
159       return !stream.fail();
160     }
161
162     // Write network parameters
163     bool write_parameters(std::ostream& stream) const {
164       for (std::size_t i = 0; i < HalfDimensions; ++i)
165         write_little_endian<BiasType>(stream, biases[i]);
166       for (std::size_t i = 0; i < HalfDimensions * InputDimensions; ++i)
167         write_little_endian<WeightType>(stream, weights[i]);
168       for (std::size_t i = 0; i < PSQTBuckets * InputDimensions; ++i)
169         write_little_endian<PSQTWeightType>(stream, psqtWeights[i]);
170       return !stream.fail();
171     }
172
173     // Convert input features
174     std::int32_t transform(const Position& pos, OutputType* output, int bucket) const {
175       update_accumulator(pos, WHITE);
176       update_accumulator(pos, BLACK);
177
178       const Color perspectives[2] = {pos.side_to_move(), ~pos.side_to_move()};
179       const auto& accumulation = pos.state()->accumulator.accumulation;
180       const auto& psqtAccumulation = pos.state()->accumulator.psqtAccumulation;
181
182       const auto psqt = (
183             psqtAccumulation[perspectives[0]][bucket]
184           - psqtAccumulation[perspectives[1]][bucket]
185         ) / 2;
186
187
188   #if defined(USE_AVX512)
189
190       constexpr IndexType NumChunks = HalfDimensions / (SimdWidth * 2);
191       static_assert(HalfDimensions % (SimdWidth * 2) == 0);
192       const __m512i Control = _mm512_setr_epi64(0, 2, 4, 6, 1, 3, 5, 7);
193       const __m512i Zero = _mm512_setzero_si512();
194
195       for (IndexType p = 0; p < 2; ++p)
196       {
197           const IndexType offset = HalfDimensions * p;
198           auto out = reinterpret_cast<__m512i*>(&output[offset]);
199           for (IndexType j = 0; j < NumChunks; ++j)
200           {
201               __m512i sum0 = _mm512_load_si512(&reinterpret_cast<const __m512i*>
202                                               (accumulation[perspectives[p]])[j * 2 + 0]);
203               __m512i sum1 = _mm512_load_si512(&reinterpret_cast<const __m512i*>
204                                               (accumulation[perspectives[p]])[j * 2 + 1]);
205
206               _mm512_store_si512(&out[j], _mm512_permutexvar_epi64(Control,
207                                  _mm512_max_epi8(_mm512_packs_epi16(sum0, sum1), Zero)));
208           }
209       }
210       return psqt;
211
212   #elif defined(USE_AVX2)
213
214       constexpr IndexType NumChunks = HalfDimensions / SimdWidth;
215       constexpr int Control = 0b11011000;
216       const __m256i Zero = _mm256_setzero_si256();
217
218       for (IndexType p = 0; p < 2; ++p)
219       {
220           const IndexType offset = HalfDimensions * p;
221           auto out = reinterpret_cast<__m256i*>(&output[offset]);
222           for (IndexType j = 0; j < NumChunks; ++j)
223           {
224               __m256i sum0 = _mm256_load_si256(&reinterpret_cast<const __m256i*>
225                                               (accumulation[perspectives[p]])[j * 2 + 0]);
226               __m256i sum1 = _mm256_load_si256(&reinterpret_cast<const __m256i*>
227                                               (accumulation[perspectives[p]])[j * 2 + 1]);
228
229               _mm256_store_si256(&out[j], _mm256_permute4x64_epi64(
230                                  _mm256_max_epi8(_mm256_packs_epi16(sum0, sum1), Zero), Control));
231           }
232       }
233       return psqt;
234
235   #elif defined(USE_SSE2)
236
237       #ifdef USE_SSE41
238       constexpr IndexType NumChunks = HalfDimensions / SimdWidth;
239       const __m128i Zero = _mm_setzero_si128();
240       #else
241       constexpr IndexType NumChunks = HalfDimensions / SimdWidth;
242       const __m128i k0x80s = _mm_set1_epi8(-128);
243       #endif
244
245       for (IndexType p = 0; p < 2; ++p)
246       {
247           const IndexType offset = HalfDimensions * p;
248           auto out = reinterpret_cast<__m128i*>(&output[offset]);
249           for (IndexType j = 0; j < NumChunks; ++j)
250           {
251               __m128i sum0 = _mm_load_si128(&reinterpret_cast<const __m128i*>
252                                            (accumulation[perspectives[p]])[j * 2 + 0]);
253               __m128i sum1 = _mm_load_si128(&reinterpret_cast<const __m128i*>
254                                            (accumulation[perspectives[p]])[j * 2 + 1]);
255               const __m128i packedbytes = _mm_packs_epi16(sum0, sum1);
256
257               #ifdef USE_SSE41
258               _mm_store_si128(&out[j], _mm_max_epi8(packedbytes, Zero));
259               #else
260               _mm_store_si128(&out[j], _mm_subs_epi8(_mm_adds_epi8(packedbytes, k0x80s), k0x80s));
261               #endif
262           }
263       }
264       return psqt;
265
266   #elif defined(USE_MMX)
267
268       constexpr IndexType NumChunks = HalfDimensions / SimdWidth;
269       const __m64 k0x80s = _mm_set1_pi8(-128);
270
271       for (IndexType p = 0; p < 2; ++p)
272       {
273           const IndexType offset = HalfDimensions * p;
274           auto out = reinterpret_cast<__m64*>(&output[offset]);
275           for (IndexType j = 0; j < NumChunks; ++j)
276           {
277               __m64 sum0 = *(&reinterpret_cast<const __m64*>(accumulation[perspectives[p]])[j * 2 + 0]);
278               __m64 sum1 = *(&reinterpret_cast<const __m64*>(accumulation[perspectives[p]])[j * 2 + 1]);
279               const __m64 packedbytes = _mm_packs_pi16(sum0, sum1);
280               out[j] = _mm_subs_pi8(_mm_adds_pi8(packedbytes, k0x80s), k0x80s);
281           }
282       }
283       _mm_empty();
284       return psqt;
285
286   #elif defined(USE_NEON)
287
288       constexpr IndexType NumChunks = HalfDimensions / (SimdWidth / 2);
289       const int8x8_t Zero = {0};
290
291       for (IndexType p = 0; p < 2; ++p)
292       {
293           const IndexType offset = HalfDimensions * p;
294           const auto out = reinterpret_cast<int8x8_t*>(&output[offset]);
295           for (IndexType j = 0; j < NumChunks; ++j)
296           {
297               int16x8_t sum = reinterpret_cast<const int16x8_t*>(accumulation[perspectives[p]])[j];
298               out[j] = vmax_s8(vqmovn_s16(sum), Zero);
299           }
300       }
301       return psqt;
302
303   #else
304
305       for (IndexType p = 0; p < 2; ++p)
306       {
307           const IndexType offset = HalfDimensions * p;
308           for (IndexType j = 0; j < HalfDimensions; ++j)
309           {
310               BiasType sum = accumulation[perspectives[p]][j];
311               output[offset + j] = static_cast<OutputType>(std::max<int>(0, std::min<int>(127, sum)));
312           }
313       }
314       return psqt;
315
316   #endif
317
318    } // end of function transform()
319
320
321
322    private:
323     void update_accumulator(const Position& pos, const Color perspective) const {
324
325       // The size must be enough to contain the largest possible update.
326       // That might depend on the feature set and generally relies on the
327       // feature set's update cost calculation to be correct and never
328       // allow updates with more added/removed features than MaxActiveDimensions.
329       using IndexList = ValueList<IndexType, FeatureSet::MaxActiveDimensions>;
330
331   #ifdef VECTOR
332       // Gcc-10.2 unnecessarily spills AVX2 registers if this array
333       // is defined in the VECTOR code below, once in each branch
334       vec_t acc[NumRegs];
335       psqt_vec_t psqt[NumPsqtRegs];
336   #endif
337
338       // Look for a usable accumulator of an earlier position. We keep track
339       // of the estimated gain in terms of features to be added/subtracted.
340       StateInfo *st = pos.state(), *next = nullptr;
341       int gain = FeatureSet::refresh_cost(pos);
342       while (st->accumulator.state[perspective] == EMPTY)
343       {
344         // This governs when a full feature refresh is needed and how many
345         // updates are better than just one full refresh.
346         if (   FeatureSet::requires_refresh(st, perspective)
347             || (gain -= FeatureSet::update_cost(st) + 1) < 0)
348           break;
349         next = st;
350         st = st->previous;
351       }
352
353       if (st->accumulator.state[perspective] == COMPUTED)
354       {
355         if (next == nullptr)
356           return;
357
358         // Update incrementally in two steps. First, we update the "next"
359         // accumulator. Then, we update the current accumulator (pos.state()).
360
361         // Gather all features to be updated.
362         const Square ksq = pos.square<KING>(perspective);
363         IndexList removed[2], added[2];
364         FeatureSet::append_changed_indices(
365           ksq, next, perspective, removed[0], added[0]);
366         for (StateInfo *st2 = pos.state(); st2 != next; st2 = st2->previous)
367           FeatureSet::append_changed_indices(
368             ksq, st2, perspective, removed[1], added[1]);
369
370         // Mark the accumulators as computed.
371         next->accumulator.state[perspective] = COMPUTED;
372         pos.state()->accumulator.state[perspective] = COMPUTED;
373
374         // Now update the accumulators listed in states_to_update[], where the last element is a sentinel.
375         StateInfo *states_to_update[3] =
376           { next, next == pos.state() ? nullptr : pos.state(), nullptr };
377   #ifdef VECTOR
378         for (IndexType j = 0; j < HalfDimensions / TileHeight; ++j)
379         {
380           // Load accumulator
381           auto accTile = reinterpret_cast<vec_t*>(
382             &st->accumulator.accumulation[perspective][j * TileHeight]);
383           for (IndexType k = 0; k < NumRegs; ++k)
384             acc[k] = vec_load(&accTile[k]);
385
386           for (IndexType i = 0; states_to_update[i]; ++i)
387           {
388             // Difference calculation for the deactivated features
389             for (const auto index : removed[i])
390             {
391               const IndexType offset = HalfDimensions * index + j * TileHeight;
392               auto column = reinterpret_cast<const vec_t*>(&weights[offset]);
393               for (IndexType k = 0; k < NumRegs; ++k)
394                 acc[k] = vec_sub_16(acc[k], column[k]);
395             }
396
397             // Difference calculation for the activated features
398             for (const auto index : added[i])
399             {
400               const IndexType offset = HalfDimensions * index + j * TileHeight;
401               auto column = reinterpret_cast<const vec_t*>(&weights[offset]);
402               for (IndexType k = 0; k < NumRegs; ++k)
403                 acc[k] = vec_add_16(acc[k], column[k]);
404             }
405
406             // Store accumulator
407             accTile = reinterpret_cast<vec_t*>(
408               &states_to_update[i]->accumulator.accumulation[perspective][j * TileHeight]);
409             for (IndexType k = 0; k < NumRegs; ++k)
410               vec_store(&accTile[k], acc[k]);
411           }
412         }
413
414         for (IndexType j = 0; j < PSQTBuckets / PsqtTileHeight; ++j)
415         {
416           // Load accumulator
417           auto accTilePsqt = reinterpret_cast<psqt_vec_t*>(
418             &st->accumulator.psqtAccumulation[perspective][j * PsqtTileHeight]);
419           for (std::size_t k = 0; k < NumPsqtRegs; ++k)
420             psqt[k] = vec_load_psqt(&accTilePsqt[k]);
421
422           for (IndexType i = 0; states_to_update[i]; ++i)
423           {
424             // Difference calculation for the deactivated features
425             for (const auto index : removed[i])
426             {
427               const IndexType offset = PSQTBuckets * index + j * PsqtTileHeight;
428               auto columnPsqt = reinterpret_cast<const psqt_vec_t*>(&psqtWeights[offset]);
429               for (std::size_t k = 0; k < NumPsqtRegs; ++k)
430                 psqt[k] = vec_sub_psqt_32(psqt[k], columnPsqt[k]);
431             }
432
433             // Difference calculation for the activated features
434             for (const auto index : added[i])
435             {
436               const IndexType offset = PSQTBuckets * index + j * PsqtTileHeight;
437               auto columnPsqt = reinterpret_cast<const psqt_vec_t*>(&psqtWeights[offset]);
438               for (std::size_t k = 0; k < NumPsqtRegs; ++k)
439                 psqt[k] = vec_add_psqt_32(psqt[k], columnPsqt[k]);
440             }
441
442             // Store accumulator
443             accTilePsqt = reinterpret_cast<psqt_vec_t*>(
444               &states_to_update[i]->accumulator.psqtAccumulation[perspective][j * PsqtTileHeight]);
445             for (std::size_t k = 0; k < NumPsqtRegs; ++k)
446               vec_store_psqt(&accTilePsqt[k], psqt[k]);
447           }
448         }
449
450   #else
451         for (IndexType i = 0; states_to_update[i]; ++i)
452         {
453           std::memcpy(states_to_update[i]->accumulator.accumulation[perspective],
454               st->accumulator.accumulation[perspective],
455               HalfDimensions * sizeof(BiasType));
456
457           for (std::size_t k = 0; k < PSQTBuckets; ++k)
458             states_to_update[i]->accumulator.psqtAccumulation[perspective][k] = st->accumulator.psqtAccumulation[perspective][k];
459
460           st = states_to_update[i];
461
462           // Difference calculation for the deactivated features
463           for (const auto index : removed[i])
464           {
465             const IndexType offset = HalfDimensions * index;
466
467             for (IndexType j = 0; j < HalfDimensions; ++j)
468               st->accumulator.accumulation[perspective][j] -= weights[offset + j];
469
470             for (std::size_t k = 0; k < PSQTBuckets; ++k)
471               st->accumulator.psqtAccumulation[perspective][k] -= psqtWeights[index * PSQTBuckets + k];
472           }
473
474           // Difference calculation for the activated features
475           for (const auto index : added[i])
476           {
477             const IndexType offset = HalfDimensions * index;
478
479             for (IndexType j = 0; j < HalfDimensions; ++j)
480               st->accumulator.accumulation[perspective][j] += weights[offset + j];
481
482             for (std::size_t k = 0; k < PSQTBuckets; ++k)
483               st->accumulator.psqtAccumulation[perspective][k] += psqtWeights[index * PSQTBuckets + k];
484           }
485         }
486   #endif
487       }
488       else
489       {
490         // Refresh the accumulator
491         auto& accumulator = pos.state()->accumulator;
492         accumulator.state[perspective] = COMPUTED;
493         IndexList active;
494         FeatureSet::append_active_indices(pos, perspective, active);
495
496   #ifdef VECTOR
497         for (IndexType j = 0; j < HalfDimensions / TileHeight; ++j)
498         {
499           auto biasesTile = reinterpret_cast<const vec_t*>(
500               &biases[j * TileHeight]);
501           for (IndexType k = 0; k < NumRegs; ++k)
502             acc[k] = biasesTile[k];
503
504           for (const auto index : active)
505           {
506             const IndexType offset = HalfDimensions * index + j * TileHeight;
507             auto column = reinterpret_cast<const vec_t*>(&weights[offset]);
508
509             for (unsigned k = 0; k < NumRegs; ++k)
510               acc[k] = vec_add_16(acc[k], column[k]);
511           }
512
513           auto accTile = reinterpret_cast<vec_t*>(
514               &accumulator.accumulation[perspective][j * TileHeight]);
515           for (unsigned k = 0; k < NumRegs; k++)
516             vec_store(&accTile[k], acc[k]);
517         }
518
519         for (IndexType j = 0; j < PSQTBuckets / PsqtTileHeight; ++j)
520         {
521           for (std::size_t k = 0; k < NumPsqtRegs; ++k)
522             psqt[k] = vec_zero_psqt();
523
524           for (const auto index : active)
525           {
526             const IndexType offset = PSQTBuckets * index + j * PsqtTileHeight;
527             auto columnPsqt = reinterpret_cast<const psqt_vec_t*>(&psqtWeights[offset]);
528
529             for (std::size_t k = 0; k < NumPsqtRegs; ++k)
530               psqt[k] = vec_add_psqt_32(psqt[k], columnPsqt[k]);
531           }
532
533           auto accTilePsqt = reinterpret_cast<psqt_vec_t*>(
534             &accumulator.psqtAccumulation[perspective][j * PsqtTileHeight]);
535           for (std::size_t k = 0; k < NumPsqtRegs; ++k)
536             vec_store_psqt(&accTilePsqt[k], psqt[k]);
537         }
538
539   #else
540         std::memcpy(accumulator.accumulation[perspective], biases,
541             HalfDimensions * sizeof(BiasType));
542
543         for (std::size_t k = 0; k < PSQTBuckets; ++k)
544           accumulator.psqtAccumulation[perspective][k] = 0;
545
546         for (const auto index : active)
547         {
548           const IndexType offset = HalfDimensions * index;
549
550           for (IndexType j = 0; j < HalfDimensions; ++j)
551             accumulator.accumulation[perspective][j] += weights[offset + j];
552
553           for (std::size_t k = 0; k < PSQTBuckets; ++k)
554             accumulator.psqtAccumulation[perspective][k] += psqtWeights[index * PSQTBuckets + k];
555         }
556   #endif
557       }
558
559   #if defined(USE_MMX)
560       _mm_empty();
561   #endif
562     }
563
564     using BiasType = std::int16_t;
565     using WeightType = std::int16_t;
566     using PSQTWeightType = std::int32_t;
567
568     alignas(CacheLineSize) BiasType biases[HalfDimensions];
569     alignas(CacheLineSize) WeightType weights[HalfDimensions * InputDimensions];
570     alignas(CacheLineSize) PSQTWeightType psqtWeights[InputDimensions * PSQTBuckets];
571   };
572
573 }  // namespace Stockfish::Eval::NNUE
574
575 #endif // #ifndef NNUE_FEATURE_TRANSFORMER_H_INCLUDED