Table of Contents

Class MetalUnifiedMemoryOptimizer

Namespace
DotCompute.Backends.Metal.Memory
Assembly
DotCompute.Backends.Metal.dll

Optimizer for unified memory access patterns on Apple Silicon.

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

Remarks

Provides optimization hints for unified memory architectures (M1/M2/M3/M4).

Constructors

MetalUnifiedMemoryOptimizer(nint, ILogger<MetalUnifiedMemoryOptimizer>)

Initializes a new instance of the MetalUnifiedMemoryOptimizer class.

public MetalUnifiedMemoryOptimizer(nint device, ILogger<MetalUnifiedMemoryOptimizer> logger)

Parameters

device nint

The Metal device handle.

logger ILogger<MetalUnifiedMemoryOptimizer>

The logger instance.

Properties

DeviceInfo

Gets the device information.

public MetalDeviceInfo DeviceInfo { get; }

Property Value

MetalDeviceInfo

IsAppleSilicon

Gets whether the system is running on Apple Silicon with unified memory.

public bool IsAppleSilicon { get; }

Property Value

bool

IsUnifiedMemory

Gets whether the device has unified memory architecture.

public bool IsUnifiedMemory { get; }

Property Value

bool

TotalBytesTransferred

Gets the total bytes transferred via zero-copy operations.

public long TotalBytesTransferred { get; }

Property Value

long

TotalZeroCopyOperations

Gets the total number of zero-copy operations tracked.

public long TotalZeroCopyOperations { get; }

Property Value

long

Methods

Dispose()

Disposes the memory optimizer.

public void Dispose()

EstimatePerformanceGain(long, MemoryUsagePattern)

Estimates the performance gain for the given allocation.

public double EstimatePerformanceGain(long sizeInBytes, MemoryUsagePattern pattern)

Parameters

sizeInBytes long

The allocation size in bytes.

pattern MemoryUsagePattern

The memory usage pattern.

Returns

double

The estimated performance multiplier (1.0 = no gain).

GetOptimalStorageMode(MemoryOptions)

Gets the optimal storage mode for the given memory options.

public MetalStorageMode GetOptimalStorageMode(MemoryOptions options)

Parameters

options MemoryOptions

The memory options.

Returns

MetalStorageMode

The optimal Metal storage mode.

GetOptimalStorageMode(MemoryUsagePattern)

Gets the optimal storage mode for the given memory usage pattern.

public MetalStorageMode GetOptimalStorageMode(MemoryUsagePattern pattern)

Parameters

pattern MemoryUsagePattern

The memory usage pattern.

Returns

MetalStorageMode

The optimal Metal storage mode.

GetPerformanceStatistics()

Gets performance statistics for zero-copy operations.

[SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = "Method performs calculations and returns a new dictionary each time")]
public Dictionary<string, object> GetPerformanceStatistics()

Returns

Dictionary<string, object>

A dictionary of performance statistics.

TrackZeroCopyOperation(long)

Tracks a zero-copy operation for statistics.

public void TrackZeroCopyOperation(long sizeInBytes)

Parameters

sizeInBytes long

The size of the zero-copy operation.