Table of Contents

Class CpuMemoryBufferView<T>

Namespace
DotCompute.Core.Memory
Assembly
DotCompute.Core.dll

CPU memory buffer view implementation.

public sealed class CpuMemoryBufferView<T> : IUnifiedMemoryBuffer<T>, IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable where T : unmanaged

Type Parameters

T
Inheritance
CpuMemoryBufferView<T>
Implements
Inherited Members
Extension Methods

Constructors

CpuMemoryBufferView(CpuMemoryBuffer<T>, int, int)

Initializes a new instance of the CpuMemoryBufferView class.

public CpuMemoryBufferView(CpuMemoryBuffer<T> parent, int offset, int length)

Parameters

parent CpuMemoryBuffer<T>

The parent.

offset int

The offset.

length int

The length.

Properties

Accelerator

Gets or sets the accelerator.

public IAccelerator Accelerator { get; }

Property Value

IAccelerator

The accelerator.

IsDirty

Gets or sets a value indicating whether dirty.

public bool IsDirty { get; }

Property Value

bool

The is dirty.

IsDisposed

Gets or sets a value indicating whether disposed.

public bool IsDisposed { get; }

Property Value

bool

The is disposed.

IsOnDevice

Gets or sets a value indicating whether on device.

public bool IsOnDevice { get; }

Property Value

bool

The is on device.

IsOnHost

Gets or sets a value indicating whether on host.

public bool IsOnHost { get; }

Property Value

bool

The is on host.

Length

Gets or sets the length.

public int Length { get; }

Property Value

int

The length.

Options

Gets or sets the options.

public MemoryOptions Options { get; }

Property Value

MemoryOptions

The options.

SizeInBytes

Gets or sets the size in bytes.

public long SizeInBytes { get; }

Property Value

long

The size in bytes.

State

Gets or sets the state.

public BufferState State { get; }

Property Value

BufferState

The state.

Methods

AsMemory()

Gets as memory.

public Memory<T> AsMemory()

Returns

Memory<T>

The result of the operation.

AsReadOnlyMemory()

Gets as read only memory.

public ReadOnlyMemory<T> AsReadOnlyMemory()

Returns

ReadOnlyMemory<T>

The result of the operation.

AsReadOnlySpan()

Gets as read only span.

public ReadOnlySpan<T> AsReadOnlySpan()

Returns

ReadOnlySpan<T>

The result of the operation.

AsSpan()

Gets as span.

public Span<T> AsSpan()

Returns

Span<T>

The result of the operation.

AsType<TNew>()

Gets as type.

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

Returns

IUnifiedMemoryBuffer<TNew>

The result of the operation.

Type Parameters

TNew

The TNew type parameter.

CopyFromAsync(ReadOnlyMemory<T>, CancellationToken)

Gets copy from asynchronously.

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

Parameters

source ReadOnlyMemory<T>

The source.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

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

Copies data from source memory to this CPU buffer view with offset support.

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

Parameters

source ReadOnlyMemory<TSource>

Source data to copy from.

offset long

Offset into this view in bytes.

cancellationToken CancellationToken

Cancellation token for the operation.

Returns

ValueTask

Completed task when copy finishes.

Type Parameters

TSource

Type of elements to copy.

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

Gets copy from host asynchronously.

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

Parameters

source ReadOnlyMemory<TSource>

The source.

offset long

The offset.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

Type Parameters

TSource

The TSource type parameter.

CopyToAsync(IUnifiedMemoryBuffer<T>, CancellationToken)

Gets copy to asynchronously.

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

Parameters

destination IUnifiedMemoryBuffer<T>

The destination.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

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

Gets copy to asynchronously.

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

Parameters

sourceOffset int

The source offset.

destination IUnifiedMemoryBuffer<T>

The destination.

destinationOffset int

The destination offset.

count int

The count of elements to copy.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

CopyToAsync(Memory<T>, CancellationToken)

Gets copy to asynchronously.

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

Parameters

destination Memory<T>

The destination.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

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

Copies data from this CPU buffer view to destination memory with offset support.

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

Parameters

destination Memory<TDest>

Destination memory to copy to.

offset long

Offset into this view in bytes.

cancellationToken CancellationToken

Cancellation token for the operation.

Returns

ValueTask

Completed task when copy finishes.

Type Parameters

TDest

Type of elements to copy.

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

Gets copy to host asynchronously.

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

Parameters

destination Memory<TDest>

The destination.

offset long

The offset.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

Type Parameters

TDest

The TDest type parameter.

Dispose()

Performs dispose.

public void Dispose()

DisposeAsync()

Gets dispose asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

The result of the operation.

EnsureOnDevice()

Performs ensure on device.

public void EnsureOnDevice()

EnsureOnDeviceAsync(AcceleratorContext, CancellationToken)

Gets ensure on device asynchronously.

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

Parameters

context AcceleratorContext

The context.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

EnsureOnHost()

Performs ensure on host.

public void EnsureOnHost()

EnsureOnHostAsync(AcceleratorContext, CancellationToken)

Gets ensure on host asynchronously.

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

Parameters

context AcceleratorContext

The context.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

FillAsync(T, int, int, CancellationToken)

Gets fill asynchronously.

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

Parameters

value T

The value.

offset int

The offset.

count int

The count of elements to fill.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

FillAsync(T, CancellationToken)

Gets fill asynchronously.

public ValueTask FillAsync(T value, CancellationToken cancellationToken = default)

Parameters

value T

The value.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

GetDeviceMemory()

Gets the device memory.

public DeviceMemory GetDeviceMemory()

Returns

DeviceMemory

The device memory.

Map(MapMode)

Gets map.

public MappedMemory<T> Map(MapMode mode)

Parameters

mode MapMode

The mode.

Returns

MappedMemory<T>

The result of the operation.

MapAsync(MapMode, CancellationToken)

Gets map asynchronously.

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

Parameters

mode MapMode

The mode.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<MappedMemory<T>>

The result of the operation.

MapRange(int, int, MapMode)

Gets map range.

public MappedMemory<T> MapRange(int offset, int length, MapMode mode)

Parameters

offset int

The offset.

length int

The length.

mode MapMode

The mode.

Returns

MappedMemory<T>

The result of the operation.

MarkDeviceDirty()

Performs mark device dirty.

public void MarkDeviceDirty()

MarkHostDirty()

Performs mark host dirty.

public void MarkHostDirty()

Slice(int, int)

Gets slice.

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

Parameters

offset int

The offset.

length int

The length.

Returns

IUnifiedMemoryBuffer<T>

The result of the operation.

Synchronize()

Performs synchronize.

public void Synchronize()

SynchronizeAsync(AcceleratorContext, CancellationToken)

Gets synchronize asynchronously.

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

Parameters

context AcceleratorContext

The context.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.