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
idGuidThe unique identifier for this kernel instance.
nativeHandlenintThe native handle or pointer to the compiled kernel.
sharedMemorySizeintThe amount of shared memory required by this kernel in bytes.
configurationKernelConfigurationThe 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
namestringThe unique name for the compiled kernel.
binarybyte[]The compiled binary data, or null if using native handles.
optionsCompilationOptionsOptional compilation options to store in metadata.
metadataDictionary<string, object>Optional additional metadata for the kernel.
Exceptions
- ArgumentNullException
Thrown when
nameis null.
Properties
Binary
Gets or sets the compiled binary data.
public ReadOnlyMemory<byte> Binary { get; set; }
Property Value
CompilationTime
Gets or sets the time spent during compilation.
public TimeSpan CompilationTime { get; set; }
Property Value
CompiledAt
Gets or sets the timestamp when this kernel was compiled.
public DateTime CompiledAt { get; set; }
Property Value
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
Cubin
Gets or sets the CUBIN binary data.
public ReadOnlyMemory<byte> Cubin { get; set; }
Property Value
EntryPoint
Gets or sets the entry point function name for this kernel.
public string EntryPoint { get; set; }
Property Value
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
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
RequiredSharedMemory
Gets or sets the required shared memory size in bytes for this kernel.
public long RequiredSharedMemory { get; set; }
Property Value
TargetDevice
Gets or sets the target device or accelerator type for this kernel.
public string TargetDevice { get; set; }
Property Value
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
disposingboolTrue 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
argumentsKernelArgumentsThe arguments to pass to the kernel during execution.
cancellationTokenCancellationTokenA 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
argumentsis null.