Use GpuPrimeWorkLimiter for GPU lease limiting

This commit is contained in:
Marek Lemańczyk committed 2025-11-02 14:02:15 +01:00
1 parent 00d4e9bde2
commit 1cbe7bf869
5 files changed
+42 -93

No files matched your search

+7 -17
View File
@@ -48,27 +48,18 @@ 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()
{
GpuPrimeLeaseLimiter.Enter();
try
if (GpuPool.TryDequeue(out var gpu))
{
if (GpuPool.TryDequeue(out var gpu))
{
return new GpuContextLease(gpu);
}
return new GpuContextLease(gpu);
}
// Create a new accelerator when the pool does not have one available.
return new GpuContextLease(new PooledContext());
}
catch
{
GpuPrimeLeaseLimiter.Exit();
throw;
}
// Create a new accelerator when the pool does not have one available.
return new GpuContextLease(new PooledContext());
}
public static void WarmUpPool(int threadCount)
{
if (threadCount <= WarmedGpuContextCount)
@@ -106,7 +97,6 @@ public static class GpuContextPool
{
ctx.Accelerator.Synchronize();
GpuPool.Enqueue(ctx);
GpuPrimeLeaseLimiter.Exit();
}
public struct GpuContextLease