Skip to content

Commit

Permalink
4?
Browse files Browse the repository at this point in the history
  • Loading branch information
SunSerega committed Dec 8, 2023
1 parent 4bf5d89 commit 38d573c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions Modules/OpenCLABC.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -10392,13 +10395,19 @@ ExecCommandCLKernelCache = record

end;

EnqueueableExecCommand = abstract class(GPUCommand<CLKernel>)
EnqueueableExecCommand = abstract class(GPUCommand<CLKernel>, 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<WeakReference<EnqueueableExecCommand>>;
{$endif ExecDebug}

protected constructor(args: array of CLKernelArg);
begin
{$ifdef ExecDebug}
All.Add(new WeakReference<EnqueueableExecCommand>(self));
{$endif ExecDebug}
args := args.ToArray;
self.args := args;
self.const_args_setters := new CLKernelArgSetter[args.Length];
Expand Down Expand Up @@ -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<EnqueueableExecCommand>;
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}
Expand Down

0 comments on commit 38d573c

Please sign in to comment.