Document GPU kernel audit progress
This commit is contained in:
1 parent
1e25ea0ccf
commit
6217ea7888
31 files changed
+3496
-3246
No files matched your search
@@ -847,7 +847,7 @@ public class MersenneDivisorCycles
|
||||
var kernel = accelerator.LoadAutoGroupedStreamKernel<
|
||||
Index1D,
|
||||
ArrayView1D<ulong, Stride1D.Dense>,
|
||||
ArrayView1D<ulong, Stride1D.Dense>>(GpuDivisorCycleKernel);
|
||||
ArrayView1D<ulong, Stride1D.Dense>>(DivisorCycleKernels.GpuDivisorCycleKernel);
|
||||
|
||||
|
||||
using Stream outputStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, BufferSize10M, useAsync: true);
|
||||
@@ -941,93 +941,8 @@ public class MersenneDivisorCycles
|
||||
|
||||
}
|
||||
|
||||
const byte ByteZero = 0;
|
||||
const byte ByteOne = 1;
|
||||
|
||||
// GPU kernel for divisor cycle calculation
|
||||
static void GpuDivisorCycleKernel(
|
||||
Index1D index,
|
||||
ArrayView1D<ulong, Stride1D.Dense> divisors,
|
||||
ArrayView1D<ulong, Stride1D.Dense> outCycles)
|
||||
{
|
||||
int i = index.X;
|
||||
outCycles[i] = CalculateCycleLengthGpu(divisors[i]);
|
||||
}
|
||||
|
||||
// GPU-friendly version of cycle length calculation
|
||||
/// <summary>
|
||||
/// GPU-friendly cycle calculator that unrolls sixteen doubling steps; it wins the 8,388,607 benchmark and stays within ~2% of the octo loop at divisor 131,071.
|
||||
/// </summary>
|
||||
public static ulong CalculateCycleLengthGpu(ulong divisor)
|
||||
{
|
||||
if ((divisor & (divisor - 1UL)) == 0UL)
|
||||
return 1UL;
|
||||
|
||||
ulong order = 1UL;
|
||||
ulong pow = 2UL;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
|
||||
if (GpuStep(ref pow, divisor, ref order))
|
||||
return order;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool GpuStep(ref ulong pow, ulong divisor, ref ulong order)
|
||||
{
|
||||
pow += pow;
|
||||
if (pow >= divisor)
|
||||
pow -= divisor;
|
||||
|
||||
order++;
|
||||
return pow == 1UL;
|
||||
}
|
||||
|
||||
public static ulong CalculateCycleLengthGpu(ulong divisor) => DivisorCycleKernels.CalculateCycleLengthGpu(divisor);
|
||||
|
||||
public static ulong CalculateCycleLength(ulong divisor, in MontgomeryDivisorData divisorData, bool skipPrimeOrderHeuristic = false)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user