diff --git a/PerfectNumbers.Core/Gpu/HeuristicCombinedGpuViews.cs b/PerfectNumbers.Core/Gpu/Accelerators/HeuristicCombinedGpuViews.cs similarity index 97% rename from PerfectNumbers.Core/Gpu/HeuristicCombinedGpuViews.cs rename to PerfectNumbers.Core/Gpu/Accelerators/HeuristicCombinedGpuViews.cs index 1a8f86d..65d70fd 100644 --- a/PerfectNumbers.Core/Gpu/HeuristicCombinedGpuViews.cs +++ b/PerfectNumbers.Core/Gpu/Accelerators/HeuristicCombinedGpuViews.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; using ILGPU; using ILGPU.Runtime; -namespace PerfectNumbers.Core.Gpu; +namespace PerfectNumbers.Core.Gpu.Accelerators; public readonly struct HeuristicCombinedGpuViews( ArrayView1D combinedDivisorsEnding1, diff --git a/PerfectNumbers.Core/Gpu/HeuristicGroupABGpuViews.cs b/PerfectNumbers.Core/Gpu/Accelerators/HeuristicGroupABGpuViews.cs similarity index 98% rename from PerfectNumbers.Core/Gpu/HeuristicGroupABGpuViews.cs rename to PerfectNumbers.Core/Gpu/Accelerators/HeuristicGroupABGpuViews.cs index b325f34..7b4e483 100644 --- a/PerfectNumbers.Core/Gpu/HeuristicGroupABGpuViews.cs +++ b/PerfectNumbers.Core/Gpu/Accelerators/HeuristicGroupABGpuViews.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; using ILGPU; using ILGPU.Runtime; -namespace PerfectNumbers.Core.Gpu; +namespace PerfectNumbers.Core.Gpu.Accelerators; public readonly struct HeuristicGroupABGpuViews( ArrayView1D groupADivisors, diff --git a/PerfectNumbers.Core/Gpu/Kernels/PrimeTesterKernels.cs b/PerfectNumbers.Core/Gpu/Kernels/PrimeTesterKernels.cs index 718ca41..3c03c6c 100644 --- a/PerfectNumbers.Core/Gpu/Kernels/PrimeTesterKernels.cs +++ b/PerfectNumbers.Core/Gpu/Kernels/PrimeTesterKernels.cs @@ -2,6 +2,7 @@ using System.Runtime.CompilerServices; using ILGPU; using ILGPU.Algorithms; using ILGPU.Runtime; +using PerfectNumbers.Core.Gpu.Accelerators; namespace PerfectNumbers.Core.Gpu; diff --git a/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs b/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs index 3c4f55e..f6cc2c4 100644 --- a/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs +++ b/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs @@ -172,7 +172,8 @@ internal static partial class PrimeOrderGpuHeuristics Accelerator accelerator = _accelerators[acceleratorIndex]; AcceleratorStream stream = accelerator.CreateStream(); - SmallPrimeFactorGpuTables cache = gpu.SmallPrimeFactorTables; + var smallPrimesView = gpu.SmallPrimeFactorPrimes; + var smallSquaresView = gpu.SmallPrimeFactorSquares; // TODO: We should create / reallocate these buffer only once or if the new required length is bigger than capacity. MemoryBuffer1D? factorBuffer = accelerator.Allocate1D(primeTargets.Length); @@ -194,9 +195,9 @@ internal static partial class PrimeOrderGpuHeuristics stream, 1, 1, - cache.Primes!.View, - cache.Squares!.View, - cache.Count, + smallPrimesView, + smallSquaresView, + smallPrimesView.Length, primeTargets.Length, value, limit, @@ -336,7 +337,8 @@ internal static partial class PrimeOrderGpuHeuristics int acceleratorIndex = AcceleratorPool.Shared.Rent(); Accelerator accelerator = _accelerators[acceleratorIndex]; AcceleratorStream stream = AcceleratorStreamPool.Rent(acceleratorIndex); - SmallPrimeFactorGpuTables cache = gpu.SmallPrimeFactorTables; + var smallPrimesView = gpu.SmallPrimeFactorPrimes; + var smallSquaresView = gpu.SmallPrimeFactorSquares; // TODO: These buffers should be created reallocated once and assigned to an accelerator. Callers should use their own // thread static cache to prevent other threads from using taking accelerators with pre-allocated buffers if they don't @@ -403,9 +405,9 @@ internal static partial class PrimeOrderGpuHeuristics prime, kernelConfig, divisorData, - cache.Primes!.View, - cache.Squares!.View, - cache.Count, + smallPrimesView, + smallSquaresView, + smallPrimesView.Length, buffers); diff --git a/PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs b/PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs index 08c1b1e..0294304 100644 --- a/PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs +++ b/PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs @@ -77,8 +77,8 @@ internal static partial class PrimeOrderCalculator ArrayView1D smallPrimeFactorRemainingSlotView = gpu.Input.View; ArrayView1D smallPrimeFactorPrimeSlotsView = gpu.OutputUlong.View; ArrayView1D smallPrimeFactorExponentSlotsView = gpu.OutputInt.View; - ArrayView1D smallPrimeFactorsPrimesView = gpu.SmallPrimeFactorTables.Primes.View; - ArrayView1D smallPrimeFactorsSquaresView = gpu.SmallPrimeFactorTables.Squares.View; + ArrayView1D smallPrimeFactorsPrimesView = gpu.SmallPrimeFactorPrimes; + ArrayView1D smallPrimeFactorsSquaresView = gpu.SmallPrimeFactorSquares; kernelLauncher( stream,