Package ai.rapids.cudf
Class MemoryBuffer
java.lang.Object
ai.rapids.cudf.MemoryBuffer
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
BaseDeviceMemoryBuffer
,HostMemoryBuffer
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface to handle events for this MemoryBuffer.static class
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
MemoryBuffer
(long address, long length) Constructorprotected
MemoryBuffer
(long address, long length, MemoryBuffer parent) Internal constructor used when creating a slice.protected
MemoryBuffer
(long address, long length, MemoryBuffer.MemoryBufferCleaner cleaner) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
addressOutOfBoundsCheck
(long address, long size, String type) void
close()
Close this buffer and free memoryfinal 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.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.final long
Returns the location of the data pointed to by this bufferReturns the current event handler for this buffer or null if no handler is associated or this buffer is closed.final long
Returns the size of this bufferint
Get the current reference count for this buffer.void
Increment the reference count for this column.void
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.setEventHandler
(MemoryBuffer.EventHandler newHandler) Set an event handler for this buffer.abstract MemoryBuffer
slice
(long offset, long len) Slice off a part of the buffer.toString()
-
Field Details
-
address
protected final long address -
length
protected final long length -
closed
protected boolean closed -
refCount
protected int refCount -
cleaner
-
id
protected final long id
-
-
Constructor Details
-
MemoryBuffer
Constructor- Parameters:
address
- location in memorylength
- size of this buffercleaner
- used to clean up the memory. May be null if no cleanup is needed.
-
MemoryBuffer
protected MemoryBuffer(long address, long length) Constructor- Parameters:
address
- location in memorylength
- size of this buffer
-
MemoryBuffer
Internal constructor used when creating a slice.- Parameters:
address
- location in memorylength
- size of this bufferparent
- the buffer that should be closed instead of closing this one.
-
-
Method Details
-
noWarnLeakExpected
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. -
getLength
public final long getLength()Returns the size of this buffer- Returns:
- - size
-
addressOutOfBoundsCheck
-
getAddress
public final long getAddress()Returns the location of the data pointed to by this buffer- Returns:
- - data address
-
copyFromMemoryBuffer
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 fromsrcOffset
- offset into src to start outlength
- how many bytes to copystream
- CUDA stream to use
-
copyFromMemoryBufferAsync
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 fromsrcOffset
- offset into src to start outlength
- how many bytes to copystream
- CUDA stream to use
-
slice
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 [[DeviceMemoryBuffer]] and [[HostMemoryBuffer]] support 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
-
setEventHandler
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.
-
getEventHandler
Returns the current event handler for this buffer or null if no handler is associated or this buffer is closed. -
close
public void close()Close this buffer and free memory- Specified by:
close
in interfaceAutoCloseable
-
toString
-
incRefCount
public void incRefCount()Increment the reference count for this column. You need to call close on this to decrement the reference count again. -
getRefCount
public int getRefCount()Get the current reference count for this buffer.
-