Switch GPU powmod host helpers to simplified mul-mod
This commit is contained in:
1 parent
03194650c9
commit
4b13bc6497
2 files changed
+7
-7
No files matched your search
@@ -81,7 +81,7 @@ public static partial class ULongExtensions
|
||||
while (index >= 0)
|
||||
{
|
||||
ulong currentBit = (exponent >> index) & 1UL;
|
||||
ulong squared = result.MulMod64(result, modulus);
|
||||
ulong squared = result.GpuCompatibleMulModSimplifiedExtension(result, modulus);
|
||||
result = currentBit == 0UL ? squared : result;
|
||||
index = currentBit == 0UL ? index - 1 : index;
|
||||
if (currentBit == 0UL)
|
||||
@@ -101,14 +101,14 @@ public static partial class ULongExtensions
|
||||
int windowLength = index - windowStart + 1;
|
||||
for (int square = 0; square < windowLength; square++)
|
||||
{
|
||||
result = result.MulMod64(result, modulus);
|
||||
result = result.GpuCompatibleMulModSimplifiedExtension(result, modulus);
|
||||
}
|
||||
|
||||
ulong mask = (1UL << windowLength) - 1UL;
|
||||
ulong windowValue = (exponent >> windowStart) & mask;
|
||||
int tableIndex = (int)((windowValue - 1UL) >> 1);
|
||||
ulong multiplier = oddPowers[tableIndex];
|
||||
result = result.MulMod64(multiplier, modulus);
|
||||
result = result.GpuCompatibleMulModSimplifiedExtension(multiplier, modulus);
|
||||
|
||||
index = windowStart - 1;
|
||||
}
|
||||
@@ -311,11 +311,11 @@ public static partial class ULongExtensions
|
||||
return;
|
||||
}
|
||||
|
||||
ulong square = baseValue.MulMod64(baseValue, modulus);
|
||||
ulong square = baseValue.GpuCompatibleMulModSimplifiedExtension(baseValue, modulus);
|
||||
for (int i = 1; i < oddPowers.Length; i++)
|
||||
{
|
||||
ulong previous = oddPowers[i - 1];
|
||||
oddPowers[i] = previous.MulMod64(square, modulus);
|
||||
oddPowers[i] = previous.GpuCompatibleMulModSimplifiedExtension(square, modulus);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ This note tracks every `MulMod` call site in the GPU-only `--mersenne=bydivisor`
|
||||
| --- | --- |
|
||||
| `ULongExtensions.GpuCompatibleMulModSimplifiedExtension` | Wraps `GpuUInt128.MulModSimplified` so host code mirrors the benchmark winner without reimplementing GPU logic.【F:PerfectNumbers.Core/ULongExtensions.Gpu.cs†L23-L31】 |
|
||||
| `ULongExtensions.MulMod64Gpu` | Marked obsolete; migrate to `ULongExtensions.GpuCompatibleMulModSimplifiedExtension` for GPU-compatible host code or `GpuUInt128.MulMod` when running inside kernels.【F:PerfectNumbers.Core/ULongExtensions.Gpu.cs†L17-L24】 |
|
||||
| `ULongExtensions.Pow2ModWindowedGpu` | Migrated to call `MulMod64` for every square and multiply, eliminating the 6–18× slowdown that the shim introduced while executing on the host.【F:PerfectNumbers.Core/ULongExtensions.Gpu.cs†L39-L109】 |
|
||||
| `ULongExtensions.InitializeStandardOddPowers` | Populates the odd-power table through `MulMod64`, so the host setup costs now match the CPU benchmark baseline.【F:PerfectNumbers.Core/ULongExtensions.Gpu.cs†L286-L309】 |
|
||||
| `ULongExtensions.Pow2ModWindowedGpu` | Migrated to call `GpuCompatibleMulModSimplifiedExtension` for every square and multiply, eliminating the 6–18× slowdown that the shim introduced while executing on the host and aligning host math with the new production helper.【F:PerfectNumbers.Core/ULongExtensions.Gpu.cs†L39-L109】 |
|
||||
| `ULongExtensions.InitializeStandardOddPowers` | Populates the odd-power table through `GpuCompatibleMulModSimplifiedExtension`, so the host setup costs now match the GPU-compatible benchmark winner.【F:PerfectNumbers.Core/ULongExtensions.Gpu.cs†L286-L309】 |
|
||||
|
||||
All host-executed `MulMod` operations in the GPU pipeline now target the optimized CPU helper.
|
||||
|
||||
|
||||
Reference in new issue
Block a user