Table of Contents

Interface IUnifiedMemoryBuffer<T>

Namespace
DotCompute.Abstractions
Assembly
DotCompute.Abstractions.dll

Unified memory buffer interface that combines the best features from all buffer implementations. This is the ONLY memory buffer interface in the entire solution.

public interface IUnifiedMemoryBuffer<T> : IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable where T : unmanaged

Type Parameters

T

The unmanaged element type.

Inherited Members
Extension Methods

Properties

Accelerator

Gets the accelerator this buffer is associated with.

IAccelerator Accelerator { get; }

Property Value

IAccelerator

ElementCount

Gets the number of elements in the buffer (alias for Length).

int ElementCount { get; }

Property Value

int

IsDirty

Gets whether the buffer has been modified and needs synchronization.

bool IsDirty { get; }

Property Value

bool

IsOnDevice

Gets whether the buffer is currently available on the device.

bool IsOnDevice { get; }

Property Value

bool

IsOnHost

Gets whether the buffer is currently available on the host.

bool IsOnHost { get; }

Property Value

bool

Length

Gets the number of elements in the buffer.

int Length { get; }

Property Value

int

Methods

AsMemory()

Gets a memory handle to the host memory. Will trigger transfer if needed.

Memory<T> AsMemory()

Returns

Memory<T>

AsReadOnlyMemory()

Gets a read-only memory handle to the host memory. Will trigger transfer if needed.

ReadOnlyMemory<T> AsReadOnlyMemory()

Returns

ReadOnlyMemory<T>

AsReadOnlySpan()

Gets a read-only span to the host memory. Will trigger transfer if needed.

ReadOnlySpan<T> AsReadOnlySpan()

Returns

ReadOnlySpan<T>

AsSpan()

Gets a span to the host memory. Will trigger transfer if needed.

Span<T> AsSpan()

Returns

Span<T>

AsType<TNew>()

Creates a view of this buffer with a different element type.

IUnifiedMemoryBuffer<TNew> AsType<TNew>() where TNew : unmanaged

Returns

IUnifiedMemoryBuffer<TNew>

A view of this buffer as the new type.

Type Parameters

TNew

The new element type.

CopyFromAsync(ReadOnlyMemory<T>, CancellationToken)

Copies data from a source memory into this buffer.

ValueTask CopyFromAsync(ReadOnlyMemory<T> source, CancellationToken cancellationToken = default)

Parameters

source ReadOnlyMemory<T>
cancellationToken CancellationToken

Returns

ValueTask

CopyToAsync(IUnifiedMemoryBuffer<T>, CancellationToken)

Copies data from this buffer to another buffer.

ValueTask CopyToAsync(IUnifiedMemoryBuffer<T> destination, CancellationToken cancellationToken = default)

Parameters

destination IUnifiedMemoryBuffer<T>
cancellationToken CancellationToken

Returns

ValueTask

CopyToAsync(int, IUnifiedMemoryBuffer<T>, int, int, CancellationToken)

Copies data from this buffer to another buffer with specified ranges.

ValueTask CopyToAsync(int sourceOffset, IUnifiedMemoryBuffer<T> destination, int destinationOffset, int count, CancellationToken cancellationToken = default)

Parameters

sourceOffset int
destination IUnifiedMemoryBuffer<T>
destinationOffset int
count int
cancellationToken CancellationToken

Returns

ValueTask

CopyToAsync(Memory<T>, CancellationToken)

Copies data from this buffer to a destination memory.

ValueTask CopyToAsync(Memory<T> destination, CancellationToken cancellationToken = default)

Parameters

destination Memory<T>
cancellationToken CancellationToken

Returns

ValueTask

EnsureOnDevice()

Ensures the buffer is available on the device. Triggers transfer if needed.

void EnsureOnDevice()

EnsureOnDeviceAsync(AcceleratorContext, CancellationToken)

Asynchronously ensures the buffer is available on the device.

ValueTask EnsureOnDeviceAsync(AcceleratorContext context = default, CancellationToken cancellationToken = default)

Parameters

context AcceleratorContext
cancellationToken CancellationToken

Returns

ValueTask

EnsureOnHost()

Ensures the buffer is available on the host. Triggers transfer if needed.

void EnsureOnHost()

EnsureOnHostAsync(AcceleratorContext, CancellationToken)

Asynchronously ensures the buffer is available on the host.

ValueTask EnsureOnHostAsync(AcceleratorContext context = default, CancellationToken cancellationToken = default)

Parameters

context AcceleratorContext
cancellationToken CancellationToken

Returns

ValueTask

FillAsync(T, int, int, CancellationToken)

Fills a portion of this buffer with a specified value.

ValueTask FillAsync(T value, int offset, int count, CancellationToken cancellationToken = default)

Parameters

value T
offset int
count int
cancellationToken CancellationToken

Returns

ValueTask

FillAsync(T, CancellationToken)

Fills this buffer with a specified value.

ValueTask FillAsync(T value, CancellationToken cancellationToken = default)

Parameters

value T
cancellationToken CancellationToken

Returns

ValueTask

GetDeviceMemory()

Gets the device memory handle. Will trigger transfer if needed.

DeviceMemory GetDeviceMemory()

Returns

DeviceMemory

Map(MapMode)

Maps this buffer to host memory for direct access.

MappedMemory<T> Map(MapMode mode = MapMode.ReadWrite)

Parameters

mode MapMode

The mapping mode.

Returns

MappedMemory<T>

A mapped memory region.

MapAsync(MapMode, CancellationToken)

Asynchronously maps this buffer to host memory.

ValueTask<MappedMemory<T>> MapAsync(MapMode mode = MapMode.ReadWrite, CancellationToken cancellationToken = default)

Parameters

mode MapMode

The mapping mode.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask<MappedMemory<T>>

A task that returns the mapped memory region.

MapRange(int, int, MapMode)

Maps a portion of this buffer to host memory for direct access.

MappedMemory<T> MapRange(int offset, int length, MapMode mode = MapMode.ReadWrite)

Parameters

offset int

The offset to start mapping at.

length int

The number of elements to map.

mode MapMode

The mapping mode.

Returns

MappedMemory<T>

A mapped memory region.

MarkDeviceDirty()

Marks the buffer as modified on the device.

void MarkDeviceDirty()

MarkHostDirty()

Marks the buffer as modified on the host.

void MarkHostDirty()

Slice(int, int)

Creates a slice of this buffer.

IUnifiedMemoryBuffer<T> Slice(int offset, int length)

Parameters

offset int

The offset in elements.

length int

The length of the slice in elements.

Returns

IUnifiedMemoryBuffer<T>

A slice of this buffer.

Synchronize()

Synchronizes the buffer state between host and device.

void Synchronize()

SynchronizeAsync(AcceleratorContext, CancellationToken)

Asynchronously synchronizes the buffer state between host and device.

ValueTask SynchronizeAsync(AcceleratorContext context = default, CancellationToken cancellationToken = default)

Parameters

context AcceleratorContext
cancellationToken CancellationToken

Returns

ValueTask