GPU logic updated to use prime % divisor result precomputed on CPU instead of re-calculating it on GPU side. Cycle lease removed.
This commit is contained in:
1 parent
a171e57353
commit
49fcd93747
2 files changed
+684
-748
No files matched your search
@@ -12,61 +12,16 @@ namespace PerfectNumbers.Core;
|
|||||||
|
|
||||||
public sealed class DivisorCycleCache
|
public sealed class DivisorCycleCache
|
||||||
{
|
{
|
||||||
internal sealed class CycleBlock
|
public sealed class CycleBlock(int index, ulong start, ulong[] cycles)
|
||||||
{
|
{
|
||||||
internal CycleBlock(int index, ulong start, ulong[] cycles)
|
internal readonly int Index = index;
|
||||||
{
|
internal readonly ulong Start = start;
|
||||||
Index = index;
|
internal readonly ulong End = start + (ulong)cycles.Length - 1UL;
|
||||||
Start = start;
|
internal readonly ulong[] Cycles = cycles;
|
||||||
Cycles = cycles;
|
|
||||||
End = start + (ulong)cycles.Length - 1UL;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal int Index { get; }
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public ulong GetCycle(ulong divisor) => Cycles[(int)(divisor - Start)];
|
||||||
internal ulong Start { get; }
|
}
|
||||||
|
|
||||||
internal ulong End { get; }
|
|
||||||
|
|
||||||
internal ulong[] Cycles { get; }
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
internal ulong GetCycle(ulong divisor)
|
|
||||||
{
|
|
||||||
if (divisor < Start || divisor > End)
|
|
||||||
{
|
|
||||||
return 0UL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Cycles[(int)(divisor - Start)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct Lease : IDisposable
|
|
||||||
{
|
|
||||||
private CycleBlock? _block;
|
|
||||||
|
|
||||||
internal Lease(CycleBlock block)
|
|
||||||
{
|
|
||||||
_block = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public readonly bool IsValid => _block is not null;
|
|
||||||
|
|
||||||
public readonly ulong Start => _block?.Start ?? 0UL;
|
|
||||||
|
|
||||||
public readonly ulong End => _block?.End ?? 0UL;
|
|
||||||
|
|
||||||
public readonly ulong[]? Values => _block?.Cycles;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public readonly ulong GetCycle(ulong divisor) => _block?.GetCycle(divisor) ?? 0UL;
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_block = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private const int CycleGenerationBatchSize = 262_144;
|
private const int CycleGenerationBatchSize = 262_144;
|
||||||
private const int GpuCycleStepsPerInvocation = 524_288 / 16;
|
private const int GpuCycleStepsPerInvocation = 524_288 / 16;
|
||||||
@@ -115,15 +70,14 @@ public sealed class DivisorCycleCache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lease Acquire(ulong divisor)
|
public CycleBlock Acquire(ulong divisor)
|
||||||
{
|
{
|
||||||
if (divisor <= _baseBlock.End)
|
if (divisor <= _baseBlock.End)
|
||||||
{
|
{
|
||||||
return new Lease(_baseBlock);
|
return _baseBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
CycleBlock block = AcquireDynamicBlock(divisor);
|
return AcquireDynamicBlock(divisor);
|
||||||
return new Lease(block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CycleBlock AcquireDynamicBlock(ulong divisor)
|
private CycleBlock AcquireDynamicBlock(ulong divisor)
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user