Go to the documentation of this file.
18 #include <rmm/cuda_stream_view.hpp>
19 #include <rmm/detail/error.hpp>
20 #include <rmm/mr/device/device_memory_resource.hpp>
23 #include <cuda_runtime_api.h>
106 : _stream{
stream}, _mr{mr}
108 allocate_async(
size);
134 : _stream{
stream}, _mr{mr}
136 allocate_async(
size);
137 copy_async(source_data,
size);
182 : _data{other._data},
184 _capacity{other._capacity},
188 other._data =
nullptr;
208 if (&other !=
this) {
213 _capacity = other._capacity;
217 other._data =
nullptr;
274 cudaMemcpyAsync(new_data,
data(),
size(), cudaMemcpyDefault, this->
stream().value()));
278 _capacity = new_size;
303 std::swap(tmp, *
this);
310 [[nodiscard]]
void const*
data() const noexcept {
return _data; }
315 void*
data() noexcept {
return _data; }
320 [[nodiscard]] std::size_t
size() const noexcept {
return _size; }
325 [[nodiscard]] std::int64_t
ssize() const noexcept
327 assert(
size() <
static_cast<std::size_t
>(std::numeric_limits<int64_t>::max()) &&
328 "Size overflows signed integer");
329 return static_cast<int64_t
>(
size());
346 [[nodiscard]] std::size_t
capacity() const noexcept {
return _capacity; }
371 void* _data{
nullptr};
373 std::size_t _capacity{};
374 cuda_stream_view _stream{};
375 mr::device_memory_resource* _mr{
376 mr::get_current_device_resource()};
388 void allocate_async(std::size_t bytes)
404 void deallocate_async() noexcept
424 void copy_async(
void const* source, std::size_t bytes)
427 RMM_EXPECTS(
nullptr != source,
"Invalid copy from nullptr.");
429 RMM_CUDA_TRY(cudaMemcpyAsync(_data, source, bytes, cudaMemcpyDefault,
stream().value()));
mr::device_memory_resource * memory_resource() const noexcept
Returns pointer to the memory resource used to allocate and deallocate the device memory.
Definition: device_buffer.hpp:368
void shrink_to_fit(cuda_stream_view stream)
Forces the deallocation of unused memory.
Definition: device_buffer.hpp:295
void * allocate(std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
Allocates memory of size at least bytes.
Definition: device_memory_resource.hpp:106
device_buffer(void const *source_data, std::size_t size, cuda_stream_view stream, 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 allo...
Definition: device_buffer.hpp:130
Management of per-device device_memory_resources.
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:34
std::size_t size() const noexcept
Returns the number of bytes.
Definition: device_buffer.hpp:320
device_buffer()
Default constructor creates an empty device_buffer
Definition: device_buffer.hpp:91
void deallocate(void *ptr, std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
Deallocate memory pointed to by p.
Definition: device_memory_resource.hpp:129
device_buffer(device_buffer const &other, cuda_stream_view stream, 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,...
Definition: device_buffer.hpp:161
device_buffer(std::size_t size, cuda_stream_view stream, mr::device_memory_resource *mr=mr::get_current_device_resource())
Constructs a new device buffer of size uninitialized bytes.
Definition: device_buffer.hpp:103
std::int64_t ssize() const noexcept
Returns the signed number of bytes.
Definition: device_buffer.hpp:325
Definition: device_buffer.hpp:77
void set_stream(cuda_stream_view stream) noexcept
Sets the stream to be used for deallocation.
Definition: device_buffer.hpp:362
void * data() noexcept
Returns raw pointer to underlying device memory allocation.
Definition: device_buffer.hpp:315
cuda_stream_view stream() const noexcept
Returns stream most recently specified for allocation/deallocation.
Definition: device_buffer.hpp:351
void resize(std::size_t new_size, cuda_stream_view stream)
Resize the device memory allocation.
Definition: device_buffer.hpp:264
bool is_empty() const noexcept
returns the number of bytes that can be held in currently allocated storage.
Definition: device_buffer.hpp:339
void const * data() const noexcept
Returns raw pointer to underlying device memory allocation.
Definition: device_buffer.hpp:310
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:82
std::size_t capacity() const noexcept
Returns actual size in bytes of device memory allocation.
Definition: device_buffer.hpp:346
device_buffer & operator=(device_buffer &&other) noexcept
Move assignment operator moves the contents from other.
Definition: device_buffer.hpp:206
~device_buffer() noexcept
Destroy the device buffer object.
Definition: device_buffer.hpp:232
device_buffer(device_buffer &&other) noexcept
Constructs a new device_buffer by moving the contents of another device_buffer into the newly constru...
Definition: device_buffer.hpp:181