Public Member Functions | List of all members
rmm::device_buffer Class Reference

Public Member Functions

 device_buffer ()
 Default constructor creates an empty device_buffer
 
 device_buffer (std::size_t size, cuda_stream_view stream=cuda_stream_view{}, mr::device_memory_resource *mr=mr::get_current_device_resource())
 Constructs a new device buffer of size uninitialized bytes. More...
 
 device_buffer (void const *source_data, std::size_t size, cuda_stream_view stream=cuda_stream_view{}, mr::device_memory_resource *mr=mr::get_current_device_resource())
 Construct a new device buffer by copying from a raw pointer to an existing host or device memory allocation. More...
 
 device_buffer (device_buffer const &other, cuda_stream_view stream=cuda_stream_view{}, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
 Construct a new device_buffer by deep copying the contents of another device_buffer, optionally using the specified stream and memory resource. More...
 
 device_buffer (device_buffer &&other) noexcept
 Constructs a new device_buffer by moving the contents of another device_buffer into the newly constructed one. More...
 
device_bufferoperator= (device_buffer const &other)
 Copies the contents of other into this device_buffer. More...
 
device_bufferoperator= (device_buffer &&other) noexcept
 Move assignment operator moves the contents from other. More...
 
 ~device_buffer () noexcept
 Destroy the device buffer object. More...
 
void resize (std::size_t new_size, cuda_stream_view stream=cuda_stream_view{})
 Resize the device memory allocation. More...
 
void shrink_to_fit (cuda_stream_view stream=cuda_stream_view{})
 Forces the deallocation of unused memory. More...
 
void const * data () const noexcept
 Returns raw pointer to underlying device memory allocation.
 
void * data () noexcept
 Returns raw pointer to underlying device memory allocation.
 
std::size_t size () const noexcept
 Returns size in bytes that was requested for the device memory allocation.
 
bool is_empty () const noexcept
 Returns whether the size in bytes of the device_buffer is zero. More...
 
std::size_t capacity () const noexcept
 Returns actual size in bytes of device memory allocation. More...
 
cuda_stream_view stream () const noexcept
 Returns stream most recently specified for allocation/deallocation.
 
void set_stream (cuda_stream_view stream) noexcept
 Sets the stream to be used for deallocation. More...
 
mr::device_memory_resourcememory_resource () const noexcept
 Returns pointer to the memory resource used to allocate and deallocate the device memory.
 

Constructor & Destructor Documentation

◆ device_buffer() [1/4]

rmm::device_buffer::device_buffer ( std::size_t  size,
cuda_stream_view  stream = cuda_stream_view{},
mr::device_memory_resource mr = mr::get_current_device_resource() 
)
inlineexplicit

Constructs a new device buffer of size uninitialized bytes.

Exceptions
rmm::bad_allocIf allocation fails.
Parameters
sizeSize in bytes to allocate in device memory.
streamCUDA stream on which memory may be allocated if the memory resource supports streams.
mrMemory resource to use for the device memory allocation.

◆ device_buffer() [2/4]

rmm::device_buffer::device_buffer ( void const *  source_data,
std::size_t  size,
cuda_stream_view  stream = cuda_stream_view{},
mr::device_memory_resource mr = mr::get_current_device_resource() 
)
inline

Construct a new device buffer by copying from a raw pointer to an existing host or device memory allocation.

Exceptions
rmm::bad_allocIf creating the new allocation fails.
rmm::logic_errorIf source_data is null, and size != 0.
rmm::cuda_errorif copying from the device memory fails.
Parameters
source_dataPointer to the host or device memory to copy from.
sizeSize in bytes to copy.
streamCUDA stream on which memory may be allocated if the memory resource supports streams.
mrMemory resource to use for the device memory allocation

◆ device_buffer() [3/4]

rmm::device_buffer::device_buffer ( device_buffer const &  other,
cuda_stream_view  stream = cuda_stream_view{},
rmm::mr::device_memory_resource mr = rmm::mr::get_current_device_resource() 
)
inline

Construct a new device_buffer by deep copying the contents of another device_buffer, optionally using the specified stream and memory resource.

Note
Only copies other.size() bytes from other, i.e., if other.size() != other.capacity(), then the size and capacity of the newly constructed device_buffer will be equal to other.size().
Exceptions
rmm::bad_allocIf creating the new allocation fails.
rmm::cuda_errorif copying from other fails.
Parameters
otherThe device_buffer whose contents will be copied
streamThe stream to use for the allocation and copy
mrThe resource to use for allocating the new device_buffer

◆ device_buffer() [4/4]

rmm::device_buffer::device_buffer ( device_buffer &&  other)
inlinenoexcept

Constructs a new device_buffer by moving the contents of another device_buffer into the newly constructed one.

After the new device_buffer is constructed, other is modified to be a valid, empty device_buffer, i.e., data() returns nullptr, and size() and capacity() are zero.

Exceptions
Nothing
Parameters
otherThe device_buffer whose contents will be moved into the newly constructed one.

◆ ~device_buffer()

rmm::device_buffer::~device_buffer ( )
inlinenoexcept

Destroy the device buffer object.

Note
If the memory resource supports streams, this destructor deallocates using the stream most recently passed to any of this device buffer's methods.

Member Function Documentation

◆ capacity()

std::size_t rmm::device_buffer::capacity ( ) const
inlinenoexcept

Returns actual size in bytes of device memory allocation.

The invariant size() <= capacity() holds.

◆ is_empty()

bool rmm::device_buffer::is_empty ( ) const
inlinenoexcept

Returns whether the size in bytes of the device_buffer is zero.

If is_empty() == true, the device_buffer may still hold an allocation if capacity() > 0.

◆ operator=() [1/2]

device_buffer& rmm::device_buffer::operator= ( device_buffer &&  other)
inlinenoexcept

Move assignment operator moves the contents from other.

This device_buffer's current device memory allocation will be deallocated on stream().

If a different stream is required, call set_stream() on the instance before assignment. After assignment, this instance's stream is replaced by the other.stream().

Parameters
otherThe device_buffer whose contents will be moved.

◆ operator=() [2/2]

device_buffer& rmm::device_buffer::operator= ( device_buffer const &  other)
inline

Copies the contents of other into this device_buffer.

All operations on the data in this device_buffer on all streams must be complete before using this operator, otherwise behavior is undefined.

If the existing capacity is large enough, and the memory resources are compatible, then this device_buffer's existing memory will be reused and others contents will simply be copied on other.stream(). I.e., if capcity() > other.size() and memory_resource()->is_equal(*other.memory_resource()).

Otherwise, the existing memory will be deallocated using memory_resource() on stream() and new memory will be allocated using other.memory_resource() on other.stream().

Exceptions
rmm::bad_allocif allocation fails
rmm::cuda_errorif the copy from other fails
Parameters
otherThe device_buffer to copy.

◆ resize()

void rmm::device_buffer::resize ( std::size_t  new_size,
cuda_stream_view  stream = cuda_stream_view{} 
)
inline

Resize the device memory allocation.

If the requested new_size is less than or equal to capacity(), no action is taken other than updating the value that is returned from size(). Specifically, no memory is allocated nor copied. The value capacity() remains the actual size of the device memory allocation.

Note
shrink_to_fit() may be used to force the deallocation of unused capacity().

If new_size is larger than capacity(), a new allocation is made on stream to satisfy new_size, and the contents of the old allocation are copied on stream to the new allocation. The old allocation is then freed. The bytes from [old_size, new_size) are uninitialized.

The invariant size() <= capacity() holds.

Exceptions
rmm::bad_allocIf creating the new allocation fails
rmm::cuda_errorif the copy from the old to new allocation fails
Parameters
new_sizeThe requested new size, in bytes
streamThe stream to use for allocation and copy

◆ set_stream()

void rmm::device_buffer::set_stream ( cuda_stream_view  stream)
inlinenoexcept

Sets the stream to be used for deallocation.

If no other rmm::device_buffer method that allocates or copies memory is called after this call with a different stream argument, then stream will be used for deallocation in the `rmm::device_buffer destructor. Otherwise, if another rmm::device_buffer method with a stream parameter is called after this, the later stream parameter will be stored and used in the destructor.

◆ shrink_to_fit()

void rmm::device_buffer::shrink_to_fit ( cuda_stream_view  stream = cuda_stream_view{})
inline

Forces the deallocation of unused memory.

Reallocates and copies on stream stream the contents of the device memory allocation to reduce capacity() to size().

If size() == capacity(), no allocations nor copies occur.

Exceptions
rmm::bad_allocIf creating the new allocation fails
rmm::cuda_errorIf the copy from the old to new allocation fails
Parameters
streamThe stream on which the allocation and copy are performed

The documentation for this class was generated from the following file: