From ea11db6d0f8aa29ee569cc0f04dce68fba972c66 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Tue, 21 Oct 2025 04:08:48 +0200 Subject: [PATCH] Restored the Dictionary parameter instead of arrays --- .../PrimeOrderCalculator.Gpu.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs b/PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs index 1073e91..4cb801c 100644 --- a/PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs +++ b/PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs @@ -13,18 +13,18 @@ internal static partial class PrimeOrderCalculator private const int GpuSmallPrimeFactorSlots = 64; - private static bool TryPopulateSmallPrimeFactorsGpu(ulong value, uint limit, Span primeBuffer, Span exponentBuffer, out int factorCount, out ulong remaining) + private static bool TryPopulateSmallPrimeFactorsGpu(ulong value, uint limit, Dictionary counts, out int factorCount, out ulong remaining) { - // primeBufferArray = ThreadStaticPools.UlongPool.Rent(GpuSmallPrimeFactorSlots); - // exponentBufferArray = ThreadStaticPools.IntPool.Rent(GpuSmallPrimeFactorSlots); - // Span primeBuffer = primeBufferArray.AsSpan(0, GpuSmallPrimeFactorSlots); - // Span exponentBuffer = exponentBufferArray.AsSpan(0, GpuSmallPrimeFactorSlots); + var primeBufferArray = ThreadStaticPools.UlongPool.Rent(GpuSmallPrimeFactorSlots); + var exponentBufferArray = ThreadStaticPools.IntPool.Rent(GpuSmallPrimeFactorSlots); + Span primeBuffer = primeBufferArray.AsSpan(0, GpuSmallPrimeFactorSlots); + Span exponentBuffer = exponentBufferArray.AsSpan(0, GpuSmallPrimeFactorSlots); // primeBuffer.Clear(); // exponentBuffer.Clear(); remaining = value; - // try - // { + try + { var lease = GpuKernelPool.GetKernel(useGpuOrder: true); var execution = lease.EnterExecutionScope(); try @@ -64,18 +64,18 @@ internal static partial class PrimeOrderCalculator scratch.RemainingSlot.View.CopyToCPU(ref remaining, 1); - // for (int i = 0; i < factorCount; i++) - // { - // ulong primeValue = primeBuffer[i]; - // int exponent = exponentBuffer[i]; - // // This will never happen in production code - // // if (primeValue == 0UL || exponent == 0) - // // { - // // continue; - // // } + for (int i = 0; i < factorCount; i++) + { + ulong primeValue = primeBuffer[i]; + int exponent = exponentBuffer[i]; + // This will never happen in production code + // if (primeValue == 0UL || exponent == 0) + // { + // continue; + // } - // counts[primeValue] = exponent; - // } + counts.Add(primeValue, exponent); + } return true; } @@ -84,11 +84,11 @@ internal static partial class PrimeOrderCalculator execution.Dispose(); lease.Dispose(); } - // } - // finally - // { - // ThreadStaticPools.UlongPool.Return(primeBufferArray); - // ThreadStaticPools.IntPool.Return(exponentBufferArray); - // } + } + finally + { + ThreadStaticPools.UlongPool.Return(primeBufferArray); + ThreadStaticPools.IntPool.Return(exponentBufferArray); + } } }