MemoryBuffer#
- abstract public class MemoryBuffer implements AutoCloseable#
Abstract class for representing the Memory Buffer.
NOTE: MemoryBuffer is public to make it easier to work with the class hierarchy, subclassing beyond what is included in CUDF is not recommended and not supported.
Subclassed by ai.rapids.cudf.BaseDeviceMemoryBuffer, ai.rapids.cudf.HostMemoryBuffer
Field Summary
Constructor Summary
Constructor.
MemoryBuffer(long address, long length, MemoryBuffer parent)Internal constructor used when creating a slice.
MemoryBuffer(long address, long length, MemoryBufferCleaner cleaner)Constructor.
Method Summary
addressOutOfBoundsCheck(long address, long size, String type)Close this buffer and free memory.
Copy a subset of src to this buffer starting at destOffset using the specified CUDA stream.
Copy a subset of src to this buffer starting at destOffset using the specified CUDA stream.
Returns the location of the data pointed to by this buffer.
Returns the current event handler for this buffer or null if no handler is associated or this buffer is closed.
Returns the size of this buffer.
Get the current reference count for this buffer.
Increment the reference count for this column.
This is a really ugly API, but it is possible that the lifecycle of a column of data may not have a clear lifecycle thanks to java and GC.
Set an event handler for this buffer.
Slice off a part of the buffer.
Protected Fields
- protected final long address#
- protected final long length#
- protected boolean closed#
- protected int refCount#
- protected final MemoryBufferCleaner cleaner#
- protected final long id#
Methods
- public void noWarnLeakExpected()#
This is a really ugly API, but it is possible that the lifecycle of a column of data may not have a clear lifecycle thanks to java and GC.
This API informs the leak tracking code that this is expected for this column, and big scary warnings should not be printed when this happens.
- public final long getLength()#
Returns the size of this buffer.
- Returns:
- size
- public final long getAddress()#
Returns the location of the data pointed to by this buffer.
- Returns:
- data address
- public final void copyFromMemoryBuffer(
- long destOffset,
- MemoryBuffer src,
- long srcOffset,
- long length,
- Cuda.Stream stream
Copy a subset of src to this buffer starting at destOffset using the specified CUDA stream.
The copy has completed when this returns, but the memory copy could overlap with operations occurring on other streams.
- Parameters:
destOffset – the offset in this to start copying from.
src – what to copy from
srcOffset – offset into src to start out
length – how many bytes to copy
stream – CUDA stream to use
- public final void copyFromMemoryBufferAsync(
- long destOffset,
- MemoryBuffer src,
- long srcOffset,
- long length,
- Cuda.Stream stream
Copy a subset of src to this buffer starting at destOffset using the specified CUDA stream.
The copy is async and may not have completed when this returns.
- Parameters:
destOffset – the offset in this to start copying from.
src – what to copy from
srcOffset – offset into src to start out
length – how many bytes to copy
stream – CUDA stream to use
- public abstract MemoryBuffer slice(long offset, long len)#
Slice off a part of the buffer.
Note that this is a zero copy operation and all slices must be closed along with the original buffer before the memory is released. So use this with some caution.
Note that
DeviceMemoryBufferandHostMemoryBuffersupport slicing, and override this function.- Parameters:
offset – where to start the slice at.
len – how many bytes to slice
- Returns:
a slice of the original buffer that will need to be closed independently
- public EventHandler setEventHandler(EventHandler newHandler)#
Set an event handler for this buffer.
This method can be invoked with null to unset the handler.
- Parameters:
newHandler – - the EventHandler to use from this point forward
- Returns:
the prior event handler, or null if not set.
- public EventHandler getEventHandler()#
Returns the current event handler for this buffer or null if no handler is associated or this buffer is closed.
- public void close()#
Close this buffer and free memory.
- public void incRefCount()#
Increment the reference count for this column.
You need to call close on this to decrement the reference count again.
- public int getRefCount()#
Get the current reference count for this buffer.
Protected Constructors
- protected MemoryBuffer(
- long address,
- long length,
- MemoryBufferCleaner cleaner
Constructor.
- Parameters:
address – location in memory
length – size of this buffer
cleaner – used to clean up the memory. May be null if no cleanup is needed.
- protected MemoryBuffer(long address, long length)#
Constructor.
- Parameters:
address – location in memory
length – size of this buffer
- protected MemoryBuffer(long address, long length, MemoryBuffer parent)#
Internal constructor used when creating a slice.
- Parameters:
address – location in memory
length – size of this buffer
parent – the buffer that should be closed instead of closing this one.
Protected Methods
- public interface EventHandler#
Interface to handle events for this MemoryBuffer.
Only invoked during close, hence
onClosedis the only event.Method Summary
onClosed is invoked with the updated refCount during close.
Methods
- public void onClosed(int refCount)#
onClosedis invoked with the updatedrefCountduringclose.The last invocation of
onClosedwill be withrefCount=0.Note
the callback is invoked with this
MemoryBuffer’s lock held.- Parameters:
refCount – - the updated ref count for this MemoryBuffer at the time of invocation
- public static abstract class MemoryBufferCleaner extends MemoryCleaner.Cleaner#
Fields inherited from class
ai.rapids.cudf.MemoryCleaner.Cleaner:idMethods inherited from class
ai.rapids.cudf.MemoryCleaner.Cleaner:addRef,clean,cleanImpl,delRef,isClean,isLeakExpected,logRefCountDebug,noWarnLeakExpected