Class CpuMemoryBuffer<T>
- Namespace
- DotCompute.Core.Memory
- Assembly
- DotCompute.Core.dll
CPU memory buffer implementation with type safety.
public sealed class CpuMemoryBuffer<T> : IUnifiedMemoryBuffer<T>, IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable where T : unmanaged
Type Parameters
T
- Inheritance
-
CpuMemoryBuffer<T>
- Implements
- Inherited Members
- Extension Methods
Constructors
CpuMemoryBuffer(IUnifiedMemoryBuffer, int)
CPU memory buffer implementation with type safety.
public CpuMemoryBuffer(IUnifiedMemoryBuffer underlyingBuffer, int length)
Parameters
underlyingBufferIUnifiedMemoryBufferlengthint
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
TNewThe TNew type parameter.
CopyFromAsync(ReadOnlyMemory<T>, CancellationToken)
Gets copy from asynchronously.
public ValueTask CopyFromAsync(ReadOnlyMemory<T> source, CancellationToken cancellationToken = default)
Parameters
sourceReadOnlyMemory<T>The source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
CopyFromAsync<TSource>(ReadOnlyMemory<TSource>, long, CancellationToken)
Copies data from source memory to this typed CPU buffer with offset support.
public ValueTask CopyFromAsync<TSource>(ReadOnlyMemory<TSource> source, long offset, CancellationToken cancellationToken = default) where TSource : unmanaged
Parameters
sourceReadOnlyMemory<TSource>Source data to copy from.
offsetlongOffset into this buffer in bytes.
cancellationTokenCancellationTokenCancellation token for the operation.
Returns
- ValueTask
Completed task when copy finishes.
Type Parameters
TSourceType 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
sourceReadOnlyMemory<TSource>The source.
offsetlongThe offset.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
Type Parameters
TSourceThe TSource type parameter.
CopyToAsync(IUnifiedMemoryBuffer<T>, CancellationToken)
Gets copy to asynchronously.
public ValueTask CopyToAsync(IUnifiedMemoryBuffer<T> destination, CancellationToken cancellationToken = default)
Parameters
destinationIUnifiedMemoryBuffer<T>The destination.
cancellationTokenCancellationTokenThe 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
sourceOffsetintThe source offset.
destinationIUnifiedMemoryBuffer<T>The destination.
destinationOffsetintThe destination offset.
countintThe count of elements to copy.
cancellationTokenCancellationTokenThe 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
destinationMemory<T>The destination.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
CopyToAsync<TDest>(Memory<TDest>, long, CancellationToken)
Copies data from this typed CPU buffer to destination memory with offset support.
public ValueTask CopyToAsync<TDest>(Memory<TDest> destination, long offset, CancellationToken cancellationToken = default) where TDest : unmanaged
Parameters
destinationMemory<TDest>Destination memory to copy to.
offsetlongOffset into this buffer in bytes.
cancellationTokenCancellationTokenCancellation token for the operation.
Returns
- ValueTask
Completed task when copy finishes.
Type Parameters
TDestType 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
destinationMemory<TDest>The destination.
offsetlongThe offset.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
Type Parameters
TDestThe 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
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, CancellationToken cancellationToken = default)
Parameters
contextAcceleratorContextThe context.
cancellationTokenCancellationTokenThe 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
valueTThe value.
offsetintThe offset.
countintThe count of elements to fill.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.
FillAsync(T, CancellationToken)
Gets fill asynchronously.
public ValueTask FillAsync(T value, CancellationToken cancellationToken = default)
Parameters
valueTThe value.
cancellationTokenCancellationTokenThe 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
modeMapModeThe 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
modeMapModeThe mode.
cancellationTokenCancellationTokenThe 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
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
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
contextAcceleratorContextThe context.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.