Table of Contents

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

context OpenCLContext

The OpenCL context for command execution.

streamManager OpenCLStreamManager

The stream manager for command queue allocation.

eventManager OpenCLEventManager

The event manager for synchronization.

profiler OpenCLProfiler

The profiler for performance monitoring.

logger ILogger<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

graph Graph

The 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

name string

The 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

graph Graph

The graph to execute.

parameters GraphParameters

The parameters for graph execution.

cancellationToken CancellationToken

Token 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

name string

The name of the graph to retrieve.

Returns

Task<Graph>

The cached graph, or null if not found.