Class CudaGraphSupport
- Namespace
- DotCompute.Backends.CUDA.Execution
- Assembly
- DotCompute.Backends.CUDA.dll
Advanced CUDA Graph support for kernel fusion and optimization on RTX 2000 Ada architecture. Provides comprehensive graph management, execution, and optimization capabilities.
public sealed class CudaGraphSupport : IDisposable
- Inheritance
-
CudaGraphSupport
- Implements
- Inherited Members
- Extension Methods
Remarks
This class manages the complete lifecycle of CUDA graphs including creation, instantiation, execution, and optimization. It provides advanced features like kernel fusion, Ada Lovelace architecture optimizations, and performance monitoring for high-throughput computing scenarios.
Constructors
CudaGraphSupport(CudaContext, CudaStreamManager, CudaEventManager, ILogger<CudaGraphSupport>)
Initializes a new instance of the CudaGraphSupport class.
public CudaGraphSupport(CudaContext context, CudaStreamManager streamManager, CudaEventManager eventManager, ILogger<CudaGraphSupport> logger)
Parameters
contextCudaContextThe CUDA context for graph operations.
streamManagerCudaStreamManagerThe stream manager for execution scheduling.
eventManagerCudaEventManagerThe event manager for timing and synchronization.
loggerILogger<CudaGraphSupport>The logger for diagnostic information.
Exceptions
- ArgumentNullException
Thrown when any parameter is null.
Methods
CaptureGraphAsync(string, Func<nint, Task>, CudaGraphCaptureMode, CancellationToken)
Captures a sequence of operations into a graph.
public Task<string> CaptureGraphAsync(string graphId, Func<nint, Task> operations, CudaGraphCaptureMode mode = CudaGraphCaptureMode.Global, CancellationToken cancellationToken = default)
Parameters
graphIdstringThe unique identifier for the captured graph.
operationsFunc<nint, Task>A function that executes operations to be captured.
modeCudaGraphCaptureModeThe capture mode for the operation.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
Exceptions
- ObjectDisposedException
Thrown if the object has been disposed.
CleanupUnusedInstances(TimeSpan)
Cleans up unused graph instances older than the specified age.
public int CleanupUnusedInstances(TimeSpan maxAge)
Parameters
maxAgeTimeSpanThe maximum age for keeping unused instances.
Returns
- int
The number of instances that were cleaned up.
Exceptions
- ObjectDisposedException
Thrown if the object has been disposed.
CreateGraphAsync(string, IEnumerable<CudaKernelOperation>, CudaGraphOptimizationOptions?, CancellationToken)
Creates a CUDA graph from a sequence of kernel operations.
public Task<string> CreateGraphAsync(string graphId, IEnumerable<CudaKernelOperation> operations, CudaGraphOptimizationOptions? options = null, CancellationToken cancellationToken = default)
Parameters
graphIdstringThe unique identifier for the graph.
operationsIEnumerable<CudaKernelOperation>The sequence of kernel operations to include in the graph.
optionsCudaGraphOptimizationOptionsOptional optimization settings for the graph.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<string>
A task that represents the asynchronous graph creation operation, returning the graph ID.
Exceptions
- ObjectDisposedException
Thrown if the object has been disposed.
Dispose()
Disposes of the graph support resources and cleans up all managed graphs and instances.
public void Dispose()
ExecuteGraphAsync(CudaGraphInstance, nint, CancellationToken)
Executes a graph instance.
public Task<CudaGraphExecutionResult> ExecuteGraphAsync(CudaGraphInstance instance, nint stream = 0, CancellationToken cancellationToken = default)
Parameters
instanceCudaGraphInstanceThe graph instance to execute.
streamnintThe CUDA stream for execution (default stream if not specified).
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<CudaGraphExecutionResult>
A task that represents the asynchronous execution operation, returning the execution results.
Exceptions
- ObjectDisposedException
Thrown if the object has been disposed.
- InvalidOperationException
Thrown if the graph instance is not valid.
FuseKernelsAsync(string, IEnumerable<CudaCompiledKernel>, CudaKernelFusionOptions, CancellationToken)
Fuses multiple kernels into a single optimized graph.
public Task<string> FuseKernelsAsync(string graphId, IEnumerable<CudaCompiledKernel> kernels, CudaKernelFusionOptions fusionOptions, CancellationToken cancellationToken = default)
Parameters
graphIdstringThe unique identifier for the fused graph.
kernelsIEnumerable<CudaCompiledKernel>The kernels to fuse together.
fusionOptionsCudaKernelFusionOptionsConfiguration options for the fusion operation.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
Exceptions
- ObjectDisposedException
Thrown if the object has been disposed.
GetGraphStatistics(string)
Gets performance statistics for a graph.
public CudaGraphStatistics GetGraphStatistics(string graphId)
Parameters
graphIdstringThe identifier of the graph for which to retrieve statistics.
Returns
- CudaGraphStatistics
A CudaGraphStatistics object containing performance metrics.
Exceptions
- ObjectDisposedException
Thrown if the object has been disposed.
InstantiateGraphAsync(string, CancellationToken)
Instantiates a graph for execution.
public Task<CudaGraphInstance> InstantiateGraphAsync(string graphId, CancellationToken cancellationToken = default)
Parameters
graphIdstringThe identifier of the graph to instantiate.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<CudaGraphInstance>
A task that represents the asynchronous instantiation operation, returning the graph instance.
Exceptions
- ObjectDisposedException
Thrown if the object has been disposed.
- ArgumentException
Thrown if the specified graph is not found.
UpdateGraphAsync(CudaGraphInstance, CudaGraphUpdateParameters, CancellationToken)
Updates a graph instance with new parameters.
public Task<bool> UpdateGraphAsync(CudaGraphInstance instance, CudaGraphUpdateParameters updateParams, CancellationToken cancellationToken = default)
Parameters
instanceCudaGraphInstanceThe graph instance to update.
updateParamsCudaGraphUpdateParametersThe parameters for the update operation.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
Exceptions
- ObjectDisposedException
Thrown if the object has been disposed.