Table of Contents

Class CudaMemoryBuffer

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

Represents a CUDA memory buffer allocated on the GPU device.

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

Remarks

Initializes a new instance of the CudaMemoryBuffer class.

Constructors

CudaMemoryBuffer(nint, long, MemoryOptions)

Represents a CUDA memory buffer allocated on the GPU device.

public CudaMemoryBuffer(nint devicePointer, long sizeInBytes, MemoryOptions options = MemoryOptions.None)

Parameters

devicePointer nint

The device memory pointer.

sizeInBytes long

The size in bytes.

options MemoryOptions

Memory allocation options.

Remarks

Initializes a new instance of the CudaMemoryBuffer class.

Properties

DevicePointer

Gets the device memory pointer.

public nint DevicePointer { get; }

Property Value

nint

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

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

Allocate(CudaDevice, long, MemoryOptions)

Allocates a new CUDA memory buffer.

public static CudaMemoryBuffer Allocate(CudaDevice device, long sizeInBytes, MemoryOptions options = MemoryOptions.None)

Parameters

device CudaDevice
sizeInBytes long
options MemoryOptions

Returns

CudaMemoryBuffer

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

CopyFromHost<T>(ReadOnlySpan<T>)

Copies data from host memory to this device buffer.

public void CopyFromHost<T>(ReadOnlySpan<T> source) where T : unmanaged

Parameters

source ReadOnlySpan<T>

Type Parameters

T

CopyTo(CudaMemoryBuffer)

Copies data from this buffer to another buffer.

public void CopyTo(CudaMemoryBuffer destination)

Parameters

destination CudaMemoryBuffer

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

CopyToHost<T>(Span<T>)

Copies data from this device buffer to host memory.

public void CopyToHost<T>(Span<T> destination) where T : unmanaged

Parameters

destination Span<T>

Type Parameters

T

Dispose()

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

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.