SystemEX  Lacking
Additional generic collection types missing in .net
ExampleRamKernelAdd.cs File Reference

Beginner-friendly example demonstrating how to use a native RAM-based compute kernel in SystemEx. More...

Classes

class  KernelRamExamples.ExampleRamKernelAdd
 Example implementation of a RAM‑based compute kernel that adds two integers. More...
class  KernelRamExamples.Programm
 Example program demonstrating how to run the RAM kernel.

Functions

delegate int KernelRamExamples.MyKernelFunction (IntPtr A, int dwSize, IntPtr B, int dwSizeB, IntPtr C)

Detailed Description

Beginner-friendly example demonstrating how to use a native RAM-based compute kernel in SystemEx.

This example shows how SystemEx executes a native C function through the RAM kernel backend. It demonstrates the complete workflow:

1. What this example does

The example loads a native DLL containing a function with the following signature:

extern "C" int MyKernelFunction(int* A, int sizeA,
int* B, int sizeB,
int* C);

The function adds the integer stored in buffer A to the integer stored in buffer B, and writes the result into buffer C.

2. How SystemEx handles native kernels

SystemEx provides a device abstraction layer that allows:

  • Creating device buffers (DeviceBuffer)
  • Sharing them with a backend (DeviceSharedBuffer)
  • Passing unmanaged pointers to native code
  • Executing native functions through delegates

The class ExampleRamKernelAdd inherits from NativeRAMKernel, which manages:

  • Buffer registration
  • Shared memory handling
  • Native delegate resolution
  • Kernel execution lifecycle (Create, BeginRun, Run, EndRun)

3. What this example teaches beginners

  • How to allocate device buffers
  • How to write initial values into buffers
  • How to register buffers with a kernel
  • How to call a native function using unmanaged pointers
  • How to read back results from device memory

4. Execution flow

The program performs the following steps:

  1. Create the kernel instance
  2. Load the native DLL
  3. Create buffers A and C
  4. Write values into A and B
  5. Register buffers with the kernel
  6. Start the kernel (BeginRun)
  7. Execute the native function (Run)
  8. Wait until the kernel finishes
  9. Read the result from buffer C

5. Notes for beginners

  • Device buffers represent memory that can be shared with native code.
  • UnmanagedObject.Point is the raw pointer passed to the native function.
  • The kernel backend ensures safe lifetime management of unmanaged memory.
  • The example uses RamSharedBackend, which stores buffers in RAM.

This example is intentionally simple and focuses on demonstrating the mechanics of native kernel execution in SystemEx.

See also
NativeRAMKernel
DeviceBuffer
DeviceSharedBuffer
RamSharedBackend