Let's analyze the potential runtime cost of adding RMS normalization to the NNUE network in Ethereal, assuming a 2017-era Xeon CPU at 2.2 GHz (e.g., Intel Xeon E5-26xx v4 series), which supports AVX2 instructions. This analysis will take into account the CPU's capabilities and typical performance for vectorized operations.
RMS Normalization: What It Entails
RMS normalization involves the following steps for a vector ( \mathbf{x} ) of size ( N ):
- Compute the mean squared value (MS):
[
\text{MS} = \frac{1}{N} \sum_{i=1}^N x_i^2
]
- Compute the root mean square (RMS):
[
\text{RMS} = \sqrt{\text{MS}}
]
- Normalize each element:
[
y_i = \frac{x_i}{\text{RMS}}
]
Assumptions for the Analysis
- Vector size: The NNUE network typically works with vectors of size ( N = 512 ) for intermediate layers (e.g.,
L1SIZE, L2SIZE).
- AVX2 registers: Each AVX2 register processes 8 single-precision floats (32-bit) per instruction.
- Clock speed: 2.2 GHz Xeon CPU.
- Latency and throughput: Based on Intel's optimization manuals for AVX2:
- Floating-point addition/multiplication: ~4 cycles latency, 1 cycle throughput.
- Horizontal reduction (summing a vector): ~8 cycles (depends on implementation).
- Square root (for RMS): ~14 cycles latency, 1 operation every 7 cycles throughput.
Step-by-Step Runtime Estimation
Step 1: Compute Mean Squared Value (MS)
-
Square each element:
- ( N = 512 ) elements.
- Using AVX2, we process 8 elements per instruction.
- Total instructions: ( 512 / 8 = 64 ).
- Each instruction takes ~4 cycles.
- Total cycles: ( 64 \times 4 = 256 ) cycles.
-
Sum the squared values (reduction):
- Horizontal reduction of 512 values.
- AVX2 reductions typically take ~8 cycles per vector (8 elements).
- Total vectors: ( 512 / 8 = 64 ).
- Total cycles: ( \log_2(64) \times 8 \approx 48 ) cycles.
-
Compute the mean:
- Divide by ( N ) (single division).
- Division latency: ~14 cycles.
Total for Step 1: ~256 + 48 + 14 = 318 cycles.
Step 2: Compute Root Mean Square (RMS)
- Square root computation:
- Single RMS computation.
- Latency: ~14 cycles.
Total for Step 2: ~14 cycles.
Step 3: Normalize Each Element
- Divide each element by RMS:
- ( N = 512 ) divisions.
- Using AVX2, we process 8 elements per instruction.
- Total instructions: ( 512 / 8 = 64 ).
- Division latency: ~14 cycles per vector.
- Total cycles: ( 64 \times 14 = 896 ).
Total for Step 3: ~896 cycles.
Overall Runtime Estimate
Summing up all steps:
- Step 1: Compute MS = 318 cycles.
- Step 2: Compute RMS = 14 cycles.
- Step 3: Normalize = 896 cycles.
Total: ( 318 + 14 + 896 = 1228 ) cycles.
At 2.2 GHz, a single clock cycle takes ( 1 / 2.2 \times 10^9 \approx 0.454 ) ns. Thus:
[
\text{Runtime} = 1228 \times 0.454 \approx 558 , \text{ns}
]
How Does This Compare to NNUE Layer Computations?
Current NNUE layers (e.g., matrix multiplications, activations, etc.) are highly optimized, taking approximately 1–2 µs (1000–2000 ns) per layer on similar hardware. Adding RMS normalization would cost ~558 ns, which is:
- ~28–55% of the runtime per layer (depending on the layer's complexity).
- A significant addition to the runtime, especially considering that millions of evaluations are performed during a chess engine search.
Impact on Search Performance
-
Search Depth Reduction:
- If RMS normalization increases evaluation time by ~30%, the engine will evaluate ~30% fewer nodes per second.
- This would lower the search depth by approximately 1–2 plies, depending on the time controls, which can significantly weaken engine strength.
-
Trade-Offs:
- While normalization might improve stability during training, its runtime cost outweighs the benefits in the inference phase, especially for chess engines where speed is critical.
Conclusion
On a 2017-era Xeon CPU, adding RMS normalization to NNUE evaluation would cost approximately 558 ns per layer, increasing the runtime by ~30%. This overhead is substantial in the performance-critical environment of chess engines, where every nanosecond counts. Consequently, normalization techniques are avoided in NNUE networks to maintain maximum efficiency during inference.