Class CudaMemoryBuffer
- Namespace
- DotCompute.Backends.CUDA.Memory
- Assembly
- DotCompute.Backends.CUDA.dll
Represents a CUDA memory buffer allocated on the GPU device.
public sealed class CudaMemoryBuffer : IUnifiedMemoryBuffer, IAsyncDisposable, IDisposable
- Inheritance
-
CudaMemoryBuffer
- Implements
- Inherited Members
- Extension Methods
Remarks
Initializes a new instance of the CudaMemoryBuffer class.
Constructors
CudaMemoryBuffer(nint, long, MemoryOptions)
Represents a CUDA memory buffer allocated on the GPU device.
public CudaMemoryBuffer(nint devicePointer, long sizeInBytes, MemoryOptions options = MemoryOptions.None)
Parameters
devicePointernintThe device memory pointer.
sizeInByteslongThe size in bytes.
optionsMemoryOptionsMemory allocation options.
Remarks
Initializes a new instance of the CudaMemoryBuffer class.
Properties
DevicePointer
Gets the device memory pointer.
public nint DevicePointer { get; }
Property Value
IsDisposed
Gets whether the buffer has been disposed.
public bool IsDisposed { get; }
Property Value
Options
Gets the memory allocation options.
public MemoryOptions Options { get; }
Property Value
SizeInBytes
Gets the size of the buffer in bytes.
public long SizeInBytes { get; }
Property Value
State
Gets the current state of the buffer.
public BufferState State { get; }
Property Value
Methods
Allocate(CudaDevice, long, MemoryOptions)
Allocates a new CUDA memory buffer.
public static CudaMemoryBuffer Allocate(CudaDevice device, long sizeInBytes, MemoryOptions options = MemoryOptions.None)
Parameters
deviceCudaDevicesizeInByteslongoptionsMemoryOptions
Returns
CopyFromAsync<T>(ReadOnlyMemory<T>, long, CancellationToken)
Asynchronously copies data from host memory to this buffer.
public ValueTask CopyFromAsync<T>(ReadOnlyMemory<T> source, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
sourceReadOnlyMemory<T>offsetlongcancellationTokenCancellationToken
Returns
Type Parameters
T
CopyFromHost<T>(ReadOnlySpan<T>)
Copies data from host memory to this device buffer.
public void CopyFromHost<T>(ReadOnlySpan<T> source) where T : unmanaged
Parameters
sourceReadOnlySpan<T>
Type Parameters
T
CopyTo(CudaMemoryBuffer)
Copies data from this buffer to another buffer.
public void CopyTo(CudaMemoryBuffer destination)
Parameters
destinationCudaMemoryBuffer
CopyToAsync<T>(Memory<T>, long, CancellationToken)
Asynchronously copies data from this buffer to host memory.
public ValueTask CopyToAsync<T>(Memory<T> destination, long offset = 0, CancellationToken cancellationToken = default) where T : unmanaged
Parameters
destinationMemory<T>offsetlongcancellationTokenCancellationToken
Returns
Type Parameters
T
CopyToHost<T>(Span<T>)
Copies data from this device buffer to host memory.
public void CopyToHost<T>(Span<T> destination) where T : unmanaged
Parameters
destinationSpan<T>
Type Parameters
T
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.