Class OpenCLCommandGraph
- Namespace
- DotCompute.Backends.OpenCL.Execution
- Assembly
- DotCompute.Backends.OpenCL.dll
Provides advanced command graph support for OpenCL operations with automatic parallelization, optimization, and reusable execution patterns.
public sealed class OpenCLCommandGraph : IAsyncDisposable
- Inheritance
-
OpenCLCommandGraph
- Implements
- Inherited Members
Remarks
Command graphs represent compute operations as directed acyclic graphs (DAGs), enabling advanced scheduling, automatic parallelization, and execution optimization.
Key features: - Automatic detection of parallel execution opportunities - Memory operation coalescing and optimization - Graph-level profiling and performance analysis - Reusable graph templates with parameter updates - Resource pooling and lifetime management
Thread Safety: This class is thread-safe for graph construction and execution. Multiple graphs can be executed concurrently on different streams.
Constructors
OpenCLCommandGraph(OpenCLContext, OpenCLStreamManager, OpenCLEventManager, OpenCLProfiler, ILogger<OpenCLCommandGraph>)
Initializes a new instance of the OpenCLCommandGraph class.
public OpenCLCommandGraph(OpenCLContext context, OpenCLStreamManager streamManager, OpenCLEventManager eventManager, OpenCLProfiler profiler, ILogger<OpenCLCommandGraph> logger)
Parameters
contextOpenCLContextThe OpenCL context for command execution.
streamManagerOpenCLStreamManagerThe stream manager for command queue allocation.
eventManagerOpenCLEventManagerThe event manager for synchronization.
profilerOpenCLProfilerThe profiler for performance monitoring.
loggerILogger<OpenCLCommandGraph>The logger for diagnostic messages.
Exceptions
- ArgumentNullException
Thrown when any parameter is null.
Methods
CacheGraphAsync(Graph)
Caches a graph for reuse, allowing efficient repeated execution.
public Task CacheGraphAsync(Graph graph)
Parameters
graphGraphThe graph to cache.
Returns
- Task
A task representing the cache operation.
Exceptions
- ArgumentNullException
Thrown when graph is null.
CreateGraph(string)
Creates a new graph builder for constructing command graphs.
public GraphBuilder CreateGraph(string name)
Parameters
namestringThe unique name for the graph.
Returns
- GraphBuilder
A new graph builder instance.
Exceptions
- ArgumentNullException
Thrown when name is null.
- ArgumentException
Thrown when name is empty or whitespace.
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.
ExecuteGraphAsync(Graph, GraphParameters, CancellationToken)
Executes a command graph asynchronously with the specified parameters.
public Task<GraphExecutionResult> ExecuteGraphAsync(Graph graph, GraphParameters parameters, CancellationToken cancellationToken = default)
Parameters
graphGraphThe graph to execute.
parametersGraphParametersThe parameters for graph execution.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task<GraphExecutionResult>
A task representing the graph execution result.
Exceptions
- ArgumentNullException
Thrown when graph or parameters is null.
- InvalidOperationException
Thrown when graph validation fails.
- OperationCanceledException
Thrown when the operation is cancelled.
GetCachedGraphAsync(string)
Retrieves a cached graph by name.
public Task<Graph?> GetCachedGraphAsync(string name)
Parameters
namestringThe name of the graph to retrieve.