Class MetalEventManager
- Namespace
- DotCompute.Backends.Metal.Execution
- Assembly
- DotCompute.Backends.Metal.dll
Advanced Metal event manager for timing, profiling, synchronization, and event pooling, following CUDA event patterns for cross-stream coordination.
public sealed class MetalEventManager : IDisposable
- Inheritance
-
MetalEventManager
- Implements
- Inherited Members
- Extension Methods
Constructors
MetalEventManager(nint, ILogger<MetalEventManager>)
public MetalEventManager(nint device, ILogger<MetalEventManager> logger)
Parameters
devicenintloggerILogger<MetalEventManager>
Methods
AddEventCallback(EventId, Func<EventId, Task>)
Adds an asynchronous callback for when an event completes
public void AddEventCallback(EventId eventId, Func<EventId, Task> callback)
Parameters
CreateEventBatchAsync(int, MetalEventType, CancellationToken)
Creates a batch of events for parallel operations
public Task<MetalEventHandle[]> CreateEventBatchAsync(int count, MetalEventType eventType = MetalEventType.Timing, CancellationToken cancellationToken = default)
Parameters
countinteventTypeMetalEventTypecancellationTokenCancellationToken
Returns
CreateSyncEventAsync(CancellationToken)
Creates a synchronization event optimized for stream coordination
public Task<MetalEventHandle> CreateSyncEventAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
CreateTimingEventAsync(CancellationToken)
Creates a high-performance timing event for precise measurements
public Task<MetalEventHandle> CreateTimingEventAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
CreateTimingPairAsync(CancellationToken)
Creates a matched pair of timing events for measuring elapsed time
public Task<(MetalEventHandle start, MetalEventHandle end)> CreateTimingPairAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetStatistics()
Gets comprehensive event manager statistics
public MetalEventStatistics GetStatistics()
Returns
IsEventComplete(EventId)
Checks if an event has completed
public bool IsEventComplete(EventId eventId)
Parameters
eventIdEventId
Returns
MeasureElapsedTimeAsync(EventId, EventId)
Measures elapsed time between two timing events using Metal Performance Counters
public Task<double> MeasureElapsedTimeAsync(EventId startEvent, EventId endEvent)
Parameters
Returns
MeasureOperationAsync(Func<nint, Task>, nint, string?, CancellationToken)
Performs high-precision timing measurement of an operation
public Task<MetalTimingResult> MeasureOperationAsync(Func<nint, Task> operation, nint commandQueue, string? operationName = null, CancellationToken cancellationToken = default)
Parameters
operationFunc<nint, Task>commandQueuenintoperationNamestringcancellationTokenCancellationToken
Returns
PerformMaintenance(object?)
public void PerformMaintenance(object? state = null)
Parameters
stateobject
ProfileOperationAsync(Func<nint, Task>, int, nint, string?, CancellationToken)
Performs comprehensive profiling with statistical analysis
public Task<MetalProfilingResult> ProfileOperationAsync(Func<nint, Task> operation, int iterations = 50, nint commandQueue = 0, string? operationName = null, CancellationToken cancellationToken = default)
Parameters
operationFunc<nint, Task>iterationsintcommandQueuenintoperationNamestringcancellationTokenCancellationToken
Returns
RecordEvent(EventId, nint)
Records an event on the specified command queue
public void RecordEvent(EventId eventId, nint commandQueue)
Parameters
RecordEventFast(nint, nint)
Records an event using the handle directly for performance
public void RecordEventFast(nint eventHandle, nint commandQueue)
Parameters
WaitForEventAsync(EventId, TimeSpan?, CancellationToken)
Waits for an event asynchronously
public Task WaitForEventAsync(EventId eventId, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
eventIdEventIdtimeoutTimeSpan?cancellationTokenCancellationToken