From c4858d28298d6880b81977015190bcd8715a52a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Sat, 11 Oct 2025 18:37:38 +0200 Subject: [PATCH] Dispose GPU execution scope with the kernel lease --- PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs b/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs index d38c0cc..15d4023 100644 --- a/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs +++ b/PerfectNumbers.Core/Gpu/PrimeOrderGpuHeuristics.cs @@ -1715,10 +1715,10 @@ internal static partial class PrimeOrderGpuHeuristics GpuUInt128[]? rentedExponents = null; GpuUInt128[]? rentedResults = null; var lease = GpuKernelPool.GetKernel(useGpuOrder: true); + var execution = lease.EnterExecutionScope(); try { - var execution = lease.EnterExecutionScope(); Accelerator accelerator = lease.Accelerator; AcceleratorStream stream = lease.Stream; var kernel = GetPow2ModWideKernel(accelerator); @@ -1755,7 +1755,6 @@ internal static partial class PrimeOrderGpuHeuristics exponentBuffer.Dispose(); remainderBuffer.Dispose(); - execution.Dispose(); return true; } catch (Exception) @@ -1775,6 +1774,7 @@ internal static partial class PrimeOrderGpuHeuristics ArrayPool.Shared.Return(rentedResults, clearArray: false); } + execution.Dispose(); lease.Dispose(); } }