Add GPU prime tester overload for preallocated buffers
This commit is contained in:
1 parent
f2ce40ade9
commit
6458f6740d
2 files changed
+127
-17
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using FluentAssertions;
|
||||
using ILGPU;
|
||||
using ILGPU.Runtime;
|
||||
using PerfectNumbers.Core.Gpu;
|
||||
using Xunit;
|
||||
|
||||
@@ -27,6 +29,34 @@ 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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user