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_buffer & | operator= (device_buffer const &other) |
Copies the contents of other into this device_buffer . More... | |
device_buffer & | operator= (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_resource * | memory_resource () const noexcept |
Returns pointer to the memory resource used to allocate and deallocate the device memory. | |
|
inlineexplicit |
Constructs a new device buffer of size
uninitialized bytes.
rmm::bad_alloc | If allocation fails. |
size | Size in bytes to allocate in device memory. |
stream | CUDA stream on which memory may be allocated if the memory resource supports streams. |
mr | Memory resource to use for the device memory allocation. |
|
inline |
Construct a new device buffer by copying from a raw pointer to an existing host or device memory allocation.
rmm::bad_alloc | If creating the new allocation fails. |
rmm::logic_error | If source_data is null, and size != 0 . |
rmm::cuda_error | if copying from the device memory fails. |
source_data | Pointer to the host or device memory to copy from. |
size | Size in bytes to copy. |
stream | CUDA stream on which memory may be allocated if the memory resource supports streams. |
mr | Memory resource to use for the device memory allocation |
|
inline |
Construct a new device_buffer
by deep copying the contents of another device_buffer
, optionally using the specified stream and memory resource.
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()
.rmm::bad_alloc | If creating the new allocation fails. |
rmm::cuda_error | if copying from other fails. |
other | The device_buffer whose contents will be copied |
stream | The stream to use for the allocation and copy |
mr | The resource to use for allocating the new device_buffer |
|
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.
Nothing |
other | The device_buffer whose contents will be moved into the newly constructed one. |
|
inlinenoexcept |
Destroy the device buffer object.
|
inlinenoexcept |
Returns actual size in bytes of device memory allocation.
The invariant size() <= capacity()
holds.
|
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
.
|
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()
.
other | The device_buffer whose contents will be moved. |
|
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 other
s 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()
.
rmm::bad_alloc | if allocation fails |
rmm::cuda_error | if the copy from other fails |
other | The device_buffer to copy. |
|
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.
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.
rmm::bad_alloc | If creating the new allocation fails |
rmm::cuda_error | if the copy from the old to new allocation fails |
new_size | The requested new size, in bytes |
stream | The stream to use for allocation and copy |
|
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.
|
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.
rmm::bad_alloc | If creating the new allocation fails |
rmm::cuda_error | If the copy from the old to new allocation fails |
stream | The stream on which the allocation and copy are performed |