Reintroduce MulHigh CPU helper and tighten GPU sieve loop

This commit is contained in:
Marek Lemańczyk committed 2025-10-26 23:41:14 +01:00
1 parent e2f68cedf2
commit 9a0e328995
10 files changed
+222 -344

No files matched your search

@@ -121,7 +121,7 @@ public class GpuKernelCompilationTests
private static readonly Action<Index1D, ArrayView1D<ulong, Stride1D.Dense>, ArrayView1D<ulong, Stride1D.Dense>> MersenneDivisorCyclesKernel =
DivisorCycleKernels.GpuDivisorCycleKernel;
private static readonly Action<Index1D, ArrayView<ulong>, ArrayView<uint>, ArrayView<ulong>, ArrayView<byte>> PrimeTesterSmallPrimeKernel =
private static readonly Action<Index1D, ArrayView<ulong>, ArrayView<uint>, ArrayView<byte>> PrimeTesterSmallPrimeKernel =
PrimeTesterKernels.SmallPrimeSieveKernel;
private static readonly Action<Index1D, ArrayView<ulong>, ArrayView<byte>> PrimeTesterSharesFactorKernel =
@@ -336,7 +336,7 @@ public class GpuKernelCompilationTests
private static void CompilePrimeTesterSmallPrimeKernel(Accelerator accelerator)
{
var kernel = accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<ulong>, ArrayView<uint>, ArrayView<ulong>, ArrayView<byte>>(PrimeTesterSmallPrimeKernel);
var kernel = accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<ulong>, ArrayView<uint>, ArrayView<byte>>(PrimeTesterSmallPrimeKernel);
_ = kernel;
}
@@ -1,6 +1,4 @@
using FluentAssertions;
using ILGPU;
using ILGPU.Runtime;
using PerfectNumbers.Core.Gpu;
using Xunit;
@@ -29,34 +27,6 @@ public class PrimeTesterGpuTests
}
}
[Fact]
public void IsPrimeBatchGpu_with_preallocated_resources_marks_expected_values()
{
GpuContextPool.ForceCpu = false;
using var context = Context.CreateDefault();
using var accelerator = context.GetPreferredDevice(false).CreateAccelerator(context);
try
{
ulong[] values = [31UL, 33UL, 37UL, 39UL];
byte[] results = new byte[values.Length];
using var inputBuffer = accelerator.Allocate1D<ulong>(values.Length);
using var outputBuffer = accelerator.Allocate1D<byte>(values.Length);
ulong[] staging = new ulong[values.Length];
PrimeTester.IsPrimeBatchGpu(values, results, accelerator, inputBuffer, outputBuffer, staging);
results.Should().Equal(new byte[] { 1, 0, 1, 0 });
}
finally
{
PrimeTester.ClearGpuCaches(accelerator);
GpuContextPool.ForceCpu = false;
GpuContextPool.DisposeAll();
}
}
[Fact]
public void IsPrimeGpu_rejects_composites()
{