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
devicenintThe Metal device handle.
loggerILogger<MetalUnifiedMemoryOptimizer>The logger instance.
Properties
DeviceInfo
Gets the device information.
public MetalDeviceInfo DeviceInfo { get; }
Property Value
IsAppleSilicon
Gets whether the system is running on Apple Silicon with unified memory.
public bool IsAppleSilicon { get; }
Property Value
IsUnifiedMemory
Gets whether the device has unified memory architecture.
public bool IsUnifiedMemory { get; }
Property Value
TotalBytesTransferred
Gets the total bytes transferred via zero-copy operations.
public long TotalBytesTransferred { get; }
Property Value
TotalZeroCopyOperations
Gets the total number of zero-copy operations tracked.
public long TotalZeroCopyOperations { get; }
Property Value
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
sizeInByteslongThe allocation size in bytes.
patternMemoryUsagePatternThe 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
optionsMemoryOptionsThe 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
patternMemoryUsagePatternThe 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
sizeInByteslongThe size of the zero-copy operation.