SystemEX  Lacking
Additional generic collection types missing in .net
KernelRamExamples.ExampleRamKernelAdd Class Reference

Example implementation of a RAM‑based compute kernel that adds two integers. More...

Inheritance diagram for KernelRamExamples.ExampleRamKernelAdd:
Collaboration diagram for KernelRamExamples.ExampleRamKernelAdd:

Public Member Functions

 ExampleRamKernelAdd ()
 Initializes a new instance of the example kernel.
Public Member Functions inherited from SystemEx.Device.NativeRAMKernel< TD >
 NativeRAMKernel ()
 Initializes a new RAM kernel instance with an empty buffer set and a default RamSharedBackend backend.
The native module is not loaded until Create is called.
bool Create (string dllPath)
 Loads the native module located at dllPath and performs backend‑specific initialization via OnCreate.
Must be called before buffers are added or the kernel is executed.
int AddBuffer (DeviceBuffer buffer, string name, int flags, object? configs)
 Adds a shared buffer to the kernel and converts the provided DeviceBuffer into a DeviceSharedBuffer<RamSharedBackend> using the RAM backend.
Derived classes may override OnAddBuffer to perform validation or backend‑specific configuration.
DeviceSharedBuffer< RamSharedBackend >? GetBuffer (string name)
 Retrieves a shared buffer by its symbolic name.
bool RemoveBuffer (string name)
 Removes a buffer by name and buffer type.
bool RemoveBuffer (int index)
 Removes a buffer by index and buffer type.
virtual bool BeginRun (string strFunction)
 Begins a kernel execution session by loading the native function specified by strFunction and locking all shared buffers.
Derived classes may override OnBegin to perform additional backend‑specific setup.
virtual void EndRun ()
 Ends the kernel execution session, unlocks all shared buffers, and performs backend cleanup via OnEnd.
bool IsRunning ()
 Indicates whether the kernel is currently running.
unsafe bool Run (object? options)
 Executes the kernel asynchronously using the delegate loaded during BeginRun.
The actual kernel logic is implemented in OnRun.

Protected Member Functions

override bool OnCreate ()
 Creates and initializes the buffers required for this kernel.
override bool OnRun (MyKernelFunction function)
 Executes the native addition kernel.
Protected Member Functions inherited from SystemEx.Device.NativeRAMKernel< TD >
virtual bool OnBegin (string strFunction)
 Called when a kernel execution session begins.
Loads the native function delegate using NativeHost and returns true if the function is successfully resolved.
virtual void OnEnd ()
 Called when a kernel execution session ends.
Derived classes may override this method to perform backend‑specific cleanup.
virtual bool OnAddBuffer (string name, DeviceSharedBuffer< RamSharedBackend > buffer)
 Called when a buffer is added to the kernel.
Derived classes may override this method to validate buffer names or apply backend‑specific configuration.
virtual bool OnRun (TD function)
 Executes the native kernel function.
Derived classes must override this method to implement backend‑specific compute logic using the resolved delegate function .

Additional Inherited Members

Properties inherited from SystemEx.Device.NativeRAMKernel< TD >
RamSharedBackend Backend [get]
 Gets the backend instance used for RAM‑based shared buffer operations.
Module? Module [get, protected set]
 Gets the native module loaded for this kernel.
The module represents the underlying shared library (DLL, SO, DYLIB) from which the kernel function delegate is resolved.
This property is assigned during Create and remains available for the entire lifetime of the kernel instance.
TD? Function [get, protected set]
 Gets the resolved native kernel function delegate.
The delegate is created during BeginRun using the function name provided by the caller and represents the entry point of the native compute routine.
If the function cannot be resolved, this property is null.
bool Running [get]
 Indicates whether the kernel is currently running.

Detailed Description

Example implementation of a RAM‑based compute kernel that adds two integers.

This class demonstrates how to use NativeRAMKernel<T>:

  • Buffers are created and registered in OnCreate.
  • The native function is executed in OnRun.
  • Unmanaged pointers are passed directly to the native DLL.

The example is intentionally simple: it adds two integer values stored in device buffers A and B, and writes the result into C.

Constructor & Destructor Documentation

◆ ExampleRamKernelAdd()

KernelRamExamples.ExampleRamKernelAdd.ExampleRamKernelAdd ( )

Initializes a new instance of the example kernel.

The native DLL is loaded later via IKernel<T>.Create.

127: base() { }

Member Function Documentation

◆ OnCreate()

override bool KernelRamExamples.ExampleRamKernelAdd.OnCreate ( )
protectedvirtual

Creates and initializes the buffers required for this kernel.

In this example, only buffer B is created here. Buffers A and C are created in Main().

Steps:

  1. Allocate a device buffer for integer B.
  2. Write the initial value (54) into the buffer.
  3. Register the buffer with the kernel.
Returns
true if buffer creation succeeds.

Reimplemented from SystemEx.Device.NativeRAMKernel< TD >.

148 {
149 DeviceBuffer B = new DeviceBuffer(sizeof(int), CacheType.ToDevice);
150
151 B.Write(0, 54U, Endian.System);
152
153 AddBuffer(B, "BufferB", 0, null);
154
155 return base.OnCreate();
156 }
int Write(ulong position, uint value, Endian endian)
Writes a 32-bit unsigned integer at the specified position.
Definition Cache.cs:288
CacheType
Definition Cache.cs:29
Endian
Specifies the byte order used when converting values to and from raw byte sequences.
Definition Conversion.cs:29
Here is the call graph for this function:

◆ OnRun()

override bool KernelRamExamples.ExampleRamKernelAdd.OnRun ( MyKernelFunction function)
protected

Executes the native addition kernel.

The method:

  • Retrieves buffers A, B, and C
  • Extracts their unmanaged memory handles
  • Invokes the native function through the delegate
  • Writes the result into buffer C
Parameters
functionThe resolved native kernel delegate.
If null, the kernel cannot be executed.
Returns
true if execution succeeds.
176 {
177
178
179 DeviceSharedBuffer < RamSharedBackend >? A = base.GetBuffer("BufferA")!;
180 DeviceSharedBuffer < RamSharedBackend >? B = base.GetBuffer("BufferB")!;
181 DeviceSharedBuffer < RamSharedBackend >? C = base.GetBuffer("BufferC")!;
182
183 var unmanagedA = (UnmanagedObject)A.HardwareBuffer!;
184 var unmanagedB = (UnmanagedObject)B.HardwareBuffer!;
185 var unmanagedC = (UnmanagedObject)C.HardwareBuffer!;
186
187 unmanagedC.Size = function(unmanagedA.Point, unmanagedA.Size, unmanagedB.Point, unmanagedB.Size, unmanagedC.Point);
188
189 return true;
190 }

The documentation for this class was generated from the following file: