Table of Contents

Class UnifiedMemoryBuffer

Namespace
DotCompute.Backends.CUDA.Memory.Models
Assembly
DotCompute.Backends.CUDA.dll

Represents a CUDA unified memory buffer accessible from both host and device.

public sealed class UnifiedMemoryBuffer : IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable
Inheritance
UnifiedMemoryBuffer
Implements
Inherited Members
Extension Methods

Remarks

Initializes a new instance of the UnifiedMemoryBuffer class.

Constructors

UnifiedMemoryBuffer(nint, long, int, CudaMemoryFlags)

Represents a CUDA unified memory buffer accessible from both host and device.

public UnifiedMemoryBuffer(nint pointer, long sizeInBytes, int deviceId, CudaMemoryFlags flags)

Parameters

pointer nint
sizeInBytes long
deviceId int
flags CudaMemoryFlags

Remarks

Initializes a new instance of the UnifiedMemoryBuffer class.

Properties

AccessStats

Gets the access pattern statistics.

public AccessPatternStats AccessStats { get; set; }

Property Value

AccessPatternStats

CurrentResidence

Gets or sets the current residence location.

public MemoryResidence CurrentResidence { get; set; }

Property Value

MemoryResidence

DeviceId

Gets the device ID associated with this buffer.

public int DeviceId { get; }

Property Value

int

Flags

Gets the managed memory flags used for allocation.

public CudaMemoryFlags Flags { get; }

Property Value

CudaMemoryFlags

IsDisposed

Gets whether the buffer has been disposed.

public bool IsDisposed { get; }

Property Value

bool

Options

Gets the memory allocation options.

public MemoryOptions Options { get; }

Property Value

MemoryOptions

Pointer

Gets the pointer to the unified memory.

public nint Pointer { get; }

Property Value

nint

SizeInBytes

Gets the size of the buffer in bytes.

public long SizeInBytes { get; }

Property Value

long

State

Gets the current state of the buffer.

public BufferState State { get; }

Property Value

BufferState

Methods

CopyFromAsync<T>(ReadOnlyMemory<T>, long, CancellationToken)

Asynchronously copies data from host memory to this buffer.

public ValueTask CopyFromAsync<T>(ReadOnlyMemory<T> source, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

source ReadOnlyMemory<T>
offset long
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

T

CopyToAsync<T>(Memory<T>, long, CancellationToken)

Asynchronously copies data from this buffer to host memory.

public ValueTask CopyToAsync<T>(Memory<T> destination, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged

Parameters

destination Memory<T>
offset long
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

T

Dispose()

Disposes the unified memory buffer.

public void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.