Table of Contents

Class CudaEventManager

Namespace
DotCompute.Backends.CUDA.Execution
Assembly
DotCompute.Backends.CUDA.dll

Advanced CUDA event manager with timing, profiling, synchronization, and event pooling

public sealed class CudaEventManager : IDisposable
Inheritance
CudaEventManager
Implements
Inherited Members
Extension Methods

Constructors

CudaEventManager(CudaContext, ILogger<CudaEventManager>)

Initializes a new instance of the CudaEventManager class.

public CudaEventManager(CudaContext context, ILogger<CudaEventManager> logger)

Parameters

context CudaContext

The context.

logger ILogger<CudaEventManager>

The logger.

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

eventId EventId
callback Func<EventId, Task>

CreateEvent(CudaEventFlags)

Creates a new CUDA event with specified flags (backward compatibility)

public nint CreateEvent(CudaEventFlags flags = CudaEventFlags.Default)

Parameters

flags CudaEventFlags

Returns

nint

CreateEventBatchAsync(int, CudaEventType, CancellationToken)

Creates a batch of events for parallel operations

public Task<CudaEventHandle[]> CreateEventBatchAsync(int count, CudaEventType eventType = CudaEventType.Timing, CancellationToken cancellationToken = default)

Parameters

count int
eventType CudaEventType
cancellationToken CancellationToken

Returns

Task<CudaEventHandle[]>

CreateSyncEventAsync(CancellationToken)

Creates a synchronization event optimized for stream coordination

public Task<CudaEventHandle> CreateSyncEventAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<CudaEventHandle>

CreateTimingEventAsync(CancellationToken)

Creates a high-performance timing event for precise measurements

public Task<CudaEventHandle> CreateTimingEventAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<CudaEventHandle>

CreateTimingPairAsync(CancellationToken)

Creates a matched pair of timing events for measuring elapsed time

public Task<(CudaEventHandle start, CudaEventHandle end)> CreateTimingPairAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<(CudaEventHandle start, CudaEventHandle end)>

DestroyEvent(nint)

Destroys a CUDA event (backward compatibility)

public void DestroyEvent(nint eventHandle)

Parameters

eventHandle nint

Dispose()

Performs dispose.

public void Dispose()

ElapsedTime(nint, nint)

Calculates elapsed time between two events (backward compatibility)

public float ElapsedTime(nint startEvent, nint endEvent)

Parameters

startEvent nint
endEvent nint

Returns

float

GetStatistics()

Gets comprehensive event manager statistics

public CudaEventStatistics GetStatistics()

Returns

CudaEventStatistics

IsEventComplete(EventId)

Checks if an event has completed

public bool IsEventComplete(EventId eventId)

Parameters

eventId EventId

Returns

bool

MeasureElapsedTime(EventId, EventId)

Measures elapsed time between two timing events in milliseconds

public float MeasureElapsedTime(EventId startEvent, EventId endEvent)

Parameters

startEvent EventId
endEvent EventId

Returns

float

MeasureOperationAsync(Func<nint, Task>, nint, string?, CancellationToken)

Performs high-precision timing measurement of an operation

public Task<CudaTimingResult> MeasureOperationAsync(Func<nint, Task> operation, nint stream = 0, string? operationName = null, CancellationToken cancellationToken = default)

Parameters

operation Func<nint, Task>
stream nint
operationName string
cancellationToken CancellationToken

Returns

Task<CudaTimingResult>

ProfileOperationAsync(Func<nint, Task>, int, nint, string?, CancellationToken)

Performs comprehensive profiling with statistical analysis

public Task<CudaProfilingResult> ProfileOperationAsync(Func<nint, Task> operation, int iterations = 100, nint stream = 0, string? operationName = null, CancellationToken cancellationToken = default)

Parameters

operation Func<nint, Task>
iterations int
stream nint
operationName string
cancellationToken CancellationToken

Returns

Task<CudaProfilingResult>

RecordEvent(EventId, nint)

Records an event on the specified stream

public void RecordEvent(EventId eventId, nint stream = 0)

Parameters

eventId EventId
stream nint

RecordEventFast(nint, nint)

Records an event using the handle directly for performance

public void RecordEventFast(nint eventHandle, nint stream = 0)

Parameters

eventHandle nint
stream nint

SynchronizeEventAsync(EventId, TimeSpan?, CancellationToken)

Synchronizes with an event asynchronously

public Task SynchronizeEventAsync(EventId eventId, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

eventId EventId
timeout TimeSpan?
cancellationToken CancellationToken

Returns

Task