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
contextOpenCLContextThe OpenCL context for kernel execution.
deviceIdOpenCLDeviceIdThe device ID for execution operations.
streamManagerOpenCLStreamManagerStream manager for command queue pooling.
profilerOpenCLProfilerProfiler for performance metrics.
loggerILogger<OpenCLKernelExecutionEngine>Logger for diagnostic information.
Exceptions
- ArgumentNullException
Thrown if any parameter is null.
Methods
DisposeAsync()
Asynchronously disposes the execution engine.
public ValueTask DisposeAsync()
Returns
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
kernelHandlenintHandle to the compiled kernel.
globalSizeNDRangeGlobal work size (NDRange dimensions).
localSizeNDRangeOptional local work size. If null, automatically calculated.
argumentsKernelArgumentsKernel arguments to bind.
waitEventsOpenCLEventHandle[]Optional events to wait for before execution.
cancellationTokenCancellationTokenCancellation 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
kernelHandlenintHandle to the compiled kernel.
globalSizeNDRangeGlobal work size (NDRange dimensions).
localSizeNDRangeOptional local work size. If null, automatically calculated.
argumentsKernelArgumentsKernel arguments to bind.
cancellationTokenCancellationTokenCancellation token for async operations.
Returns
- Task<ExecutionResult>
Execution result containing timing and work size information.