Table of Contents

Class MetalGraphManager

Namespace
DotCompute.Backends.Metal.Execution.Graph
Assembly
DotCompute.Backends.Metal.dll

Provides centralized management of Metal compute graphs including creation, optimization, execution, and lifecycle management with comprehensive performance monitoring.

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

Constructors

MetalGraphManager(ILogger<MetalGraphManager>, MetalGraphConfiguration?)

Initializes a new instance of the MetalGraphManager class.

public MetalGraphManager(ILogger<MetalGraphManager> logger, MetalGraphConfiguration? defaultConfiguration = null)

Parameters

logger ILogger<MetalGraphManager>

The logger instance for graph management operations.

defaultConfiguration MetalGraphConfiguration

Default configuration for new graphs.

Properties

GraphCount

Gets the number of graphs currently managed.

public int GraphCount { get; }

Property Value

int

Graphs

Gets the collection of active graphs managed by this instance.

public IReadOnlyDictionary<string, MetalComputeGraph> Graphs { get; }

Property Value

IReadOnlyDictionary<string, MetalComputeGraph>

Statistics

Gets the statistics for all managed graphs.

public IReadOnlyDictionary<string, MetalGraphStatistics> Statistics { get; }

Property Value

IReadOnlyDictionary<string, MetalGraphStatistics>

Methods

AnalyzeGraphAsync(string)

Analyzes a graph for optimization opportunities without applying changes.

public Task<MetalGraphAnalysis?> AnalyzeGraphAsync(string graphName)

Parameters

graphName string

The name of the graph to analyze.

Returns

Task<MetalGraphAnalysis>

The analysis result, or null if the graph was not found.

BuildAllGraphsAsync()

Builds all graphs that are not yet built.

public Task BuildAllGraphsAsync()

Returns

Task

A task representing the asynchronous build operation.

CloneGraph(string, string, MetalGraphConfiguration?)

Clones an existing graph with a new name.

public MetalComputeGraph? CloneGraph(string sourceName, string targetName, MetalGraphConfiguration? configuration = null)

Parameters

sourceName string

The name of the source graph to clone.

targetName string

The name for the cloned graph.

configuration MetalGraphConfiguration

Optional configuration for the cloned graph.

Returns

MetalComputeGraph

The cloned graph, or null if the source graph was not found.

Exceptions

ArgumentException

Thrown when target name already exists.

CreateGraph(string, MetalGraphConfiguration?)

Creates a new Metal compute graph with the specified configuration.

public MetalComputeGraph CreateGraph(string name, MetalGraphConfiguration? configuration = null)

Parameters

name string

The unique name for the graph.

configuration MetalGraphConfiguration

Optional configuration for the graph.

Returns

MetalComputeGraph

The created Metal compute graph.

Exceptions

ArgumentException

Thrown when name is null, empty, or already exists.

ObjectDisposedException

Thrown when the manager has been disposed.

Dispose()

Releases all resources used by the Metal graph manager.

public void Dispose()

ExecuteGraphAsync(string, nint, CancellationToken)

Executes a graph using the specified Metal command queue.

public Task<MetalGraphExecutionResult?> ExecuteGraphAsync(string graphName, nint commandQueue, CancellationToken cancellationToken = default)

Parameters

graphName string

The name of the graph to execute.

commandQueue nint

The Metal command queue for execution.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<MetalGraphExecutionResult>

The execution result, or null if the graph was not found.

GenerateComprehensiveReport()

Generates a comprehensive report of all graph statistics.

public string GenerateComprehensiveReport()

Returns

string

A formatted report string.

GetAggregatedStatistics()

Gets aggregated statistics for all managed graphs.

public AggregatedGraphStatistics GetAggregatedStatistics()

Returns

AggregatedGraphStatistics

Aggregated statistics across all graphs.

GetGraph(string)

Gets an existing graph by name.

public MetalComputeGraph? GetGraph(string name)

Parameters

name string

The name of the graph to retrieve.

Returns

MetalComputeGraph

The graph with the specified name, or null if not found.

GetGraphStatistics(string)

Gets comprehensive statistics for a specific graph.

public MetalGraphStatistics? GetGraphStatistics(string graphName)

Parameters

graphName string

The name of the graph.

Returns

MetalGraphStatistics

The graph statistics, or null if not found.

OptimizeGraphAsync(string, MetalOptimizationParameters?)

Optimizes a graph for maximum performance and efficiency.

public Task<MetalOptimizationResult?> OptimizeGraphAsync(string graphName, MetalOptimizationParameters? parameters = null)

Parameters

graphName string

The name of the graph to optimize.

parameters MetalOptimizationParameters

Optional optimization parameters.

Returns

Task<MetalOptimizationResult>

The optimization result, or null if the graph was not found.

RemoveGraph(string)

Removes and disposes a graph.

public bool RemoveGraph(string name)

Parameters

name string

The name of the graph to remove.

Returns

bool

True if the graph was found and removed; otherwise, false.

ResetAllStatistics()

Resets statistics for all graphs.

public void ResetAllStatistics()

ResetGraphStatistics(string)

Resets statistics for a specific graph.

public bool ResetGraphStatistics(string graphName)

Parameters

graphName string

The name of the graph to reset statistics for.

Returns

bool

True if statistics were reset; false if graph not found.