Table of Contents

Class CompiledKernel

Namespace
DotCompute.Abstractions.Kernels
Assembly
DotCompute.Abstractions.dll

Represents a compiled kernel that contains the compiled binary or bytecode and can be executed on a compute device with the appropriate arguments.

public class CompiledKernel : IDisposable
Inheritance
CompiledKernel
Implements
Inherited Members
Extension Methods

Constructors

CompiledKernel()

Initializes a new instance of the CompiledKernel class.

public CompiledKernel()

CompiledKernel(Guid, nint, int, KernelConfiguration)

Initializes a new instance of the CompiledKernel class for low-level usage with native handle. This constructor is typically used by backend implementations that work with native kernel objects.

[SetsRequiredMembers]
public CompiledKernel(Guid id, nint nativeHandle, int sharedMemorySize, KernelConfiguration configuration)

Parameters

id Guid

The unique identifier for this kernel instance.

nativeHandle nint

The native handle or pointer to the compiled kernel.

sharedMemorySize int

The amount of shared memory required by this kernel in bytes.

configuration KernelConfiguration

The kernel configuration used during compilation.

CompiledKernel(string, byte[]?, CompilationOptions?, Dictionary<string, object>?)

Initializes a new instance of the CompiledKernel class with the specified parameters.

public CompiledKernel(string name, byte[]? binary, CompilationOptions? options = null, Dictionary<string, object>? metadata = null)

Parameters

name string

The unique name for the compiled kernel.

binary byte[]

The compiled binary data, or null if using native handles.

options CompilationOptions

Optional compilation options to store in metadata.

metadata Dictionary<string, object>

Optional additional metadata for the kernel.

Exceptions

ArgumentNullException

Thrown when name is null.

Properties

Binary

Gets or sets the compiled binary data.

public ReadOnlyMemory<byte> Binary { get; set; }

Property Value

ReadOnlyMemory<byte>

CompilationTime

Gets or sets the time spent during compilation.

public TimeSpan CompilationTime { get; set; }

Property Value

TimeSpan

CompiledAt

Gets or sets the timestamp when this kernel was compiled.

public DateTime CompiledAt { get; set; }

Property Value

DateTime

CompiledBinary

Gets the compiled binary or bytecode data for this kernel.

public ReadOnlyMemory<byte>? CompiledBinary { get; init; }

Property Value

ReadOnlyMemory<byte>?

The compiled kernel binary as a byte array, or null if the kernel uses a native handle or if compilation is deferred until execution time.

ComputeCapability

Gets or sets the compute capability version used for compilation.

public Version ComputeCapability { get; set; }

Property Value

Version

Cubin

Gets or sets the CUBIN binary data.

public ReadOnlyMemory<byte> Cubin { get; set; }

Property Value

ReadOnlyMemory<byte>

EntryPoint

Gets or sets the entry point function name for this kernel.

public string EntryPoint { get; set; }

Property Value

string

Id

Gets the unique identifier for this compiled kernel instance.

public string Id { get; init; }

Property Value

string

A string representation of the kernel's unique ID, generated automatically if not specified.

IsDisposed

Gets a value indicating whether this kernel instance has been disposed.

public bool IsDisposed { get; }

Property Value

bool

True if the kernel has been disposed; otherwise, false.

MaxThreadsPerBlock

Gets or sets the maximum threads per block supported by this kernel.

public int MaxThreadsPerBlock { get; set; }

Property Value

int

Metadata

Gets the compilation metadata associated with this kernel.

public Dictionary<string, object> Metadata { get; init; }

Property Value

Dictionary<string, object>

A dictionary containing compilation-specific metadata such as compilation options, native handles, shared memory requirements, and device-specific configuration.

Name

Gets the unique name identifier for this compiled kernel.

public required string Name { get; init; }

Property Value

string

The kernel name used for identification during execution.

Ptx

Gets or sets the PTX intermediate representation code.

public string Ptx { get; set; }

Property Value

string

RequiredSharedMemory

Gets or sets the required shared memory size in bytes for this kernel.

public long RequiredSharedMemory { get; set; }

Property Value

long

TargetDevice

Gets or sets the target device or accelerator type for this kernel.

public string TargetDevice { get; set; }

Property Value

string

Methods

Dispose()

Releases all resources used by this CompiledKernel instance.

public void Dispose()

Remarks

This method sets the IsDisposed property to true and suppresses finalization for this object. Derived classes should override the Dispose(bool) method to release specific resources.

Dispose(bool)

Releases the unmanaged resources used by the CompiledKernel and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

True to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

This method is called by the Dispose() method and the finalizer. Override this method in derived classes to provide specific resource cleanup logic.

ExecuteAsync(KernelArguments, CancellationToken)

Executes the compiled kernel asynchronously with the specified arguments.

public virtual Task ExecuteAsync(KernelArguments arguments, CancellationToken cancellationToken = default)

Parameters

arguments KernelArguments

The arguments to pass to the kernel during execution.

cancellationToken CancellationToken

A cancellation token to cancel the kernel execution.

Returns

Task

A task representing the asynchronous kernel execution.

Remarks

This is the base implementation that simply completes successfully. Backend-specific implementations should override this method to provide actual kernel execution functionality.

Exceptions

ObjectDisposedException

Thrown when attempting to execute a disposed kernel.

ArgumentNullException

Thrown when arguments is null.