Hybrid device mode implemented as the current --mersenne=bydivisor CPU execution path. CPU path is now limited to CPU calculations, only.

This commit is contained in:
mlemanczyk committed 2025-12-01 03:45:39 +01:00
1 parent 353a121d03
commit 941733905b
49 files changed
+4965 -1726

No files matched your search

@@ -2,6 +2,7 @@ using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using ILGPU;
using ILGPU.Runtime;
using PerfectNumbers.Core.Gpu.Accelerators;
namespace PerfectNumbers.Core.Gpu;
@@ -21,18 +22,16 @@ public class MersenneNumberResidueGpuTester(bool useGpuOrder)
// TODO: When cycles are missing for larger q values, compute only the single required cycle on the device
// requested by the caller, skip queuing additional block generation, and keep the snapshot cache untouched.
private static readonly Accelerator[] _accelerators = AcceleratorPool.Shared.Accelerators;
// GPU residue variant: check 2^p % q == 1 for q = 2*p*k + 1.
public void Scan(ulong exponent, UInt128 twoP, LastDigit lastDigit, UInt128 maxK, ref bool isPrime)
public void Scan(PrimeOrderCalculatorAccelerator gpu, ulong exponent, UInt128 twoP, LastDigit lastDigit, UInt128 maxK, ref bool isPrime)
{
// GpuPrimeWorkLimiter.Acquire();
var acceleratorIndex = AcceleratorPool.Shared.Rent();
var accelerator = _accelerators[acceleratorIndex];
var acceleratorIndex = gpu.AcceleratorIndex;
var accelerator = gpu.Accelerator;
// Monitor.Enter(gpuLease.ExecutionLock);
var stream = accelerator.CreateStream();
var stream = AcceleratorStreamPool.Rent(acceleratorIndex);
var kernel = GetPow2ModKernel(accelerator);
var resources = RentResources(accelerator, GpuConstants.ScanBatchSize);
var gpuKernels = GpuKernelPool.GetOrAddKernels(acceleratorIndex, stream, KernelType.SmallCycles | KernelType.SmallPrimes);
@@ -109,7 +108,7 @@ public class MersenneNumberResidueGpuTester(bool useGpuOrder)
}
ReturnResources(resources);
stream.Dispose();
AcceleratorStreamPool.Return(acceleratorIndex, stream);
// Monitor.Exit(gpuLease.ExecutionLock);
gpuKernels.Dispose();
// GpuPrimeWorkLimiter.Release();