Align Lucas-Lehmer GPU helpers with windowed pow2 guidance
This commit is contained in:
1 parent
82e44e3f3f
commit
360a31bd54
2 files changed
+4
-15
No files matched your search
@@ -1020,18 +1020,8 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static ulong ShiftLeftByNativeChunk(ulong value, ulong modulus)
|
private static ulong ShiftLeftByNativeChunk(ulong value, ulong modulus)
|
||||||
{
|
{
|
||||||
// TODO: Collapse this eight-step shift ladder into the ProcessEightBitWindows helper once it lands so
|
// Multiply by 2^NativeModuloChunkBits in one pass so the native-modulo path avoids eight `%` reductions.
|
||||||
// we reuse the precomputed window residues instead of emitting `% modulus` after every shift.
|
return MulMod64(value, 1UL << NativeModuloChunkBits, 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;
|
|
||||||
value = (value << 1) % modulus;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class MersenneNumberLucasLehmerGpuTester
|
|||||||
|
|
||||||
var gpu = GpuContextPool.RentPreferred(preferCpu: false);
|
var gpu = GpuContextPool.RentPreferred(preferCpu: false);
|
||||||
var accelerator = gpu.Accelerator;
|
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);
|
var expBuffer = accelerator.Allocate1D<ulong>(count);
|
||||||
ulong[] expArray = ArrayPool<ulong>.Shared.Rent(count);
|
ulong[] expArray = ArrayPool<ulong>.Shared.Rent(count);
|
||||||
@@ -479,8 +479,7 @@ public class MersenneNumberLucasLehmerGpuTester
|
|||||||
{
|
{
|
||||||
if ((exponent & 1UL) != 0UL)
|
if ((exponent & 1UL) != 0UL)
|
||||||
{
|
{
|
||||||
// TODO: Route these powmods through the ProcessEightBitWindows helper once it lands for GPU
|
// The base varies per primitive-root candidate, so pow2-specific ladders do not apply.
|
||||||
// host-side fallbacks so the Lucas–Lehmer setup reuses the benchmarked windowed ladder.
|
|
||||||
result = MulMod(result, value, modulus);
|
result = MulMod(result, value, modulus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user