From 38d573cdf50d95cfba3e4d166174a3b3238afc8e Mon Sep 17 00:00:00 2001 From: Sun Serega Date: Fri, 8 Dec 2023 21:23:48 +0200 Subject: [PATCH] 4? --- Modules/OpenCLABC.pas | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Modules/OpenCLABC.pas b/Modules/OpenCLABC.pas index 250dfc75..b932950f 100644 --- a/Modules/OpenCLABC.pas +++ b/Modules/OpenCLABC.pas @@ -1380,9 +1380,12 @@ EventRetainReleaseData = record private static procedure RegisterExecCacheTry(command: object; is_new: boolean; descr: string) := ExecCacheTries.GetOrAdd(MakeName(command), name->new ConcurrentQueue<(boolean,string)>).Enqueue((is_new,descr)); + private static procedure DisposeAllCommands; public static procedure ReportExecCache(otp: System.IO.TextWriter := Console.Out) := lock otp do begin + DisposeAllCommands; + otp.WriteLine(System.Environment.StackTrace); foreach var kvp in ExecCacheTries.OrderBy(kvp->kvp.Key) do @@ -10392,13 +10395,19 @@ ExecCommandCLKernelCache = record end; - EnqueueableExecCommand = abstract class(GPUCommand) + EnqueueableExecCommand = abstract class(GPUCommand, IDisposable) private args: array of CLKernelArg; private const_args_setters: array of CLKernelArgSetter; private args_c, args_non_const_c: integer; + {$ifdef ExecDebug} + private static All := new ConcurrentBag>; + {$endif ExecDebug} protected constructor(args: array of CLKernelArg); begin + {$ifdef ExecDebug} + All.Add(new WeakReference(self)); + {$endif ExecDebug} args := args.ToArray; self.args := args; self.const_args_setters := new CLKernelArgSetter[args.Length]; @@ -10538,11 +10547,28 @@ ExecCommandCLKernelCache = record if post_enq_act<>nil then Result.AddAction(post_enq_act); end; - protected procedure Finalize; override := + public procedure Dispose; + begin + if k_cache.data=nil then exit; k_cache.Release({$ifdef ExecDebug}self{$endif}); + GC.SuppressFinalize(self); + end; + protected procedure Finalize; override := Dispose; end; +{$ifdef ExecDebug} +static procedure ExecDebug.DisposeAllCommands := + while true do + begin + var r: WeakReference; + if not EnqueueableExecCommand.All.TryTake(r) then break; + var c: EnqueueableExecCommand; + if not r.TryGetTarget(c) then continue; + c.Dispose; + end; +{$endif ExecDebug} + {$endregion ExecCommand} {$region GetCommand}