Class MemoryBuffer

java.lang.Object
ai.rapids.cudf.MemoryBuffer
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
BaseDeviceMemoryBuffer, HostMemoryBuffer

public abstract class MemoryBuffer extends Object 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.
  • Field Details

    • address

      protected final long address
    • length

      protected final long length
    • closed

      protected boolean closed
    • refCount

      protected int refCount
    • cleaner

      protected final MemoryBuffer.MemoryBufferCleaner cleaner
    • id

      protected final long id
  • Constructor Details

    • MemoryBuffer

      protected MemoryBuffer(long address, long length, MemoryBuffer.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.
    • MemoryBuffer

      protected MemoryBuffer(long address, long length)
      Constructor
      Parameters:
      address - location in memory
      length - size of this buffer
    • MemoryBuffer

      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.
  • 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

      protected final void addressOutOfBoundsCheck(long address, long size, String type)
    • 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 from
      srcOffset - offset into src to start out
      length - how many bytes to copy
      stream - 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 from
      srcOffset - offset into src to start out
      length - how many bytes to copy
      stream - CUDA stream to use
    • slice

      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 [[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

      public MemoryBuffer.EventHandler setEventHandler(MemoryBuffer.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.
    • getEventHandler

      public MemoryBuffer.EventHandler 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 interface AutoCloseable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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.