Various small optimizations

This commit is contained in:
mlemanczyk committed 2025-11-02 11:24:18 +01:00
1 parent 76dfe108a9
commit 07be671726
14 files changed
+206 -276

No files matched your search

+34 -40
View File
@@ -95,49 +95,48 @@ public sealed class PrimeTester
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsPrimeGpu(ulong n)
{
bool forceCpu = GpuContextPool.ForceCpu;
bool belowGpuRange = n < 31UL;
// bool belowGpuRange = n < 31UL;
if (forceCpu || belowGpuRange)
{
// if (belowGpuRange)
// {
return IsPrime(n);
}
// }
var limiter = GpuPrimeWorkLimiter.Acquire();
var gpu = PrimeTesterGpuContextPool.Rent(1);
var accelerator = gpu.Accelerator;
var kernel = gpu.Kernel;
// var limiter = GpuPrimeWorkLimiter.Acquire();
// var gpu = PrimeTesterGpuContextPool.Rent(1);
// var accelerator = gpu.Accelerator;
// var kernel = gpu.Kernel;
ulong value = n;
byte flag = 0;
// ulong value = n;
// byte flag = 0;
var input = gpu.Input;
var output = gpu.Output;
var inputView = input.View;
var outputView = output.View;
// var input = gpu.Input;
// var output = gpu.Output;
// var inputView = input.View;
// var outputView = output.View;
inputView.CopyFromCPU(ref value, 1);
kernel(
1,
inputView,
gpu.DevicePrimesDefault.View,
gpu.DevicePrimesLastOne.View,
gpu.DevicePrimesLastSeven.View,
gpu.DevicePrimesLastThree.View,
gpu.DevicePrimesLastNine.View,
gpu.DevicePrimesPow2Default.View,
gpu.DevicePrimesPow2LastOne.View,
gpu.DevicePrimesPow2LastSeven.View,
gpu.DevicePrimesPow2LastThree.View,
gpu.DevicePrimesPow2LastNine.View,
outputView);
accelerator.Synchronize();
outputView.CopyToCPU(ref flag, 1);
// inputView.CopyFromCPU(ref value, 1);
// kernel(
// 1,
// inputView,
// gpu.DevicePrimesDefault.View,
// gpu.DevicePrimesLastOne.View,
// gpu.DevicePrimesLastSeven.View,
// gpu.DevicePrimesLastThree.View,
// gpu.DevicePrimesLastNine.View,
// gpu.DevicePrimesPow2Default.View,
// gpu.DevicePrimesPow2LastOne.View,
// gpu.DevicePrimesPow2LastSeven.View,
// gpu.DevicePrimesPow2LastThree.View,
// gpu.DevicePrimesPow2LastNine.View,
// outputView);
// accelerator.Synchronize();
// outputView.CopyToCPU(ref flag, 1);
gpu.Dispose();
limiter.Dispose();
// gpu.Dispose();
// limiter.Dispose();
return flag != 0;
// return flag != 0;
}
public static int GpuBatchSize { get; set; } = 262_144;
@@ -147,11 +146,6 @@ public sealed class PrimeTester
public static void WarmUpGpuKernels(int threadCount)
{
if (GpuContextPool.ForceCpu)
{
return;
}
int target = threadCount >> 2;
if (target == 0)
{