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
sizeInByteslongSize of the buffer in bytes.
optionsMemoryOptionsMemory allocation options.
memoryManagerCpuMemoryManagerThe memory manager that owns this buffer.
numaNodeintThe NUMA node to allocate memory on.
policyNumaMemoryPolicyThe NUMA memory policy to use.
loggerILogger<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
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
AsType<TNew>()
Gets as type.
public IUnifiedMemoryBuffer<TNew> AsType<TNew>() where TNew : unmanaged
Returns
- IUnifiedMemoryBuffer<TNew>
The result of the operation.
Type Parameters
TNewThe TNew type parameter.
CopyFromAsync(ReadOnlyMemory<byte>, CancellationToken)
Gets copy from asynchronously.
public ValueTask CopyFromAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
Parameters
sourceReadOnlyMemory<byte>The source.
cancellationTokenCancellationTokenThe 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
destinationIUnifiedMemoryBuffer<byte>The destination.
cancellationTokenCancellationTokenThe 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
sourceOffsetintThe source offset.
destinationIUnifiedMemoryBuffer<byte>The destination.
destinationOffsetintThe destination offset.
countintThe count.
cancellationTokenCancellationTokenThe 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
destinationMemory<byte>The destination.
cancellationTokenCancellationTokenThe 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
contextAcceleratorContextThe context.
cancellationTokenCancellationTokenThe 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
contextAcceleratorContextThe context.
cancellationTokenCancellationTokenThe 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
valuebyteThe value.
offsetintThe offset.
countintThe count.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
FillAsync(byte, CancellationToken)
Gets fill asynchronously.
public ValueTask FillAsync(byte value, CancellationToken cancellationToken = default)
Parameters
valuebyteThe value.
cancellationTokenCancellationTokenThe 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
Map(MapMode)
Gets map.
public MappedMemory<byte> Map(MapMode mode = MapMode.ReadWrite)
Parameters
modeMapModeThe 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
modeMapModeThe mode.
cancellationTokenCancellationTokenThe 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
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
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
contextAcceleratorContextThe context.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.