Table of Contents

Class KernelExecutionService

Namespace
DotCompute.Runtime.Services
Assembly
DotCompute.Runtime.dll

Production-grade kernel execution service that bridges generated kernel code with runtime infrastructure. Provides automatic backend selection, caching, and optimization.

public class KernelExecutionService : IComputeOrchestrator, IDisposable
Inheritance
KernelExecutionService
Implements
Inherited Members
Extension Methods

Constructors

KernelExecutionService(AcceleratorRuntime, ILogger<KernelExecutionService>, IUnifiedKernelCompiler, IKernelCache, IKernelProfiler)

Production-grade kernel execution service that bridges generated kernel code with runtime infrastructure. Provides automatic backend selection, caching, and optimization.

public KernelExecutionService(AcceleratorRuntime runtime, ILogger<KernelExecutionService> logger, IUnifiedKernelCompiler compiler, IKernelCache cache, IKernelProfiler profiler)

Parameters

runtime AcceleratorRuntime
logger ILogger<KernelExecutionService>
compiler IUnifiedKernelCompiler
cache IKernelCache
profiler IKernelProfiler

Methods

Dispose()

Performs dispose.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

ExecuteAsync<T>(string, IAccelerator, params object[])

Executes a kernel on a specific accelerator instance.

public Task<T> ExecuteAsync<T>(string kernelName, IAccelerator accelerator, params object[] args)

Parameters

kernelName string

The fully qualified kernel name

accelerator IAccelerator

The specific accelerator to use

args object[]

The kernel arguments

Returns

Task<T>

The execution result

Type Parameters

T

The return type

ExecuteAsync<T>(string, params object[])

Executes a kernel by name with automatic backend selection and parameter marshaling.

public Task<T> ExecuteAsync<T>(string kernelName, params object[] args)

Parameters

kernelName string

The fully qualified kernel name

args object[]

The kernel arguments

Returns

Task<T>

The execution result

Type Parameters

T

The return type

ExecuteAsync<T>(string, string, params object[])

Executes a kernel with explicit backend preference.

public Task<T> ExecuteAsync<T>(string kernelName, string preferredBackend, params object[] args)

Parameters

kernelName string

The fully qualified kernel name

preferredBackend string

The preferred backend for execution

args object[]

The kernel arguments

Returns

Task<T>

The execution result

Type Parameters

T

The return type

ExecuteKernelAsync(string, IKernelExecutionParameters)

Executes a kernel with advanced execution parameters.

public Task<object?> ExecuteKernelAsync(string kernelName, IKernelExecutionParameters executionParameters)

Parameters

kernelName string

The kernel name

executionParameters IKernelExecutionParameters

Advanced execution parameters

Returns

Task<object>

The execution result

ExecuteKernelAsync(string, object[], CancellationToken)

Executes a kernel with cancellation token support.

public Task<object?> ExecuteKernelAsync(string kernelName, object[] args, CancellationToken cancellationToken = default)

Parameters

kernelName string

The kernel name

args object[]

The kernel arguments

cancellationToken CancellationToken

Cancellation token

Returns

Task<object>

The execution result

ExecuteWithBuffersAsync<T>(string, IEnumerable<IUnifiedMemoryBuffer>, params object[])

Executes a kernel with unified buffer parameters for zero-copy optimization.

public Task<T> ExecuteWithBuffersAsync<T>(string kernelName, IEnumerable<IUnifiedMemoryBuffer> buffers, params object[] scalarArgs)

Parameters

kernelName string

The fully qualified kernel name

buffers IEnumerable<IUnifiedMemoryBuffer>

Unified buffers for zero-copy execution

scalarArgs object[]

Scalar arguments

Returns

Task<T>

The execution result

Type Parameters

T

The return type

GetOptimalAcceleratorAsync(string)

Gets the optimal accelerator for a specific kernel.

public Task<IAccelerator?> GetOptimalAcceleratorAsync(string kernelName)

Parameters

kernelName string

The kernel name

Returns

Task<IAccelerator>

The optimal accelerator or null if none suitable

GetSupportedAcceleratorsAsync(string)

Gets available accelerators that support a specific kernel.

public Task<IReadOnlyList<IAccelerator>> GetSupportedAcceleratorsAsync(string kernelName)

Parameters

kernelName string

The kernel name

Returns

Task<IReadOnlyList<IAccelerator>>

Available accelerators supporting the kernel

PrecompileKernelAsync(string, IAccelerator?)

Pre-compiles a kernel for improved runtime performance.

public Task PrecompileKernelAsync(string kernelName, IAccelerator? accelerator = null)

Parameters

kernelName string

The kernel name to pre-compile

accelerator IAccelerator

Optional specific accelerator, or null for all suitable accelerators

Returns

Task

A task representing the pre-compilation operation

RegisterKernels(IEnumerable<KernelRegistrationInfo>)

Registers kernels from the generated kernel registry. This method should be called during application startup.

public void RegisterKernels(IEnumerable<KernelRegistrationInfo> kernelRegistrations)

Parameters

kernelRegistrations IEnumerable<KernelRegistrationInfo>

Kernel registrations from generated code

ValidateKernelArgsAsync(string, params object[])

Validates kernel arguments before execution.

public Task<bool> ValidateKernelArgsAsync(string kernelName, params object[] args)

Parameters

kernelName string

The kernel name

args object[]

The arguments to validate

Returns

Task<bool>

Validation result with any errors or warnings