Merge remote-tracking branch 'github/codex/optimize-evenperfectbitscanner-for-static-arrays-khd9w8' into work

# Conflicts:
#	PerfectNumbers.Core/Gpu/GpuContextPool.cs
#	PerfectNumbers.Core/Gpu/GpuKernelLease.cs
#	PerfectNumbers.Core/Gpu/GpuKernelPool.cs
#	PerfectNumbers.Core/Gpu/GpuStaticTableInitializer.cs
#	PerfectNumbers.Core/Gpu/Kernels/PrimeOrderSpecialMaxKernels.cs
#	PerfectNumbers.Core/PrimeOrderCalculator.Cpu.cs
#	PerfectNumbers.Core/PrimeOrderCalculator.Gpu.cs
#	PerfectNumbers.Core/PrimeTester.cs
This commit is contained in:
Marek Lemańczyk committed 2025-11-03 23:59:12 +01:00
1 parent 507daaddb9
commit 4c4d4243fb
23 files changed
+858 -633

No files matched your search

+9 -11
View File
@@ -1,4 +1,3 @@
using System;
using System.Collections.Concurrent;
using ILGPU;
using ILGPU.Runtime;
@@ -15,14 +14,12 @@ public static class GpuContextPool
public readonly Context Context;
public readonly Accelerator Accelerator;
private static readonly Context _sharedContext = Context.CreateDefault();
private static readonly Device _sharedDevice = _sharedContext.GetPreferredDevice(false);
private static readonly Accelerator _sharedAccelerator = _sharedDevice.CreateAccelerator(_sharedContext);
public PooledContext()
public PooledContext(KernelContainer kernels)
{
Context = _sharedContext;
Accelerator = _sharedAccelerator;
Context = SharedGpuContext.Context;
Accelerator = SharedGpuContext.Accelerator;
GpuStaticTableInitializer.EnsureStaticTables(kernels, Accelerator);
kernels.Dispose();
// NOTE: Avoid loading/compiling any kernel here to prevent implicit
// CL stream/queue creation during accelerator construction.
// Some OpenCL drivers are fragile when a queue is created immediately
@@ -48,7 +45,7 @@ public static class GpuContextPool
private static int WarmedGpuContextCount;
// Allows callers to choose CPU/GPU per use-case, decoupled from ForceCpu.
public static GpuContextLease Rent()
public static GpuContextLease Rent()
{
if (GpuPool.TryDequeue(out var gpu))
{
@@ -56,7 +53,7 @@ public static class GpuContextPool
}
// Create a new accelerator when the pool does not have one available.
return new GpuContextLease(new PooledContext());
return new GpuContextLease(new PooledContext(GpuKernelPool.GetKernels()));
}
@@ -74,7 +71,8 @@ public static class GpuContextPool
PooledContext context;
for (int i = 0; i < toCreate; i++)
{
context = new PooledContext();
KernelContainer kernels = GpuKernelPool.GetKernels();
context = new PooledContext(kernels);
contexts[i] = context;
pool.Enqueue(context);
}