Align Lucas-Lehmer GPU helpers with windowed pow2 guidance

This commit is contained in:
Marek Lemańczyk committed 2025-10-20 18:37:15 +02:00
1 parent 82e44e3f3f
commit 360a31bd54
2 files changed
+4 -15

No files matched your search

+2 -12
View File
@@ -1020,18 +1020,8 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ulong ShiftLeftByNativeChunk(ulong value, ulong modulus)
{
// TODO: Collapse this eight-step shift ladder into the ProcessEightBitWindows helper once it lands so
// we reuse the precomputed window residues instead of emitting `% modulus` after every shift.
value = (value << 1) % modulus;
value = (value << 1) % modulus;
value = (value << 1) % modulus;
value = (value << 1) % modulus;
value = (value << 1) % modulus;
value = (value << 1) % modulus;
value = (value << 1) % modulus;
value = (value << 1) % modulus;
return value;
// Multiply by 2^NativeModuloChunkBits in one pass so the native-modulo path avoids eight `%` reductions.
return MulMod64(value, 1UL << NativeModuloChunkBits, modulus);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -112,7 +112,7 @@ public class MersenneNumberLucasLehmerGpuTester
var gpu = GpuContextPool.RentPreferred(preferCpu: false);
var accelerator = gpu.Accelerator;
var kernel = GetBatchKernel(accelerator); // TODO: Switch this batch path to the ProcessEightBitWindows residue kernel once Lucas–Lehmer integrates the benchmarked windowed pow2 helper for small exponents.
var kernel = GetBatchKernel(accelerator); // Batch kernel already relies on the Mersenne squaring reducer; windowed pow2 helpers do not apply here.
var expBuffer = accelerator.Allocate1D<ulong>(count);
ulong[] expArray = ArrayPool<ulong>.Shared.Rent(count);
@@ -479,8 +479,7 @@ public class MersenneNumberLucasLehmerGpuTester
{
if ((exponent & 1UL) != 0UL)
{
// TODO: Route these powmods through the ProcessEightBitWindows helper once it lands for GPU
// host-side fallbacks so the Lucas–Lehmer setup reuses the benchmarked windowed ladder.
// The base varies per primitive-root candidate, so pow2-specific ladders do not apply.
result = MulMod(result, value, modulus);
}