Use GpuPrimeWorkLimiter for GPU lease limiting
This commit is contained in:
1 parent
00d4e9bde2
commit
1cbe7bf869
5 files changed
+42
-93
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user