![]() |
SystemEX
Lacking
Additional generic collection types missing in .net
|
Example implementation of a RAM‑based compute kernel that adds two integers. More...
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. | |
Example implementation of a RAM‑based compute kernel that adds two integers.
This class demonstrates how to use NativeRAMKernel<T>:
The example is intentionally simple: it adds two integer values stored in device buffers A and B, and writes the result into C.
| KernelRamExamples.ExampleRamKernelAdd.ExampleRamKernelAdd | ( | ) |
Initializes a new instance of the example kernel.
The native DLL is loaded later via IKernel<T>.Create.
|
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:
true if buffer creation succeeds.Reimplemented from SystemEx.Device.NativeRAMKernel< TD >.
|
protected |
Executes the native addition kernel.
The method:
C | function | The resolved native kernel delegate. If null, the kernel cannot be executed. |
true if execution succeeds.