Naming improvements and small cleanup
This commit is contained in:
1 parent
bf7c4bab39
commit
66ca969929
10 files changed
+35
-30
No files matched your search
+5
-5
@@ -3,17 +3,17 @@ using ILGPU.Runtime;
|
||||
|
||||
namespace PerfectNumbers.Core.Gpu.Accelerators;
|
||||
|
||||
internal sealed class HeuristicGpuCombinedTables
|
||||
internal readonly struct HeuristicCombinedGpuTables
|
||||
{
|
||||
private static readonly Accelerator[] _accelerators = AcceleratorPool.Shared.Accelerators;
|
||||
|
||||
private static readonly HeuristicGpuCombinedTables[] _sharedTables = new HeuristicGpuCombinedTables[PerfectNumberConstants.RollingAccelerators];
|
||||
private static readonly HeuristicCombinedGpuTables[] _sharedTables = new HeuristicCombinedGpuTables[PerfectNumberConstants.RollingAccelerators];
|
||||
|
||||
internal static void WarmUp(int acceleratorIndex, AcceleratorStream stream) => _sharedTables[acceleratorIndex] = new(_accelerators[acceleratorIndex], stream);
|
||||
|
||||
internal static HeuristicGpuCombinedTables GetStaticTables(int acceleratorIndex) => _sharedTables[acceleratorIndex];
|
||||
internal static HeuristicCombinedGpuTables GetStaticTables(int acceleratorIndex) => _sharedTables[acceleratorIndex];
|
||||
|
||||
internal HeuristicGpuCombinedTables(Accelerator accelerator, AcceleratorStream stream)
|
||||
internal HeuristicCombinedGpuTables(Accelerator accelerator, AcceleratorStream stream)
|
||||
{
|
||||
var combinedEnding1 = HeuristicCombinedPrimeTester.CombinedDivisorsEnding1;
|
||||
HeuristicCombinedDivisorsEnding1 = accelerator.CopySpanToDevice(stream, combinedEnding1);
|
||||
@@ -45,7 +45,7 @@ internal sealed class HeuristicGpuCombinedTables
|
||||
internal readonly MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicCombinedDivisorsEnding9;
|
||||
internal readonly MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicCombinedDivisorSquaresEnding9;
|
||||
|
||||
internal HeuristicGpuCombinedDivisorTables CreateHeuristicDivisorTables() => new(
|
||||
internal HeuristicCombinedGpuViews CreateViews() => new(
|
||||
HeuristicCombinedDivisorsEnding1.View,
|
||||
HeuristicCombinedDivisorsEnding3.View,
|
||||
HeuristicCombinedDivisorsEnding7.View,
|
||||
+5
-5
@@ -3,15 +3,15 @@ using ILGPU.Runtime;
|
||||
|
||||
namespace PerfectNumbers.Core.Gpu.Accelerators;
|
||||
|
||||
internal sealed class HeuristicGpuGroupABTables
|
||||
internal sealed class HeuristicGroupABGpuTables
|
||||
{
|
||||
private static readonly Accelerator[] _accelerators = AcceleratorPool.Shared.Accelerators;
|
||||
|
||||
private static readonly HeuristicGpuGroupABTables[] _sharedTables = new HeuristicGpuGroupABTables[PerfectNumberConstants.RollingAccelerators];
|
||||
private static readonly HeuristicGroupABGpuTables[] _sharedTables = new HeuristicGroupABGpuTables[PerfectNumberConstants.RollingAccelerators];
|
||||
|
||||
private static readonly SemaphoreSlim[] _locks = [..Enumerable.Range(1, PerfectNumberConstants.RollingAccelerators).Select(_ => new SemaphoreSlim(1))];
|
||||
|
||||
internal static HeuristicGpuGroupABTables EnsureStaticTables(int acceleratorIndex, AcceleratorStream stream)
|
||||
internal static HeuristicGroupABGpuTables EnsureStaticTables(int acceleratorIndex, AcceleratorStream stream)
|
||||
{
|
||||
var @lock = _locks[acceleratorIndex];
|
||||
@lock.Wait();
|
||||
@@ -28,7 +28,7 @@ internal sealed class HeuristicGpuGroupABTables
|
||||
return existing;
|
||||
}
|
||||
|
||||
internal HeuristicGpuGroupABTables(Accelerator accelerator, AcceleratorStream stream)
|
||||
internal HeuristicGroupABGpuTables(Accelerator accelerator, AcceleratorStream stream)
|
||||
{
|
||||
var heuristicGroupA = HeuristicPrimeSieves.GroupADivisorsStorage;
|
||||
HeuristicGroupADivisors = accelerator.CopySpanToDevice(stream, heuristicGroupA);
|
||||
@@ -55,7 +55,7 @@ internal sealed class HeuristicGpuGroupABTables
|
||||
internal readonly MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicGroupBDivisorsEnding9;
|
||||
internal readonly MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicGroupBDivisorSquaresEnding9;
|
||||
|
||||
internal HeuristicGpuGroupABDivisorTables CreateHeuristicDivisorTables() => new(
|
||||
internal HeuristicGroupABGpuViews CreateViews() => new(
|
||||
HeuristicGroupADivisors.View,
|
||||
HeuristicGroupADivisorSquares.View,
|
||||
HeuristicGroupBDivisorsEnding1.View,
|
||||
@@ -19,7 +19,7 @@ internal sealed class HeuristicGroupABPrimeTesterAccelerator
|
||||
Console.WriteLine($"Preparing heuristic accelerator {i}...");
|
||||
var accelerator = accelerators[i];
|
||||
AcceleratorStream stream = accelerator.CreateStream();
|
||||
_ = HeuristicGpuGroupABTables.EnsureStaticTables(i, stream);
|
||||
_ = HeuristicGroupABGpuTables.EnsureStaticTables(i, stream);
|
||||
// _ = GpuKernelPool.GetOrAddKernels(accelerator, stream, KernelType.None);
|
||||
// KernelContainer kernels = GpuKernelPool.GetOrAddKernels(accelerator, stream);
|
||||
// GpuStaticTableInitializer.EnsureStaticTables(accelerator, kernels, stream);
|
||||
@@ -75,7 +75,7 @@ internal sealed class HeuristicGroupABPrimeTesterAccelerator
|
||||
|
||||
#endregion
|
||||
|
||||
public readonly HeuristicGpuGroupABDivisorTables DivisorTables;
|
||||
public readonly HeuristicGroupABGpuViews DivisorTables;
|
||||
internal readonly Context Context;
|
||||
public readonly Accelerator Accelerator;
|
||||
|
||||
@@ -102,7 +102,7 @@ internal sealed class HeuristicGroupABPrimeTesterAccelerator
|
||||
public MemoryBuffer1D<int, Stride1D.Dense>? HeuristicFlag = null!;
|
||||
public int BufferCapacity;
|
||||
|
||||
private HeuristicGpuGroupABTables _sharedTables;
|
||||
private HeuristicGroupABGpuTables _sharedTables;
|
||||
public MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicGroupADivisors => _sharedTables.HeuristicGroupADivisors;
|
||||
public MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicGroupADivisorSquares => _sharedTables.HeuristicGroupADivisorSquares;
|
||||
public MemoryBuffer1D<ulong, Stride1D.Dense> HeuristicGroupBDivisorsEnding1 => _sharedTables.HeuristicGroupBDivisorsEnding1;
|
||||
@@ -125,14 +125,14 @@ internal sealed class HeuristicGroupABPrimeTesterAccelerator
|
||||
Accelerator = accelerator;
|
||||
EnsureCapacity(minBufferCapacity);
|
||||
|
||||
HeuristicTrialDivisionKernel = KernelUtil.GetKernel(accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<int>, ulong, ulong, HeuristicGpuDivisorTableKind, HeuristicGpuGroupABDivisorTables>(PrimeTesterKernels.HeuristicTrialGroupABDivisionKernel));
|
||||
HeuristicTrialDivisionKernel = KernelUtil.GetKernel(accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<int>, ulong, ulong, HeuristicGpuDivisorTableKind, HeuristicGroupABGpuViews>(PrimeTesterKernels.HeuristicTrialGroupABDivisionKernel));
|
||||
|
||||
AcceleratorStream stream = AcceleratorStreamPool.Rent(acceleratorIndex);
|
||||
|
||||
// GpuStaticTableInitializer.EnsureStaticTables(accelerator, kernels, stream);
|
||||
|
||||
_sharedTables = HeuristicGpuGroupABTables.EnsureStaticTables(acceleratorIndex, stream);
|
||||
DivisorTables = _sharedTables.CreateHeuristicDivisorTables();
|
||||
_sharedTables = HeuristicGroupABGpuTables.EnsureStaticTables(acceleratorIndex, stream);
|
||||
DivisorTables = _sharedTables.CreateViews();
|
||||
|
||||
stream.Synchronize();
|
||||
AcceleratorStreamPool.Return(acceleratorIndex, stream);
|
||||
|
||||
@@ -69,7 +69,7 @@ public sealed class PrimeOrderCalculatorAccelerator
|
||||
AcceleratorStream stream = accelerator.CreateStream();
|
||||
// TODO: Review which tables are needed when final execution path is defined.
|
||||
LastDigitGpuTables.WarmUp(i, stream);
|
||||
HeuristicGpuCombinedTables.WarmUp(i, stream);
|
||||
HeuristicCombinedGpuTables.WarmUp(i, stream);
|
||||
// SmallPrimeFactorGpuTables.WarmUp(i, stream);
|
||||
// SharedHeuristicGpuTables.EnsureStaticTables(accelerator, stream);
|
||||
// _ = GpuKernelPool.GetOrAddKernels(accelerator, stream, KernelType.None);
|
||||
@@ -111,8 +111,9 @@ public sealed class PrimeOrderCalculatorAccelerator
|
||||
public readonly MemoryBuffer1D<int, Stride1D.Dense> SmallPrimeFactorCountSlot;
|
||||
public readonly MemoryBuffer1D<ulong, Stride1D.Dense> SpecialMaxResult;
|
||||
|
||||
public readonly HeuristicGpuCombinedDivisorTables DivisorTables;
|
||||
public readonly SmallPrimeFactorGpuTables SmallPrimeFactorTables;
|
||||
public readonly HeuristicCombinedGpuViews DivisorTables;
|
||||
public readonly MemoryBuffer1D<uint, Stride1D.Dense> SmallPrimeFactorPrimes;
|
||||
public readonly MemoryBuffer1D<ulong, Stride1D.Dense> SmallPrimeFactorSquares;
|
||||
|
||||
public readonly Kernel CheckFactorsKernel;
|
||||
public readonly Kernel ConvertToStandardKernel;
|
||||
@@ -217,9 +218,13 @@ public sealed class PrimeOrderCalculatorAccelerator
|
||||
DevicePrimesPow2LastThree = lastDigitSharedTables.DevicePrimesPow2LastThree;
|
||||
DevicePrimesPow2LastNine = lastDigitSharedTables.DevicePrimesPow2LastNine;
|
||||
|
||||
var heuristicSharedTables = HeuristicGpuCombinedTables.GetStaticTables(acceleratorIndex);
|
||||
DivisorTables = heuristicSharedTables.CreateHeuristicDivisorTables();
|
||||
SmallPrimeFactorTables = SmallPrimeFactorGpuTables.GetStaticTables(acceleratorIndex);
|
||||
var heuristicSharedTables = HeuristicCombinedGpuTables.GetStaticTables(acceleratorIndex);
|
||||
|
||||
DivisorTables = heuristicSharedTables.CreateViews();
|
||||
|
||||
var smallPrimeFactorTables = SmallPrimeFactorGpuTables.GetStaticTables(acceleratorIndex);
|
||||
SmallPrimeFactorPrimes = smallPrimeFactorTables.Primes;
|
||||
SmallPrimeFactorSquares = smallPrimeFactorTables.Squares;
|
||||
|
||||
var checkFactorsKernel = accelerator.LoadStreamKernel<int, ulong, ArrayView1D<KeyValuePair<ulong, int>, Stride1D.Dense>, MontgomeryDivisorData, ArrayView1D<ulong, Stride1D.Dense>>(PrimeOrderGpuHeuristics.CheckFactorsKernel);
|
||||
CheckFactorsKernel = KernelUtil.GetKernel(checkFactorsKernel);
|
||||
@@ -227,7 +232,7 @@ public sealed class PrimeOrderCalculatorAccelerator
|
||||
var convertKernel = accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView1D<ulong, Stride1D.Dense>, MontgomeryDivisorData, ArrayView1D<ulong, Stride1D.Dense>>(Pow2MontgomeryKernels.Pow2MontgomeryKernelConvertToStandard);
|
||||
ConvertToStandardKernel = KernelUtil.GetKernel(convertKernel);
|
||||
|
||||
HeuristicCombinedTrialDivisionKernel = KernelUtil.GetKernel(accelerator.LoadAutoGroupedStreamKernel<Index1D, byte, ArrayView<int>, ulong, ulong, HeuristicGpuCombinedDivisorTables>(PrimeTesterKernels.HeuristicTrialCombinedDivisionKernel));
|
||||
HeuristicCombinedTrialDivisionKernel = KernelUtil.GetKernel(accelerator.LoadAutoGroupedStreamKernel<Index1D, byte, ArrayView<int>, ulong, ulong, HeuristicCombinedGpuViews>(PrimeTesterKernels.HeuristicTrialCombinedDivisionKernel));
|
||||
|
||||
var keepKernel = accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView1D<ulong, Stride1D.Dense>, MontgomeryDivisorData, ArrayView1D<ulong, Stride1D.Dense>>(Pow2MontgomeryKernels.Pow2MontgomeryKernelKeepMontgomery);
|
||||
KeepMontgomeryKernel = KernelUtil.GetKernel(keepKernel);
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ using ILGPU.Runtime;
|
||||
|
||||
namespace PerfectNumbers.Core.Gpu;
|
||||
|
||||
public readonly struct HeuristicGpuCombinedDivisorTables(
|
||||
public readonly struct HeuristicCombinedGpuViews(
|
||||
ArrayView1D<ulong, Stride1D.Dense> combinedDivisorsEnding1,
|
||||
ArrayView1D<ulong, Stride1D.Dense> combinedDivisorsEnding3,
|
||||
ArrayView1D<ulong, Stride1D.Dense> combinedDivisorsEnding7,
|
||||
+1
-1
@@ -4,7 +4,7 @@ using ILGPU.Runtime;
|
||||
|
||||
namespace PerfectNumbers.Core.Gpu;
|
||||
|
||||
public readonly struct HeuristicGpuGroupABDivisorTables(
|
||||
public readonly struct HeuristicGroupABGpuViews(
|
||||
ArrayView1D<ulong, Stride1D.Dense> groupADivisors,
|
||||
ArrayView1D<ulong, Stride1D.Dense> groupADivisorSquares,
|
||||
ArrayView1D<ulong, Stride1D.Dense> groupBDivisorsEnding1,
|
||||
@@ -83,7 +83,7 @@ internal static class PrimeTesterKernels
|
||||
ArrayView<int> resultFlag,
|
||||
ulong n,
|
||||
ulong maxDivisorSquare,
|
||||
HeuristicGpuCombinedDivisorTables tables)
|
||||
HeuristicCombinedGpuViews tables)
|
||||
{
|
||||
// byte nMod10 = (byte)(n % 10UL);
|
||||
ArrayView1D<ulong, Stride1D.Dense> divisors = tables.SelectDivisors(nMod10);
|
||||
@@ -116,7 +116,7 @@ internal static class PrimeTesterKernels
|
||||
ulong n,
|
||||
ulong maxDivisorSquare,
|
||||
HeuristicGpuDivisorTableKind tableKind,
|
||||
HeuristicGpuGroupABDivisorTables tables)
|
||||
HeuristicGroupABGpuViews tables)
|
||||
{
|
||||
ArrayView1D<ulong, Stride1D.Dense> divisors = tables.SelectDivisors(tableKind);
|
||||
ArrayView1D<ulong, Stride1D.Dense> divisorSquares = tables.SelectDivisorSquares(tableKind);
|
||||
|
||||
@@ -3,8 +3,8 @@ using ILGPU;
|
||||
using ILGPU.Runtime;
|
||||
|
||||
namespace PerfectNumbers.Core.Gpu;
|
||||
|
||||
public readonly struct SmallPrimeFactorGpuTables
|
||||
|
||||
{
|
||||
private static readonly Accelerator[] _accelerators = AcceleratorPool.Shared.Accelerators;
|
||||
private static readonly SmallPrimeFactorGpuTables[] _sharedTables = new SmallPrimeFactorGpuTables[PerfectNumberConstants.RollingAccelerators];
|
||||
|
||||
Reference in new issue
Block a user