Table of Contents

Class MetalGraphNode

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

Represents an individual computation node in a Metal compute graph. Each node encapsulates a single operation (kernel, memory copy, barrier) with its dependencies and resource requirements.

public sealed class MetalGraphNode
Inheritance
MetalGraphNode
Inherited Members

Constructors

MetalGraphNode(string, MetalNodeType)

Initializes a new instance of the MetalGraphNode class.

public MetalGraphNode(string id, MetalNodeType type)

Parameters

id string

The unique identifier for this node.

type MetalNodeType

The type of operation this node represents.

Exceptions

ArgumentException

Thrown when id is null or whitespace.

Properties

Arguments

Gets or sets the kernel arguments array.

public IReadOnlyList<object> Arguments { get; set; }

Property Value

IReadOnlyList<object>

CanBeFused

Gets or sets a value indicating whether this node can be fused with adjacent nodes.

public bool CanBeFused { get; set; }

Property Value

bool

CopySize

Gets or sets the size in bytes for memory operations.

public long CopySize { get; set; }

Property Value

long

CreatedAt

Gets the timestamp when this node was created.

public DateTimeOffset CreatedAt { get; }

Property Value

DateTimeOffset

Dependencies

Gets or sets the list of nodes that this node depends on.

public IList<MetalGraphNode> Dependencies { get; }

Property Value

IList<MetalGraphNode>

DestinationBuffer

Gets or sets the destination buffer for memory operations.

public nint DestinationBuffer { get; set; }

Property Value

nint

EstimatedMemoryUsage

Gets or sets the estimated memory usage of this node in bytes.

public long EstimatedMemoryUsage { get; set; }

Property Value

long

ExecutionDuration

Gets the execution duration, if the node has completed.

public TimeSpan? ExecutionDuration { get; }

Property Value

TimeSpan?

ExecutionEndTime

Gets or sets the timestamp when this node completed execution.

public DateTimeOffset? ExecutionEndTime { get; set; }

Property Value

DateTimeOffset?

ExecutionError

Gets or sets any error that occurred during execution.

public Exception? ExecutionError { get; set; }

Property Value

Exception

ExecutionStartTime

Gets or sets the timestamp when this node started execution.

public DateTimeOffset? ExecutionStartTime { get; set; }

Property Value

DateTimeOffset?

ExecutionState

Gets or sets the current execution state of this node.

public MetalNodeExecutionState ExecutionState { get; set; }

Property Value

MetalNodeExecutionState

FillValue

Gets or sets the fill value for memory set operations.

public byte FillValue { get; set; }

Property Value

byte

Id

Gets the unique identifier for this node.

public string Id { get; }

Property Value

string

IsMemoryOptimized

Gets or sets a value indicating whether this node's memory access patterns are optimized.

public bool IsMemoryOptimized { get; set; }

Property Value

bool

Kernel

Gets or sets the compiled Metal kernel for kernel nodes.

public ICompiledKernel? Kernel { get; set; }

Property Value

ICompiledKernel

MetalResources

Gets or sets Metal-specific resources associated with this node.

public Dictionary<string, object> MetalResources { get; }

Property Value

Dictionary<string, object>

OptimizationHints

Gets or sets optimization hints for this node.

public MetalOptimizationHints OptimizationHints { get; set; }

Property Value

MetalOptimizationHints

Priority

Gets or sets the priority level for this node's execution.

public MetalNodePriority Priority { get; set; }

Property Value

MetalNodePriority

RequiredEncoderType

Gets or sets the Metal command encoder type required for this node.

public MetalCommandEncoderType RequiredEncoderType { get; set; }

Property Value

MetalCommandEncoderType

SourceBuffer

Gets or sets the source buffer for memory operations.

public nint SourceBuffer { get; set; }

Property Value

nint

ThreadgroupsPerGrid

Gets or sets the number of threadgroups to dispatch for kernel nodes.

public MTLSize ThreadgroupsPerGrid { get; set; }

Property Value

MTLSize

ThreadsPerThreadgroup

Gets or sets the number of threads per threadgroup for kernel nodes.

public MTLSize ThreadsPerThreadgroup { get; set; }

Property Value

MTLSize

Type

Gets the type of operation this node represents.

public MetalNodeType Type { get; }

Property Value

MetalNodeType

UserData

Gets or sets custom user data associated with this node.

public object? UserData { get; set; }

Property Value

object

Methods

AddDependency(MetalGraphNode)

Adds a dependency to this node.

public void AddDependency(MetalGraphNode dependency)

Parameters

dependency MetalGraphNode

The node that this node depends on.

Exceptions

ArgumentNullException

Thrown when dependency is null.

InvalidOperationException

Thrown when adding the dependency would create a cycle.

Clone(string)

Creates a shallow copy of this node with a new ID.

public MetalGraphNode Clone(string newId)

Parameters

newId string

The ID for the cloned node.

Returns

MetalGraphNode

A new node instance that is a copy of this node.

DependsOn(string)

Determines if this node depends directly on the specified node.

public bool DependsOn(string nodeId)

Parameters

nodeId string

The ID of the node to check for dependency.

Returns

bool

true if this node depends on the specified node; otherwise, false.

GetTransitiveDependencies()

Gets all transitive dependencies of this node.

public HashSet<MetalGraphNode> GetTransitiveDependencies()

Returns

HashSet<MetalGraphNode>

A set of all nodes that this node transitively depends on.

HasDependencies()

Determines if this node has any dependencies.

public bool HasDependencies()

Returns

bool

true if the node has dependencies; otherwise, false.

RemoveDependency(string)

Removes a dependency from this node.

public bool RemoveDependency(string dependencyId)

Parameters

dependencyId string

The ID of the dependency to remove.

Returns

bool

true if the dependency was found and removed; otherwise, false.

ToString()

Returns a string representation of this node.

public override string ToString()

Returns

string

A string containing the node's type and ID.

Validate()

Validates this node's configuration and resource requirements.

public IReadOnlyList<string> Validate()

Returns

IReadOnlyList<string>

A list of validation errors, or an empty list if valid.