This commit is contained in:
Marek Lemańczyk committed 2025-09-23 23:29:44 +02:00
1 parent 4e5dd35a15
commit 7079d108e7
1 file changed
+30 -30
@@ -322,23 +322,23 @@ public sealed class MersenneNumberDivisorByDivisorGpuTester
MersenneDivisorCycles? divisorCycles = useCycles ? MersenneDivisorCycles.Shared : null; MersenneDivisorCycles? divisorCycles = useCycles ? MersenneDivisorCycles.Shared : null;
ulong cycle = useCycles ? divisorCycles!.GetCycle(divisor) : 0UL; ulong cycle = useCycles ? divisorCycles!.GetCycle(divisor) : 0UL;
MontgomeryDivisorData divisorData = CreateMontgomeryDivisorData(divisor); MontgomeryDivisorData divisorData = CreateMontgomeryDivisorData(divisor);
Span<ulong> primeSpan = _primesHost.AsSpan(0, _owner._gpuBatchSize); Span<ulong> primeSpan = _primesHost.AsSpan(0, _owner._gpuBatchSize);
Span<int> indexSpan = _indexHost.AsSpan(0, _owner._gpuBatchSize); Span<int> indexSpan = _indexHost.AsSpan(0, _owner._gpuBatchSize);
Span<byte> hitSpan = _hitsHost.AsSpan(0, _owner._gpuBatchSize); Span<byte> hitSpan = _hitsHost.AsSpan(0, _owner._gpuBatchSize);
int currentSpanSize = _owner._gpuBatchSize; int currentSpanSize = _owner._gpuBatchSize;
while (offset < primes.Length) while (offset < primes.Length)
{ {
int batchSize = Math.Min(_owner._gpuBatchSize, primes.Length - offset); int batchSize = Math.Min(_owner._gpuBatchSize, primes.Length - offset);
if (batchSize != currentSpanSize) if (batchSize != currentSpanSize)
{ {
primeSpan = _primesHost.AsSpan(0, batchSize); primeSpan = _primesHost.AsSpan(0, batchSize);
indexSpan = _indexHost.AsSpan(0, batchSize); indexSpan = _indexHost.AsSpan(0, batchSize);
hitSpan = _hitsHost.AsSpan(0, batchSize); hitSpan = _hitsHost.AsSpan(0, batchSize);
currentSpanSize = batchSize; currentSpanSize = batchSize;
} }
primes.Slice(offset, batchSize).CopyTo(primeSpan); primes.Slice(offset, batchSize).CopyTo(primeSpan);
if (++consoleStatus == PerfectNumberConstants.ConsoleInterval) if (++consoleStatus == PerfectNumberConstants.ConsoleInterval)
{ {
@@ -346,11 +346,11 @@ public sealed class MersenneNumberDivisorByDivisorGpuTester
consoleStatus = 0; consoleStatus = 0;
} }
Span<byte> hitsSlice = hits.Slice(offset, batchSize); Span<byte> hitsSlice = hits.Slice(offset, batchSize);
int gpuCount = 0; int gpuCount = 0;
if (useCycles) if (useCycles)
{ {
for (int i = 0; i < batchSize; i++) for (int i = 0; i < batchSize; i++)
{ {
ulong primeValue = primeSpan[i]; ulong primeValue = primeSpan[i];
@@ -367,19 +367,19 @@ public sealed class MersenneNumberDivisorByDivisorGpuTester
if (gpuCount > 0) if (gpuCount > 0)
{ {
var primesView = _primesBuffer.View.SubView(0, gpuCount); var primesView = _primesBuffer.View.SubView(0, gpuCount);
var hitsView = _hitsBuffer.View.SubView(0, gpuCount); var hitsView = _hitsBuffer.View.SubView(0, gpuCount);
primesView.CopyFromCPU(ref MemoryMarshal.GetReference(primeSpan), gpuCount); primesView.CopyFromCPU(ref MemoryMarshal.GetReference(primeSpan), gpuCount);
_kernel(gpuCount, divisorData, primesView, hitsView); _kernel(gpuCount, divisorData, primesView, hitsView);
_accelerator.Synchronize(); _accelerator.Synchronize();
hitsView.CopyToCPU(ref MemoryMarshal.GetReference(hitSpan), gpuCount); hitsView.CopyToCPU(ref MemoryMarshal.GetReference(hitSpan), gpuCount);
for (int i = 0; i < gpuCount; i++) for (int i = 0; i < gpuCount; i++)
{ {
hitsSlice[indexSpan[i]] = hitSpan[i]; hitsSlice[indexSpan[i]] = hitSpan[i];
} }
} }
} }
else else
{ {