Skip to content

Commit

Permalink
hotfixes cleanup for 2001
Browse files Browse the repository at this point in the history
update to #2
  • Loading branch information
SunSerega committed Jun 21, 2019
1 parent df7f52d commit 3fa1056
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions OpenCLABC.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ interface
//ToDo issue компилятора:
// - #1958
// - #1981
// - #1998
// - #1999
// - #2001

type

Expand Down Expand Up @@ -636,10 +634,9 @@ function CommandQueueHostFunc<T>.Invoke(c: Context; cq: cl_command_queue; prev_e
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_prev_ev := @prev_ev; //ToDo #1998
yield Task.Run(()->
begin
if prev_ev<>cl_event.Zero then cl.WaitForEvents(1,костыль_для_prev_ev).RaiseIfError;
if prev_ev<>cl_event.Zero then cl.WaitForEvents(1,@prev_ev).RaiseIfError;
if self.f<>nil then self.res := self.f();

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down Expand Up @@ -821,15 +818,14 @@ function CommandQueueHostFunc<T>.Invoke(c: Context; cq: cl_command_queue; prev_e
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_cq := cq; //ToDo #2001
yield Task.Run(()->
begin
if ev_lst.Count<>0 then cl.WaitForEvents(ev_lst.Count, ev_lst.ToArray).RaiseIfError;

var buff_ev: cl_event;
if prev.ev=cl_event.Zero then
cl.EnqueueWriteBuffer(костыль_для_cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), ptr.res, 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueWriteBuffer(костыль_для_cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), ptr.res, 1,@prev.ev,@buff_ev).RaiseIfError;
cl.EnqueueWriteBuffer(cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), ptr.res, 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueWriteBuffer(cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), ptr.res, 1,@prev.ev,@buff_ev).RaiseIfError;
cl.WaitForEvents(1, @buff_ev).RaiseIfError;

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down Expand Up @@ -871,7 +867,6 @@ function CommandQueueHostFunc<T>.Invoke(c: Context; cq: cl_command_queue; prev_e
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_cq := cq; //ToDo #2001
yield Task.Run(()->
begin
if a.ev<>cl_event.Zero then cl.WaitForEvents(1,@a.ev).RaiseIfError;
Expand All @@ -881,8 +876,8 @@ function CommandQueueHostFunc<T>.Invoke(c: Context; cq: cl_command_queue; prev_e

var buff_ev: cl_event;
if prev.ev=cl_event.Zero then
cl.EnqueueWriteBuffer(костыль_для_cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), gchnd.AddrOfPinnedObject, 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueWriteBuffer(костыль_для_cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), gchnd.AddrOfPinnedObject, 1,@prev.ev,@buff_ev).RaiseIfError;
cl.EnqueueWriteBuffer(cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), gchnd.AddrOfPinnedObject, 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueWriteBuffer(cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), gchnd.AddrOfPinnedObject, 1,@prev.ev,@buff_ev).RaiseIfError;
cl.WaitForEvents(1,@buff_ev).RaiseIfError;

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down Expand Up @@ -940,15 +935,14 @@ function KernelArgCommandQueue.WriteData(a: CommandQueue<&Array>) := WriteData(a
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_cq := cq; //ToDo #2001
yield Task.Run(()->
begin
if ev_lst.Count<>0 then cl.WaitForEvents(ev_lst.Count, ev_lst.ToArray).RaiseIfError;

var buff_ev: cl_event;
if prev.ev=cl_event.Zero then
cl.EnqueueReadBuffer(костыль_для_cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), ptr.res, 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueReadBuffer(костыль_для_cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), ptr.res, 1,@prev.ev,@buff_ev).RaiseIfError;
cl.EnqueueReadBuffer(cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), ptr.res, 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueReadBuffer(cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), ptr.res, 1,@prev.ev,@buff_ev).RaiseIfError;
cl.WaitForEvents(1, @buff_ev).RaiseIfError;

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down Expand Up @@ -990,7 +984,6 @@ function KernelArgCommandQueue.WriteData(a: CommandQueue<&Array>) := WriteData(a
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_cq := cq; //ToDo #2001
yield Task.Run(()->
begin
if a.ev<>cl_event.Zero then cl.WaitForEvents(1,@a.ev).RaiseIfError;
Expand All @@ -1000,8 +993,8 @@ function KernelArgCommandQueue.WriteData(a: CommandQueue<&Array>) := WriteData(a

var buff_ev: cl_event;
if prev.ev=cl_event.Zero then
cl.EnqueueReadBuffer(костыль_для_cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), gchnd.AddrOfPinnedObject, 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueReadBuffer(костыль_для_cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), gchnd.AddrOfPinnedObject, 1,@prev.ev,@buff_ev).RaiseIfError;
cl.EnqueueReadBuffer(cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), gchnd.AddrOfPinnedObject, 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueReadBuffer(cq, org.memobj, 0, new UIntPtr(offset.res), new UIntPtr(len.res), gchnd.AddrOfPinnedObject, 1,@prev.ev,@buff_ev).RaiseIfError;
cl.WaitForEvents(1,@buff_ev).RaiseIfError;

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down Expand Up @@ -1061,15 +1054,14 @@ function KernelArgCommandQueue.ReadData(a: CommandQueue<&Array>) := ReadData(a,
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_cq := cq; //ToDo #2001
yield Task.Run(()->
begin
if ev_lst.Count<>0 then cl.WaitForEvents(ev_lst.Count, ev_lst.ToArray).RaiseIfError;

var buff_ev: cl_event;
if prev.ev=cl_event.Zero then
cl.EnqueueFillBuffer(костыль_для_cq, org.memobj, ptr.res,new UIntPtr(pattern_len.res), new UIntPtr(offset.res),new UIntPtr(len.res), 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueFillBuffer(костыль_для_cq, org.memobj, ptr.res,new UIntPtr(pattern_len.res), new UIntPtr(offset.res),new UIntPtr(len.res), 1,@prev.ev,@buff_ev).RaiseIfError;
cl.EnqueueFillBuffer(cq, org.memobj, ptr.res,new UIntPtr(pattern_len.res), new UIntPtr(offset.res),new UIntPtr(len.res), 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueFillBuffer(cq, org.memobj, ptr.res,new UIntPtr(pattern_len.res), new UIntPtr(offset.res),new UIntPtr(len.res), 1,@prev.ev,@buff_ev).RaiseIfError;
cl.WaitForEvents(1, @buff_ev).RaiseIfError;

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down Expand Up @@ -1111,7 +1103,6 @@ function KernelArgCommandQueue.ReadData(a: CommandQueue<&Array>) := ReadData(a,
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_cq := cq; //ToDo #2001
yield Task.Run(()->
begin
if a.ev<>cl_event.Zero then cl.WaitForEvents(1,@a.ev).RaiseIfError;
Expand All @@ -1122,8 +1113,8 @@ function KernelArgCommandQueue.ReadData(a: CommandQueue<&Array>) := ReadData(a,

var buff_ev: cl_event;
if prev.ev=cl_event.Zero then
cl.EnqueueFillBuffer(костыль_для_cq, org.memobj, gchnd.AddrOfPinnedObject,new UIntPtr(pattern_sz), new UIntPtr(offset.res),new UIntPtr(len.res), 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueFillBuffer(костыль_для_cq, org.memobj, gchnd.AddrOfPinnedObject,new UIntPtr(pattern_sz), new UIntPtr(offset.res),new UIntPtr(len.res), 1,@prev.ev,@buff_ev).RaiseIfError;
cl.EnqueueFillBuffer(cq, org.memobj, gchnd.AddrOfPinnedObject,new UIntPtr(pattern_sz), new UIntPtr(offset.res),new UIntPtr(len.res), 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueFillBuffer(cq, org.memobj, gchnd.AddrOfPinnedObject,new UIntPtr(pattern_sz), new UIntPtr(offset.res),new UIntPtr(len.res), 1,@prev.ev,@buff_ev).RaiseIfError;
cl.WaitForEvents(1,@buff_ev).RaiseIfError;

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down Expand Up @@ -1185,15 +1176,14 @@ function KernelArgCommandQueue.PatternFill(a: CommandQueue<&Array>) := PatternFi
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_cq := cq; //ToDo #2001
yield Task.Run(()->
begin
if ev_lst.Count<>0 then cl.WaitForEvents(ev_lst.Count, ev_lst.ToArray).RaiseIfError;

var buff_ev: cl_event;
if prev.ev=cl_event.Zero then
cl.EnqueueCopyBuffer(костыль_для_cq, f_arg.res.memobj,t_arg.res.memobj, new UIntPtr(f_pos.res),new UIntPtr(t_pos.res), new UIntPtr(len.res), 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueCopyBuffer(костыль_для_cq, f_arg.res.memobj,t_arg.res.memobj, new UIntPtr(f_pos.res),new UIntPtr(t_pos.res), new UIntPtr(len.res), 1,@prev.ev,@buff_ev).RaiseIfError;
cl.EnqueueCopyBuffer(cq, f_arg.res.memobj,t_arg.res.memobj, new UIntPtr(f_pos.res),new UIntPtr(t_pos.res), new UIntPtr(len.res), 0,nil,@buff_ev).RaiseIfError else
cl.EnqueueCopyBuffer(cq, f_arg.res.memobj,t_arg.res.memobj, new UIntPtr(f_pos.res),new UIntPtr(t_pos.res), new UIntPtr(len.res), 1,@prev.ev,@buff_ev).RaiseIfError;
cl.WaitForEvents(1, @buff_ev).RaiseIfError;

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down Expand Up @@ -1282,20 +1272,18 @@ function KernelArgCommandQueue.CopyTo(arg: CommandQueue<KernelArg>) := CopyTo(ar
self.ev := cl.CreateUserEvent(c._context, ec);
ec.RaiseIfError;

var костыль_для_c := c; //ToDo #2001
var костыль_для_cq := cq; //ToDo #2001
yield Task.Run(()->
begin
if ev_lst.Count<>0 then cl.WaitForEvents(ev_lst.Count,ev_lst.ToArray);

for var i := 0 to args_q.Length-1 do
begin
if args_q[i].res.memobj=cl_mem.Zero then args_q[i].res.Init(костыль_для_c);
if args_q[i].res.memobj=cl_mem.Zero then args_q[i].res.Init(c);
cl.SetKernelArg(org._kernel, i, new UIntPtr(UIntPtr.Size), args_q[i].res.memobj).RaiseIfError;
end;

var kernel_ev: cl_event;
cl.EnqueueNDRangeKernel(костыль_для_cq, org._kernel, work_szs.Length, nil,work_szs,nil, 0,nil,@kernel_ev).RaiseIfError; // prev.ev уже в ev_lst, тут проверять не надо
cl.EnqueueNDRangeKernel(cq, org._kernel, work_szs.Length, nil,work_szs,nil, 0,nil,@kernel_ev).RaiseIfError; // prev.ev уже в ev_lst, тут проверять не надо
cl.WaitForEvents(1,@kernel_ev).RaiseIfError;

cl.SetUserEventStatus(self.ev, CommandExecutionStatus.COMPLETE).RaiseIfError;
Expand Down

0 comments on commit 3fa1056

Please sign in to comment.