Class MetalExecutionContext
- Namespace
- DotCompute.Backends.Metal.Execution
- Assembly
- DotCompute.Backends.Metal.dll
Metal execution context for managing execution state, resource lifetime tracking, performance metrics collection, and command dependency resolution. Follows CUDA execution context patterns optimized for Metal.
public sealed class MetalExecutionContext : IDisposable, IAsyncDisposable
- Inheritance
-
MetalExecutionContext
- Implements
- Inherited Members
- Extension Methods
Constructors
MetalExecutionContext(nint, ILogger<MetalExecutionContext>, MetalExecutionContextOptions?)
public MetalExecutionContext(nint device, ILogger<MetalExecutionContext> logger, MetalExecutionContextOptions? options = null)
Parameters
devicenintloggerILogger<MetalExecutionContext>optionsMetalExecutionContextOptions
Properties
CommandStream
Gets the command stream manager
public MetalCommandStream CommandStream { get; }
Property Value
Device
Gets the Metal device handle
public nint Device { get; }
Property Value
ErrorHandler
Gets the error handler
public MetalErrorHandler ErrorHandler { get; }
Property Value
EventManager
Gets the event manager
public MetalEventManager EventManager { get; }
Property Value
IsAppleSilicon
Gets whether the context is running on Apple Silicon
public bool IsAppleSilicon { get; }
Property Value
IsExecutionPaused
Gets whether execution is currently paused
public bool IsExecutionPaused { get; }
Property Value
TotalOperationsExecuted
Gets the total number of operations executed
public long TotalOperationsExecuted { get; }
Property Value
TotalResourcesTracked
Gets the total number of resources tracked
public long TotalResourcesTracked { get; }
Property Value
Methods
AddDependency(string, string)
Adds a dependency between operations
public void AddDependency(string dependentOperation, string dependencyOperation)
Parameters
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
ExecuteOperationAsync<T>(string, Func<MetalOperationExecutionInfo, Task<T>>, MetalExecutionOptions?, CancellationToken)
Executes an operation with full context management
public Task<T> ExecuteOperationAsync<T>(string operationId, Func<MetalOperationExecutionInfo, Task<T>> operation, MetalExecutionOptions? options = null, CancellationToken cancellationToken = default)
Parameters
operationIdstringoperationFunc<MetalOperationExecutionInfo, Task<T>>optionsMetalExecutionOptionscancellationTokenCancellationToken
Returns
- Task<T>
Type Parameters
T
GetStatistics()
Gets comprehensive execution statistics
public MetalExecutionStatistics GetStatistics()
Returns
PauseExecutionAsync(CancellationToken)
Pauses execution context (stops accepting new operations)
public Task PauseExecutionAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
PerformHealthCheckAsync(CancellationToken)
Performs a comprehensive health check
public Task<MetalHealthCheckResult> PerformHealthCheckAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
ResumeExecution()
Resumes execution context
public void ResumeExecution()
TrackResource(string, nint, MetalResourceType, long)
Tracks a resource for lifetime management
public void TrackResource(string resourceId, nint resourceHandle, MetalResourceType resourceType, long sizeInBytes = 0)
Parameters
resourceIdstringresourceHandlenintresourceTypeMetalResourceTypesizeInByteslong
UntrackResource(string, bool)
Stops tracking a resource and optionally releases it
public void UntrackResource(string resourceId, bool releaseResource = false)