Table of Contents

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

context CudaContext

The context.

logger ILogger

The logger.

maxPinnedMemory long

The max pinned memory.

Properties

AvailablePinnedMemory

Gets the available pinned memory.

public long AvailablePinnedMemory { get; }

Property Value

long

MaxPinnedMemory

Gets the maximum amount of pinned memory that can be allocated.

public long MaxPinnedMemory { get; }

Property Value

long

Statistics

Gets memory allocation statistics.

public PinnedMemoryStatistics Statistics { get; }

Property Value

PinnedMemoryStatistics

TotalAllocated

Gets the total amount of pinned memory currently allocated.

public long TotalAllocated { get; }

Property Value

long

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

count long
cancellationToken CancellationToken

Returns

Task<IPinnedMemoryBuffer<T>>

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

count long
flags CudaHostAllocFlags
cancellationToken CancellationToken

Returns

Task<IPinnedMemoryBuffer<T>>

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

count long
cancellationToken CancellationToken

Returns

Task<IPinnedMemoryBuffer<T>>

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

count long
cancellationToken CancellationToken

Returns

Task<IPinnedMemoryBuffer<T>>

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

hostPtr nint
sizeInBytes long
flags CudaHostRegisterFlags
cancellationToken CancellationToken

Returns

Task<IPinnedMemoryRegistration>