Table of Contents

Class CudaRawMemoryBuffer

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

Raw untyped CUDA memory buffer for byte-level operations.

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

Remarks

Initializes a new instance of the CudaRawMemoryBuffer class.

Constructors

CudaRawMemoryBuffer(nint, long, bool)

Raw untyped CUDA memory buffer for byte-level operations.

public CudaRawMemoryBuffer(nint devicePtr, long sizeInBytes, bool ownsMemory = true)

Parameters

devicePtr nint

The device memory pointer.

sizeInBytes long

The size in bytes.

ownsMemory bool

Whether this buffer owns the memory.

Remarks

Initializes a new instance of the CudaRawMemoryBuffer class.

Properties

DevicePointer

public nint DevicePointer { get; }

Property Value

nint

HostPointer

public nint HostPointer { get; }

Property Value

nint

IsDisposed

Gets whether the buffer has been disposed.

public bool IsDisposed { get; }

Property Value

bool

IsUnified

public static bool IsUnified { get; }

Property Value

bool

Location

public static MemoryLocation Location { get; }

Property Value

MemoryLocation

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

AsMemory()

public Memory<byte> AsMemory()

Returns

Memory<byte>

AsReadOnlySpan()

public ReadOnlySpan<byte> AsReadOnlySpan()

Returns

ReadOnlySpan<byte>

AsSpan()

public Span<byte> AsSpan()

Returns

Span<byte>

CopyFrom(IUnifiedMemoryBuffer)

public void CopyFrom(IUnifiedMemoryBuffer source)

Parameters

source IUnifiedMemoryBuffer

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

Copies data from a source memory into this buffer.

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

Parameters

source ReadOnlyMemory<TSource>

The source memory to copy from.

offset long

The offset in bytes where to start copying.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

A task representing the copy operation.

Type Parameters

TSource

CopyTo(IUnifiedMemoryBuffer)

public void CopyTo(IUnifiedMemoryBuffer destination)

Parameters

destination IUnifiedMemoryBuffer

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

Copies data from this buffer to a destination memory.

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

Parameters

destination Memory<TDest>

The destination memory to copy to.

offset long

The offset in bytes where to start copying from.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

A task representing the copy operation.

Type Parameters

TDest

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.

Prefetch(int)

public void Prefetch(int deviceId = -1)

Parameters

deviceId int

Synchronize()

public static void Synchronize()