Skip to content

Commit

Permalink
Mandelbrot example +1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunSerega committed Dec 28, 2023
1 parent 21c1cac commit ef1b659
Show file tree
Hide file tree
Showing 24 changed files with 2,126 additions and 752 deletions.
2 changes: 1 addition & 1 deletion DataScraping/Reps/OpenCL-Docs
Submodule OpenCL-Docs updated from 81ad45 to 2d470a
32 changes: 31 additions & 1 deletion LastPack.log
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ Tester: Compiling "Samples/OpenCLABC/Кеширование CLProgramCode/Simple
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/!Крутящийся треугольник/Крутящийся треугольник.pas"
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/Mandelbrot/0Mandelbrot.pas"
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/Mandelbrot/FieldTest.pas"
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/Mandelbrot/SamplingTests.pas"
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/Точки на поле/Точки.pas"
Tester: Compiling: OK
Tester: Switched to platform "NVIDIA CUDA" and using 1 devices
Expand Down Expand Up @@ -832,6 +838,10 @@ Tester: Executing Test[Samples/OpenCLABC/Кеширование CLProgramCode/Si
Tester: Done executing
Tester: Executing Test[Samples/OpenCLABC/Кеширование CLProgramCode/SimpleAddition но с кешем]
Tester: Done executing
Tester: Executing Test[Samples/OpenGLABC/Mandelbrot/FieldTest]
Tester: Done executing
Tester: Executing Test[Samples/OpenGLABC/Mandelbrot/SamplingTests]
Tester: Done executing
Tester: Switched to platform "Intel(R) OpenCL" and using 1 devices
Tester: Executing Test[Tests/Exec/CL/ToString]
Tester: Done executing
Expand Down Expand Up @@ -1041,6 +1051,10 @@ Tester: Executing Test[Samples/OpenCLABC/Кеширование CLProgramCode/Si
Tester: Done executing
Tester: Executing Test[Samples/OpenCLABC/Кеширование CLProgramCode/SimpleAddition но с кешем]
Tester: Done executing
Tester: Executing Test[Samples/OpenGLABC/Mandelbrot/FieldTest]
Tester: Done executing
Tester: Executing Test[Samples/OpenGLABC/Mandelbrot/SamplingTests]
Tester: Done executing
Tester: Cleanup
Tester: Done testing
Finished runing Tester
Expand Down Expand Up @@ -1070,6 +1084,22 @@ Packing sample file "Samples/OpenCLABC/Кеширование CLProgramCode/Simp
Packing sample file "Samples/OpenGLABC/Common.pas"
Packing sample file "Samples/OpenGLABC/!Крутящийся треугольник/Крутящийся треугольник.pas"
Packing sample file "Samples/OpenGLABC/!Крутящийся треугольник/Крутящийся треугольник.vert"
Packing sample file "Samples/OpenGLABC/Mandelbrot/0Mandelbrot.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Blocks.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/CameraDef.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/FieldTest.bmp"
Packing sample file "Samples/OpenGLABC/Mandelbrot/FieldTest.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/GL_CL_Context.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/MandelbrotSampling.cl"
Packing sample file "Samples/OpenGLABC/Mandelbrot/MandelbrotSampling.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/MemoryLayering.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/PointComponents.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/SamplingTests.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Settings.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/SheetTransfer.cl"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Shaders/Box.geom"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Shaders/Empty.vert"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Shaders/Rainbow.frag"
Packing sample file "Samples/OpenGLABC/Точки на поле/Empty.vert"
Packing sample file "Samples/OpenGLABC/Точки на поле/Mandelbrot.frag"
Packing sample file "Samples/OpenGLABC/Точки на поле/SinglePointToScreen.geom"
Expand All @@ -1079,5 +1109,5 @@ Packing sample file "Samples/OpenGLABC/Точки на поле/Минимум
Packing sample file "Samples/OpenGLABC/Точки на поле/Спирали.frag"
Packing sample file "Samples/OpenGLABC/Точки на поле/Сумма расстояний.frag"
Packing sample file "Samples/OpenGLABC/Точки на поле/Точки.pas"
Packed 27 sample files
Packed 43 sample files
Done packing
18 changes: 17 additions & 1 deletion Log/Release.log
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ Packing sample file "Samples/OpenCLABC/Кеширование CLProgramCode/Simp
Packing sample file "Samples/OpenGLABC/Common.pas"
Packing sample file "Samples/OpenGLABC/!Крутящийся треугольник/Крутящийся треугольник.pas"
Packing sample file "Samples/OpenGLABC/!Крутящийся треугольник/Крутящийся треугольник.vert"
Packing sample file "Samples/OpenGLABC/Mandelbrot/0Mandelbrot.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Blocks.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/CameraDef.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/FieldTest.bmp"
Packing sample file "Samples/OpenGLABC/Mandelbrot/FieldTest.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/GL_CL_Context.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/MandelbrotSampling.cl"
Packing sample file "Samples/OpenGLABC/Mandelbrot/MandelbrotSampling.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/MemoryLayering.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/PointComponents.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/SamplingTests.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Settings.pas"
Packing sample file "Samples/OpenGLABC/Mandelbrot/SheetTransfer.cl"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Shaders/Box.geom"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Shaders/Empty.vert"
Packing sample file "Samples/OpenGLABC/Mandelbrot/Shaders/Rainbow.frag"
Packing sample file "Samples/OpenGLABC/Точки на поле/Empty.vert"
Packing sample file "Samples/OpenGLABC/Точки на поле/Mandelbrot.frag"
Packing sample file "Samples/OpenGLABC/Точки на поле/SinglePointToScreen.geom"
Expand All @@ -32,4 +48,4 @@ Packing sample file "Samples/OpenGLABC/Точки на поле/Минимум
Packing sample file "Samples/OpenGLABC/Точки на поле/Спирали.frag"
Packing sample file "Samples/OpenGLABC/Точки на поле/Сумма расстояний.frag"
Packing sample file "Samples/OpenGLABC/Точки на поле/Точки.pas"
Packed 27 sample files
Packed 43 sample files
10 changes: 10 additions & 0 deletions Log/Test.log
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ Tester: Compiling "Samples/OpenCLABC/Кеширование CLProgramCode/Simple
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/!Крутящийся треугольник/Крутящийся треугольник.pas"
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/Mandelbrot/0Mandelbrot.pas"
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/Mandelbrot/FieldTest.pas"
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/Mandelbrot/SamplingTests.pas"
Tester: Compiling: OK
Tester: Compiling "Samples/OpenGLABC/Точки на поле/Точки.pas"
Tester: Compiling: OK
Tester: Executing Test[Tests/Exec/CL/ToString]
Expand Down Expand Up @@ -439,6 +445,10 @@ Tester: Executing Test[Samples/OpenCLABC/Кеширование CLProgramCode/Si
Tester: Done executing
Tester: Executing Test[Samples/OpenCLABC/Кеширование CLProgramCode/SimpleAddition но с кешем]
Tester: Done executing
Tester: Executing Test[Samples/OpenGLABC/Mandelbrot/FieldTest]
Tester: Done executing
Tester: Executing Test[Samples/OpenGLABC/Mandelbrot/SamplingTests]
Tester: Done executing
Tester: Cleanup
Tester: Done testing
Finished runing Tester
49 changes: 41 additions & 8 deletions Modules.Packed/OpenCLABC.pas
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
//===================================
// Обязательно сделать до следующей стабильной версии:

//TODO Сеттеры параметров не всегда известно, нужны ли
// - Добавить параметр "unuse_is_error := true"

//TODO При создании CLArray и т.п. указывается map_use, но влияет он и на .ReadArray и т.п.
// - Перетестить и переименовать... host_use?

//TODO Если кинуло AggEx, возвращать из тестов его внутренний массив исключений
// - TestExecutor сейчас возвращает исключение текстом... Ужас
//TODO Устечка памяти в виде ивентов после исключения в очереди
Expand Down Expand Up @@ -1525,15 +1531,15 @@ EventRetainReleaseData = record

CLMemoryObserver = static class

public static auto property &Default: MemoryObserver := new EmptyMemoryObserver;
public static auto property Current: MemoryObserver := new EmptyMemoryObserver;

private static procedure ReportFree(ntv: cl_mem{$ifdef DEBUG}; mem_obj: object{$endif});
begin
var sz: UIntPtr;
OpenCLABCInternalException.RaiseIfError(
cl.GetMemObjectInfo_MEM_SIZE(ntv, sz)
);
&Default.RemoveMemoryUse(sz.ToUInt64, {$ifdef DEBUG}mem_obj{$else}ntv{$endif});
Current.RemoveMemoryUse(sz.ToUInt64, {$ifdef DEBUG}mem_obj{$else}ntv{$endif});
end;

end;
Expand Down Expand Up @@ -4213,6 +4219,25 @@ CLProgramLinkOptions = class(CLProgramOptions)
begin
self.code := code;
self.k_name := k_name;

// Create one instance, to check if everything is valid
var ec: clErrorCode;
var k := cl.CreateKernel(code.ntv, k_name, ec);

if ec.IS_ERROR then
begin
if ec=clErrorCode.INVALID_KERNEL_NAME then
begin
var names: string;
OpenCLABCInternalException.RaiseIfError(
cl.GetProgramInfo_PROGRAM_KERNEL_NAMES(code.ntv, names)
);
raise new OpenCLABCInternalException($'Kernel [{k_name}] is not defined in {code}. Existing kernel names: {names}');
end;
OpenCLABCInternalException.RaiseIfError(ec);
end;

AddExistingNative(k);
end;

public constructor(ntv: cl_kernel);
Expand Down Expand Up @@ -4369,7 +4394,7 @@ CLMemoryUsage = record
self.ntv := cl.CreateBuffer(c.ntv, CLMemoryUsage.MakeCLFlags(kernel_use,map_use), size, nil, ec);
OpenCLABCInternalException.RaiseIfError(ec);

CLMemoryObserver.Default.AddMemoryUse(size.ToUInt64, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});
CLMemoryObserver.Current.AddMemoryUse(size.ToUInt64, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});

end;
public constructor(size: integer; c: CLContext; kernel_use: CLMemoryUsage := CLMemoryUsage.read_write_bits; map_use: CLMemoryUsage := CLMemoryUsage.read_write_bits) :=
Expand Down Expand Up @@ -5042,7 +5067,7 @@ CLMemoryUsage = record
self.ntv := cl.CreateBuffer(c.ntv, CLMemoryUsage.MakeCLFlags(kernel_use,map_use), new UIntPtr(ValueSize), nil, ec);
OpenCLABCInternalException.RaiseIfError(ec);

CLMemoryObserver.Default.AddMemoryUse(ValueSize, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});
CLMemoryObserver.Current.AddMemoryUse(ValueSize, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});

end;
public constructor(c: CLContext; val: T; kernel_use: CLMemoryUsage := CLMemoryUsage.read_write_bits; map_use: CLMemoryUsage := CLMemoryUsage.read_write_bits);
Expand All @@ -5052,7 +5077,7 @@ CLMemoryUsage = record
self.ntv := cl.CreateBuffer(c.ntv, CLMemoryUsage.MakeCLFlags(kernel_use,map_use) + clMemFlags.MEM_COPY_HOST_PTR, new UIntPtr(ValueSize), val, ec);
OpenCLABCInternalException.RaiseIfError(ec);

CLMemoryObserver.Default.AddMemoryUse(ValueSize, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});
CLMemoryObserver.Current.AddMemoryUse(ValueSize, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});

end;

Expand Down Expand Up @@ -5172,7 +5197,7 @@ CLMemoryUsage = record
self.ntv := cl.CreateBuffer(c.ntv, CLMemoryUsage.MakeCLFlags(kernel_use,map_use), new UIntPtr(ByteSize), nil, ec);
OpenCLABCInternalException.RaiseIfError(ec);

CLMemoryObserver.Default.AddMemoryUse(ByteSize, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});
CLMemoryObserver.Current.AddMemoryUse(ByteSize, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});

end;
private procedure InitByVal(c: CLContext; var els: T; kernel_use, map_use: CLMemoryUsage);
Expand All @@ -5182,7 +5207,7 @@ CLMemoryUsage = record
self.ntv := cl.CreateBuffer(c.ntv, CLMemoryUsage.MakeCLFlags(kernel_use,map_use) + clMemFlags.MEM_COPY_HOST_PTR, new UIntPtr(ByteSize), els, ec);
OpenCLABCInternalException.RaiseIfError(ec);

CLMemoryObserver.Default.AddMemoryUse(ByteSize, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});
CLMemoryObserver.Current.AddMemoryUse(ByteSize, {$ifdef DEBUG}new CLMemoryAlloc(self, ntv){$else}ntv{$endif});

end;

Expand Down Expand Up @@ -37491,6 +37516,12 @@ GLIteropApiBlock = record
var prev_ev := l.AttachInvokeActions(g{$ifdef EventDebug}, l{$endif});
var res_ev: cl_event;
InvokeImpl(api_block, g.GetCQ(false), ntv_mem_objs, prev_ev, res_ev);
//TODO Проверить и сделать всё релевантное из EnqueueableCore
// - В частности что если enq_ev=0 из за предыдущих ошибок? Может ли тут NV тоже отказываться давать ивент?
// - И сделать issue в OpenCL-Docs об этом, типа кто прав (или оба?)
{$ifdef EventDebug}
EventDebug.RegisterEventRetain(res_ev, $'Enq by {TypeName(self)}, waiting on: {prev_ev.evs?.Take(prev_ev.count).JoinToString}');
{$endif EventDebug}
Result := new QueueResNil(prev_ev + res_ev);
end;

Expand Down Expand Up @@ -37954,7 +37985,9 @@ procedure CLArray<T>.SetSliceProp(range: IntRange; value: array of T) :=
end;

begin
var left_mem_objs := EmptyMemoryObserver(CLMemoryObserver.Default).impl.mem_uses.Keys;
var obs := CLMemoryObserver.Current as TrackingMemoryObserver;
if obs=nil then obs := EmptyMemoryObserver(CLMemoryObserver.Current).impl;
var left_mem_objs := obs.mem_uses.Keys;
if left_mem_objs.Any then
raise new OpenCLABCInternalException($'Not all memory objects were disposed: ' + left_mem_objs.JoinToString);
end;
Expand Down
Loading

0 comments on commit ef1b659

Please sign in to comment.