Table of Contents

Class OpenCLKernelExecutionEngine

Namespace
DotCompute.Backends.OpenCL.Execution
Assembly
DotCompute.Backends.OpenCL.dll

Production-grade OpenCL kernel execution engine with automatic work size optimization and comprehensive error handling.

public sealed class OpenCLKernelExecutionEngine : IAsyncDisposable
Inheritance
OpenCLKernelExecutionEngine
Implements
Inherited Members

Remarks

This execution engine provides:

  • NDRange kernel dispatch (1D/2D/3D work dimensions)
  • Automatic work group size calculation based on device and kernel limits
  • Type-safe argument binding with validation
  • Event-based synchronization with profiling integration
  • Optimal work size calculation respecting device capabilities
  • Comprehensive error handling with detailed diagnostics

Constructors

OpenCLKernelExecutionEngine(OpenCLContext, OpenCLDeviceId, OpenCLStreamManager, OpenCLProfiler, ILogger<OpenCLKernelExecutionEngine>)

Initializes a new instance of the OpenCLKernelExecutionEngine class.

public OpenCLKernelExecutionEngine(OpenCLContext context, OpenCLDeviceId deviceId, OpenCLStreamManager streamManager, OpenCLProfiler profiler, ILogger<OpenCLKernelExecutionEngine> logger)

Parameters

context OpenCLContext

The OpenCL context for kernel execution.

deviceId OpenCLDeviceId

The device ID for execution operations.

streamManager OpenCLStreamManager

Stream manager for command queue pooling.

profiler OpenCLProfiler

Profiler for performance metrics.

logger ILogger<OpenCLKernelExecutionEngine>

Logger for diagnostic information.

Exceptions

ArgumentNullException

Thrown if any parameter is null.

Methods

DisposeAsync()

Asynchronously disposes the execution engine.

public ValueTask DisposeAsync()

Returns

ValueTask

ExecuteKernelAsync(nint, NDRange, NDRange?, KernelArguments, OpenCLEventHandle[]?, CancellationToken)

Executes a kernel with automatic work size optimization and profiling.

public Task<ExecutionResult> ExecuteKernelAsync(nint kernelHandle, NDRange globalSize, NDRange? localSize, KernelArguments arguments, OpenCLEventHandle[]? waitEvents = null, CancellationToken cancellationToken = default)

Parameters

kernelHandle nint

Handle to the compiled kernel.

globalSize NDRange

Global work size (NDRange dimensions).

localSize NDRange

Optional local work size. If null, automatically calculated.

arguments KernelArguments

Kernel arguments to bind.

waitEvents OpenCLEventHandle[]

Optional events to wait for before execution.

cancellationToken CancellationToken

Cancellation token for async operations.

Returns

Task<ExecutionResult>

Execution result containing event, timing, and work size information.

Exceptions

ArgumentException

Thrown if kernel handle is invalid or work sizes are invalid.

OpenCLException

Thrown if kernel execution fails.

ExecuteKernelSyncAsync(nint, NDRange, NDRange?, KernelArguments, CancellationToken)

Executes a kernel synchronously, waiting for completion.

public Task<ExecutionResult> ExecuteKernelSyncAsync(nint kernelHandle, NDRange globalSize, NDRange? localSize, KernelArguments arguments, CancellationToken cancellationToken = default)

Parameters

kernelHandle nint

Handle to the compiled kernel.

globalSize NDRange

Global work size (NDRange dimensions).

localSize NDRange

Optional local work size. If null, automatically calculated.

arguments KernelArguments

Kernel arguments to bind.

cancellationToken CancellationToken

Cancellation token for async operations.

Returns

Task<ExecutionResult>

Execution result containing timing and work size information.