diff --git a/EvenPerfectBitScanner.Benchmarks/MulMod64Benchmarks.Gpu.cs b/EvenPerfectBitScanner.Benchmarks/MulMod64Benchmarks.Gpu.cs
index eb193c4..4d327cf 100644
--- a/EvenPerfectBitScanner.Benchmarks/MulMod64Benchmarks.Gpu.cs
+++ b/EvenPerfectBitScanner.Benchmarks/MulMod64Benchmarks.Gpu.cs
@@ -11,6 +11,11 @@ using PerfectNumbers.Core.Gpu;
namespace EvenPerfectBitScanner.Benchmarks;
+///
+/// GPU benchmarks for 64-bit modular multiplication helpers.
+/// Windows 11 results ranged from 0.62 ms to 1.63 ms, and GpuCompatibleMulModSimplifiedExtension led the PrimeSizedModulus case at 0.641 ms.
+/// Recommended helper for p ≥ 138,000,000 is GpuCompatibleMulModSimplifiedExtension.
+///
[SimpleJob(RuntimeMoniker.Net80)]
[MemoryDiagnoser]
public class MulMod64BenchmarksGpu : IDisposable
@@ -76,66 +81,110 @@ public class MulMod64BenchmarksGpu : IDisposable
_legacyDeferredKernel = _accelerator.LoadAutoGroupedStreamKernel, ArrayView>(LegacyDeferredKernel);
}
+ ///
+ /// Inline wide multiply/reduce baseline: ZeroOperands 0.618 ms, MixedBitPattern 0.640 ms, CrossWordBlend 0.928 ms, NearFullRange 0.875 ms, PrimeSizedModulus 0.759 ms, SparseOperands 0.804 ms.
+ /// Use primarily as a reference; optimized GPU-specific helpers beat it across all datasets.
+ ///
[Benchmark(Baseline = true)]
public void ExtensionBaseline()
{
LaunchKernel(_extensionBaselineKernel);
}
+ ///
+ /// Original GPU-compatible extension path: means from 0.614 ms (MixedBitPattern) to 1.023 ms (CrossWordBlend) with PrimeSizedModulus at 0.697 ms.
+ /// Retain only when mirroring the CPU extension logic outweighs the speed gap to the simplified helper.
+ ///
[Benchmark]
public void GpuCompatibleMulModExtension()
{
LaunchKernel(_gpuCompatibleExtensionKernel);
}
+ ///
+ /// Simplified GPU extension helper: 0.708 ms (ZeroOperands), 0.905 ms (CrossWordBlend), 0.798 ms (NearFullRange), and class-leading 0.641 ms (PrimeSizedModulus).
+ /// Recommended for production GPU scans, especially for large p ≥ 138,000,000.
+ ///
[Benchmark]
public void GpuCompatibleMulModSimplifiedExtension()
{
LaunchKernel(_gpuCompatibleSimplifiedKernel);
}
+ ///
+ /// Inline UInt128 multiplication without operand reduction: CrossWordBlend 0.838 ms, MixedBitPattern 0.865 ms, NearFullRange 0.786 ms, PrimeSizedModulus 0.709 ms, SparseOperands 0.751 ms, ZeroOperands 0.827 ms.
+ /// Suitable when explicit UInt128 math is acceptable, though it trails the simplified GPU helper on every dataset.
+ ///
[Benchmark]
public void InlineUInt128Operands()
{
LaunchKernel(_inlineKernel);
}
+ ///
+ /// Reduces operands before multiplying: ZeroOperands 0.926 ms, CrossWordBlend 0.847 ms, MixedBitPattern 0.843 ms, NearFullRange 0.689 ms, PrimeSizedModulus 0.809 ms, SparseOperands 0.746 ms.
+ /// Only competitive on NearFullRange; the extra reductions hurt other scenarios.
+ ///
[Benchmark]
public void InlineUInt128OperandsWithReductionFirst()
{
LaunchKernel(_inlineReductionFirstKernel);
}
+ ///
+ /// Performs operand reduction and then multiplies inline: CrossWordBlend 1.041 ms, MixedBitPattern 0.913 ms, NearFullRange 0.847 ms, PrimeSizedModulus 0.812 ms, SparseOperands 0.744 ms, ZeroOperands 0.802 ms.
+ /// Consistently slower than both the reduction-first and simplified GPU helpers.
+ ///
[Benchmark]
public void InlineUInt128OperandsWithOperandReduction()
{
LaunchKernel(_inlineOperandReductionKernel);
}
+ ///
+ /// Uses local temporaries for the wide product: ZeroOperands 0.691 ms, CrossWordBlend 0.914 ms, MixedBitPattern 0.874 ms, NearFullRange 0.702 ms, PrimeSizedModulus 0.817 ms, SparseOperands 0.728 ms.
+ /// Balanced choice when sticking with manual wide products, but still slower than the simplified GPU path.
+ ///
[Benchmark]
public void InlineUInt128WithLocals()
{
LaunchKernel(_inlineLocalsKernel);
}
+ ///
+ /// Combines local temporaries with operand reduction: ZeroOperands 0.698 ms, CrossWordBlend 0.858 ms, MixedBitPattern 0.877 ms, NearFullRange 0.851 ms, PrimeSizedModulus 0.761 ms, SparseOperands 0.779 ms.
+ /// Adds little benefit over the non-reduced local variant while increasing cost on most datasets.
+ ///
[Benchmark]
public void InlineUInt128WithLocalsAndOperandReduction()
{
LaunchKernel(_inlineLocalsOperandReductionKernel);
}
+ ///
+ /// Multiply-high decomposition: ZeroOperands 0.651 ms, CrossWordBlend 0.848 ms, MixedBitPattern 0.758 ms, NearFullRange 0.812 ms, PrimeSizedModulus 0.728 ms, SparseOperands 0.699 ms.
+ /// Useful when avoiding UInt128 temporaries on sparse inputs, but still behind the simplified GPU helper for prime-sized moduli.
+ ///
[Benchmark]
public void MultiplyHighDecomposition()
{
LaunchKernel(_mulHighKernel);
}
+ ///
+ /// Legacy GPU baseline: ZeroOperands 0.759 ms, CrossWordBlend 0.971 ms, MixedBitPattern 0.827 ms, NearFullRange 0.870 ms, PrimeSizedModulus 0.737 ms, SparseOperands 0.620 ms.
+ /// Retain only for regression comparisons; newer helpers are faster except on the sparse sample.
+ ///
[Benchmark]
public void GpuCompatibleBaseline()
{
LaunchKernel(_legacyKernel);
}
+ ///
+ /// Deferred legacy helper: ZeroOperands 1.561 ms, CrossWordBlend 1.631 ms, MixedBitPattern 1.540 ms, NearFullRange 1.438 ms, PrimeSizedModulus 1.598 ms, SparseOperands 1.096 ms.
+ /// Slowest option in every scenario; keep only for historical context.
+ ///
[Benchmark]
public void GpuCompatibleDeferred()
{