Class CudaPinnedMemoryAllocator
- Namespace
- DotCompute.Backends.CUDA.Memory
- Assembly
- DotCompute.Backends.CUDA.dll
Manages pinned (page-locked) host memory for high-bandwidth transfers. Pinned memory provides up to 10x bandwidth improvement (20GB/s vs 2GB/s).
public sealed class CudaPinnedMemoryAllocator : IDisposable
- Inheritance
-
CudaPinnedMemoryAllocator
- Implements
- Inherited Members
- Extension Methods
Constructors
CudaPinnedMemoryAllocator(CudaContext, ILogger, long)
Initializes a new instance of the CudaPinnedMemoryAllocator class.
public CudaPinnedMemoryAllocator(CudaContext context, ILogger logger, long maxPinnedMemory = 4294967296)
Parameters
contextCudaContextThe context.
loggerILoggerThe logger.
maxPinnedMemorylongThe max pinned memory.
Properties
AvailablePinnedMemory
Gets the available pinned memory.
public long AvailablePinnedMemory { get; }
Property Value
MaxPinnedMemory
Gets the maximum amount of pinned memory that can be allocated.
public long MaxPinnedMemory { get; }
Property Value
Statistics
Gets memory allocation statistics.
public PinnedMemoryStatistics Statistics { get; }
Property Value
TotalAllocated
Gets the total amount of pinned memory currently allocated.
public long TotalAllocated { get; }
Property Value
Methods
AllocateMappedAsync<T>(long, CancellationToken)
Allocates mapped pinned memory accessible from both host and device.
public Task<IPinnedMemoryBuffer<T>> AllocateMappedAsync<T>(long count, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
countlongcancellationTokenCancellationToken
Returns
Type Parameters
T
AllocatePinnedAsync<T>(long, CudaHostAllocFlags, CancellationToken)
Allocates pinned host memory for high-bandwidth transfers.
public Task<IPinnedMemoryBuffer<T>> AllocatePinnedAsync<T>(long count, CudaHostAllocFlags flags = CudaHostAllocFlags.None, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
countlongflagsCudaHostAllocFlagscancellationTokenCancellationToken
Returns
Type Parameters
T
AllocatePortableAsync<T>(long, CancellationToken)
Allocates portable pinned memory accessible from all CUDA contexts.
public Task<IPinnedMemoryBuffer<T>> AllocatePortableAsync<T>(long count, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
countlongcancellationTokenCancellationToken
Returns
Type Parameters
T
AllocateWriteCombinedAsync<T>(long, CancellationToken)
Allocates write-combined pinned memory for optimal GPU write performance.
public Task<IPinnedMemoryBuffer<T>> AllocateWriteCombinedAsync<T>(long count, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
countlongcancellationTokenCancellationToken
Returns
Type Parameters
T
Dispose()
Performs dispose.
public void Dispose()
RegisterHostMemoryAsync(nint, long, CudaHostRegisterFlags, CancellationToken)
Registers existing host memory as pinned for improved transfer performance.
public Task<IPinnedMemoryRegistration> RegisterHostMemoryAsync(nint hostPtr, long sizeInBytes, CudaHostRegisterFlags flags = CudaHostRegisterFlags.None, CancellationToken cancellationToken = default)
Parameters
hostPtrnintsizeInByteslongflagsCudaHostRegisterFlagscancellationTokenCancellationToken