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
loggerILogger<MetalGraphManager>The logger instance for graph management operations.
defaultConfigurationMetalGraphConfigurationDefault configuration for new graphs.
Properties
GraphCount
Gets the number of graphs currently managed.
public int GraphCount { get; }
Property Value
Graphs
Gets the collection of active graphs managed by this instance.
public IReadOnlyDictionary<string, MetalComputeGraph> Graphs { get; }
Property Value
Statistics
Gets the statistics for all managed graphs.
public IReadOnlyDictionary<string, MetalGraphStatistics> Statistics { get; }
Property Value
Methods
AnalyzeGraphAsync(string)
Analyzes a graph for optimization opportunities without applying changes.
public Task<MetalGraphAnalysis?> AnalyzeGraphAsync(string graphName)
Parameters
graphNamestringThe 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
sourceNamestringThe name of the source graph to clone.
targetNamestringThe name for the cloned graph.
configurationMetalGraphConfigurationOptional 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
namestringThe unique name for the graph.
configurationMetalGraphConfigurationOptional 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
graphNamestringThe name of the graph to execute.
commandQueuenintThe Metal command queue for execution.
cancellationTokenCancellationTokenOptional 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
namestringThe 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
graphNamestringThe 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
graphNamestringThe name of the graph to optimize.
parametersMetalOptimizationParametersOptional 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
namestringThe 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
graphNamestringThe name of the graph to reset statistics for.
Returns
- bool
True if statistics were reset; false if graph not found.