Class UnifiedMemoryManagerExtensions
- Namespace
- DotCompute.Core.Extensions
- Assembly
- DotCompute.Core.dll
Extension methods for IUnifiedMemoryManager to provide additional memory query operations and backward compatibility with legacy APIs that expect these methods.
public static class UnifiedMemoryManagerExtensions
- Inheritance
-
UnifiedMemoryManagerExtensions
- Inherited Members
Methods
AllocatePinnedAsync<T>(IUnifiedMemoryManager, int, CancellationToken)
Allocates pinned (page-locked) host memory for faster transfers. This is primarily a CUDA feature.
[RequiresUnreferencedCode("This method uses reflection to dynamically invoke generic methods and may not work in AOT scenarios.")]
[RequiresDynamicCode("This method uses reflection to dynamically invoke generic methods and may not work in AOT scenarios.")]
public static ValueTask<IUnifiedMemoryBuffer<T>> AllocatePinnedAsync<T>(this IUnifiedMemoryManager memoryManager, int count, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
memoryManagerIUnifiedMemoryManagerThe memory manager.
countintThe number of elements to allocate.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer<T>>
A pinned memory buffer.
Type Parameters
TThe element type.
AllocateUnifiedAsync<T>(IUnifiedMemoryManager, int, CancellationToken)
Allocates unified memory that is accessible by both host and device. This is primarily a CUDA feature.
[RequiresUnreferencedCode("This method uses reflection to dynamically invoke generic methods and may not work in AOT scenarios.")]
[RequiresDynamicCode("This method uses reflection to dynamically invoke generic methods and may not work in AOT scenarios.")]
public static ValueTask<IUnifiedMemoryBuffer<T>> AllocateUnifiedAsync<T>(this IUnifiedMemoryManager memoryManager, int count, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
memoryManagerIUnifiedMemoryManagerThe memory manager.
countintThe number of elements to allocate.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask<IUnifiedMemoryBuffer<T>>
A unified memory buffer.
Type Parameters
TThe element type.
GetAvailableMemory(IUnifiedMemoryManager)
Gets the available memory in bytes that can be allocated by this memory manager. This delegates to the Statistics property or calculates from existing properties.
public static long GetAvailableMemory(this IUnifiedMemoryManager manager)
Parameters
managerIUnifiedMemoryManagerThe unified memory manager instance.
Returns
- long
The amount of available memory in bytes.
Exceptions
- ArgumentNullException
Thrown when manager is null.
GetMemorySummary(IUnifiedMemoryManager)
Gets a detailed memory summary containing all key memory metrics.
public static string GetMemorySummary(this IUnifiedMemoryManager manager)
Parameters
managerIUnifiedMemoryManagerThe unified memory manager instance.
Returns
- string
A formatted string with memory usage details.
Exceptions
- ArgumentNullException
Thrown when manager is null.
GetMemoryUtilizationPercentage(IUnifiedMemoryManager)
Calculates the memory utilization percentage (0-100) based on used vs total memory.
public static double GetMemoryUtilizationPercentage(this IUnifiedMemoryManager manager)
Parameters
managerIUnifiedMemoryManagerThe unified memory manager instance.
Returns
- double
The memory utilization as a percentage (0-100).
Exceptions
- ArgumentNullException
Thrown when manager is null.
GetTotalMemory(IUnifiedMemoryManager)
Gets the total memory in bytes that this memory manager can potentially manage. This represents the total capacity of the memory subsystem.
public static long GetTotalMemory(this IUnifiedMemoryManager manager)
Parameters
managerIUnifiedMemoryManagerThe unified memory manager instance.
Returns
- long
The total memory capacity in bytes.
Exceptions
- ArgumentNullException
Thrown when manager is null.
GetUsedMemory(IUnifiedMemoryManager)
Gets the currently used memory in bytes by this memory manager. This represents the amount of memory that has been allocated and is currently in use.
public static long GetUsedMemory(this IUnifiedMemoryManager manager)
Parameters
managerIUnifiedMemoryManagerThe unified memory manager instance.
Returns
- long
The amount of used memory in bytes.
Exceptions
- ArgumentNullException
Thrown when manager is null.
IsUnderMemoryPressure(IUnifiedMemoryManager, double)
Determines if the memory manager is under memory pressure based on utilization.
public static bool IsUnderMemoryPressure(this IUnifiedMemoryManager manager, double pressureThreshold = 85)
Parameters
managerIUnifiedMemoryManagerThe unified memory manager instance.
pressureThresholddoubleThe threshold percentage (0-100) above which memory pressure is considered high. Defaults to 85%.
Returns
- bool
True if memory utilization is above the pressure threshold, false otherwise.
Exceptions
- ArgumentNullException
Thrown when manager is null.
- ArgumentOutOfRangeException
Thrown when pressureThreshold is not between 0 and 100.