Class CpuMemoryBufferTyped<T>
- Namespace
- DotCompute.Backends.CPU.Accelerators
- Assembly
- DotCompute.Backends.CPU.dll
Provides a typed view of a CpuMemoryBuffer for strongly-typed element access.
public sealed class CpuMemoryBufferTyped<T> : IUnifiedMemoryBuffer<T>, IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable where T : unmanaged
Type Parameters
T
- Inheritance
-
CpuMemoryBufferTyped<T>
- Implements
- Inherited Members
- Extension Methods
Constructors
CpuMemoryBufferTyped(CpuMemoryBuffer, int, CpuMemoryManager, ILogger?)
Provides a typed view of a CpuMemoryBuffer for strongly-typed element access.
public CpuMemoryBufferTyped(CpuMemoryBuffer parentBuffer, int elementCount, CpuMemoryManager memoryManager, ILogger? logger)
Parameters
parentBufferCpuMemoryBufferelementCountintmemoryManagerCpuMemoryManagerloggerILogger
Properties
Accelerator
Gets or sets the accelerator.
public IAccelerator Accelerator { get; }
Property Value
- IAccelerator
The accelerator.
Count
Gets or sets the count.
public int Count { get; }
Property Value
- int
The count.
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.
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.
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.
CreateView(int, int)
Creates a view of this buffer with the specified offset and length. This is an alias for Slice for backward compatibility.
public IUnifiedMemoryBuffer<T> CreateView(int offset, int length)
Parameters
Returns
- IUnifiedMemoryBuffer<T>
A view of this buffer.
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(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.
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 = MapMode.ReadWrite)
Parameters
modeMapModeThe mode.
Returns
- MappedMemory<T>
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<T>> MapAsync(MapMode mode = MapMode.ReadWrite, 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 = MapMode.ReadWrite)
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 = default, CancellationToken cancellationToken = default)
Parameters
contextAcceleratorContextThe context.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ValueTask
The result of the operation.