Table of Contents

Class CpuMemoryBuffer

Namespace
DotCompute.Backends.CPU.Accelerators
Assembly
DotCompute.Backends.CPU.dll

CPU-based memory buffer implementation that uses host system memory. Implements the IUnifiedMemoryBuffer interface for CPU computations.

public sealed class CpuMemoryBuffer : IUnifiedMemoryBuffer<byte>, IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable
Inheritance
CpuMemoryBuffer
Implements
Inherited Members
Extension Methods

Constructors

CpuMemoryBuffer(long, MemoryOptions, CpuMemoryManager, int, NumaMemoryPolicy, ILogger<CpuMemoryBuffer>?)

Initializes a new instance of the CpuMemoryBuffer class.

public CpuMemoryBuffer(long sizeInBytes, MemoryOptions options, CpuMemoryManager memoryManager, int numaNode, NumaMemoryPolicy policy, ILogger<CpuMemoryBuffer>? logger = null)

Parameters

sizeInBytes long

Size of the buffer in bytes.

options MemoryOptions

Memory allocation options.

memoryManager CpuMemoryManager

The memory manager that owns this buffer.

numaNode int

The NUMA node to allocate memory on.

policy NumaMemoryPolicy

The NUMA memory policy to use.

logger ILogger<CpuMemoryBuffer>

Optional logger for diagnostics.

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<byte> AsMemory()

Returns

Memory<byte>

The result of the operation.

AsReadOnlyMemory()

Gets as read only memory.

public ReadOnlyMemory<byte> AsReadOnlyMemory()

Returns

ReadOnlyMemory<byte>

The result of the operation.

AsReadOnlySpan()

Gets as read only span.

public ReadOnlySpan<byte> AsReadOnlySpan()

Returns

ReadOnlySpan<byte>

The result of the operation.

AsSpan()

Gets as span.

public Span<byte> AsSpan()

Returns

Span<byte>

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<byte>, CancellationToken)

Gets copy from asynchronously.

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

Parameters

source ReadOnlyMemory<byte>

The source.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

CopyToAsync(IUnifiedMemoryBuffer<byte>, CancellationToken)

Gets copy to asynchronously.

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

Parameters

destination IUnifiedMemoryBuffer<byte>

The destination.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

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

Gets copy to asynchronously.

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

Parameters

sourceOffset int

The source offset.

destination IUnifiedMemoryBuffer<byte>

The destination.

destinationOffset int

The destination offset.

count int

The count.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

CopyToAsync(Memory<byte>, CancellationToken)

Gets copy to asynchronously.

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

Parameters

destination Memory<byte>

The destination.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

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 = default, 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 = default, CancellationToken cancellationToken = default)

Parameters

context AcceleratorContext

The context.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

FillAsync(byte, int, int, CancellationToken)

Gets fill asynchronously.

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

Parameters

value byte

The value.

offset int

The offset.

count int

The count.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.

FillAsync(byte, CancellationToken)

Gets fill asynchronously.

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

Parameters

value byte

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.

GetMemory()

Gets the memory for the buffer. Alias for AsMemory for compatibility.

public Memory<byte> GetMemory()

Returns

Memory<byte>

Map(MapMode)

Gets map.

public MappedMemory<byte> Map(MapMode mode = MapMode.ReadWrite)

Parameters

mode MapMode

The mode.

Returns

MappedMemory<byte>

The result of the operation.

MapAsync(MapMode, CancellationToken)

Gets map asynchronously.

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "MappedMemory is returned to caller who is responsible for disposal")]
public ValueTask<MappedMemory<byte>> MapAsync(MapMode mode = MapMode.ReadWrite, CancellationToken cancellationToken = default)

Parameters

mode MapMode

The mode.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<MappedMemory<byte>>

The result of the operation.

MapRange(int, int, MapMode)

Gets map range.

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

Parameters

offset int

The offset.

length int

The length.

mode MapMode

The mode.

Returns

MappedMemory<byte>

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<byte> Slice(int offset, int length)

Parameters

offset int

The offset.

length int

The length.

Returns

IUnifiedMemoryBuffer<byte>

The result of the operation.

Synchronize()

Performs synchronize.

public void Synchronize()

SynchronizeAsync(AcceleratorContext, CancellationToken)

Gets synchronize asynchronously.

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

Parameters

context AcceleratorContext

The context.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

The result of the operation.