Document GPU mul-mod benchmark guidance
This commit is contained in:
1 parent
d0ba08dd24
commit
3e081141e0
1 file changed
+49
@@ -11,6 +11,11 @@ using PerfectNumbers.Core.Gpu;
|
||||
|
||||
namespace EvenPerfectBitScanner.Benchmarks;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[SimpleJob(RuntimeMoniker.Net80)]
|
||||
[MemoryDiagnoser]
|
||||
public class MulMod64BenchmarksGpu : IDisposable
|
||||
@@ -76,66 +81,110 @@ public class MulMod64BenchmarksGpu : IDisposable
|
||||
_legacyDeferredKernel = _accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<MulMod64GpuKernelInput>, ArrayView<ulong>>(LegacyDeferredKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
public void ExtensionBaseline()
|
||||
{
|
||||
LaunchKernel(_extensionBaselineKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void GpuCompatibleMulModExtension()
|
||||
{
|
||||
LaunchKernel(_gpuCompatibleExtensionKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void GpuCompatibleMulModSimplifiedExtension()
|
||||
{
|
||||
LaunchKernel(_gpuCompatibleSimplifiedKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void InlineUInt128Operands()
|
||||
{
|
||||
LaunchKernel(_inlineKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void InlineUInt128OperandsWithReductionFirst()
|
||||
{
|
||||
LaunchKernel(_inlineReductionFirstKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void InlineUInt128OperandsWithOperandReduction()
|
||||
{
|
||||
LaunchKernel(_inlineOperandReductionKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void InlineUInt128WithLocals()
|
||||
{
|
||||
LaunchKernel(_inlineLocalsKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void InlineUInt128WithLocalsAndOperandReduction()
|
||||
{
|
||||
LaunchKernel(_inlineLocalsOperandReductionKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void MultiplyHighDecomposition()
|
||||
{
|
||||
LaunchKernel(_mulHighKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void GpuCompatibleBaseline()
|
||||
{
|
||||
LaunchKernel(_legacyKernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void GpuCompatibleDeferred()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user