19 #include <rmm/cuda_stream_view.hpp>
20 #include <rmm/detail/error.hpp>
21 #include <rmm/detail/exec_check_disable.hpp>
23 #include <rmm/mr/device/device_memory_resource.hpp>
70 static_assert(std::is_trivially_copyable<T>::value,
71 "device_uvector only supports types that are trivially copyable.");
75 using size_type = std::size_t;
76 using reference = value_type&;
77 using const_reference = value_type
const&;
78 using pointer = value_type*;
79 using const_pointer = value_type
const*;
80 using iterator = pointer;
81 using const_iterator = const_pointer;
83 RMM_EXEC_CHECK_DISABLE
86 RMM_EXEC_CHECK_DISABLE
121 : _storage{elements_to_bytes(
size),
stream, mr}
138 : _storage{other._storage,
stream, mr}
150 [[nodiscard]] pointer
element_ptr(std::size_t element_index) noexcept
152 assert(element_index <
size());
153 return data() + element_index;
164 [[nodiscard]] const_pointer
element_ptr(std::size_t element_index)
const noexcept
166 assert(element_index <
size());
167 return data() + element_index;
207 value_type
const& value,
213 if constexpr (std::is_same<value_type, bool>::value) {
219 if constexpr (std::is_fundamental<value_type>::value) {
220 if (value == value_type{0}) {
226 RMM_CUDA_TRY(cudaMemcpyAsync(
316 RMM_CUDA_TRY(cudaMemcpyAsync(
397 [[nodiscard]] std::size_t
capacity() const noexcept
399 return bytes_to_elements(_storage.
capacity());
410 [[nodiscard]] pointer
data() noexcept {
return static_cast<pointer
>(_storage.
data()); }
420 [[nodiscard]] const_pointer
data() const noexcept
422 return static_cast<const_pointer
>(_storage.
data());
432 [[nodiscard]] iterator
begin() noexcept {
return data(); }
441 [[nodiscard]] const_iterator
cbegin() const noexcept {
return data(); }
450 [[nodiscard]] const_iterator
begin() const noexcept {
return cbegin(); }
470 [[nodiscard]] const_iterator
cend() const noexcept {
return data() +
size(); }
480 [[nodiscard]] const_iterator
end() const noexcept {
return cend(); }
485 [[nodiscard]] std::size_t
size() const noexcept {
return bytes_to_elements(_storage.
size()); }
490 [[nodiscard]] std::int64_t
ssize() const noexcept
492 assert(
size() <
static_cast<std::size_t
>(std::numeric_limits<int64_t>::max()) &&
493 "Size overflows signed integer");
494 return static_cast<int64_t
>(
size());
534 [[nodiscard]] std::size_t constexpr elements_to_bytes(std::size_t num_elements)
const noexcept
536 return num_elements *
sizeof(value_type);
539 [[nodiscard]] std::size_t constexpr bytes_to_elements(std::size_t num_bytes)
const noexcept
541 return num_bytes /
sizeof(value_type);
const_pointer data() const noexcept
Returns const pointer to underlying device storage.
Definition: device_uvector.hpp:420
void set_element_async(std::size_t element_index, value_type const &value, cuda_stream_view stream)
Performs an asynchronous copy of v to the specified element in device memory.
Definition: device_uvector.hpp:206
iterator end() noexcept
Returns an iterator to the element following the last element of the vector.
Definition: device_uvector.hpp:460
const_iterator end() const noexcept
Returns an iterator to the element following the last element of the vector.
Definition: device_uvector.hpp:480
value_type element(std::size_t element_index, cuda_stream_view stream) const
Returns the specified element from device memory.
Definition: device_uvector.hpp:311
void set_stream(cuda_stream_view stream) noexcept
Sets the stream to be used for deallocation.
Definition: device_uvector.hpp:529
RAII construct for device memory allocation.
device_uvector & operator=(device_uvector const &)=delete
Copy assignment is deleted as it doesn't allow a stream argument.
const_iterator begin() const noexcept
Returns a const_iterator to the first element.
Definition: device_uvector.hpp:450
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
Management of per-device device_memory_resources.
cuda_stream_view stream() const noexcept
Returns stream most recently specified for allocation/deallocation.
Definition: device_uvector.hpp:518
device_uvector(std::size_t size, cuda_stream_view stream, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Construct a new device_uvector with sufficient uninitialized storage for size elements.
Definition: device_uvector.hpp:117
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
mr::device_memory_resource * memory_resource() const noexcept
Returns pointer to the resource used to allocate and deallocate the device storage.
Definition: device_uvector.hpp:510
const_iterator cbegin() const noexcept
Returns a const_iterator to the first element.
Definition: device_uvector.hpp:441
void resize(std::size_t new_size, cuda_stream_view stream)
Resizes the vector to contain new_size elements.
Definition: device_uvector.hpp:370
device_uvector(device_uvector const &)=delete
Copy ctor is deleted as it doesn't allow a stream argument.
bool is_empty() const noexcept
Returns true if the vector contains no elements, i.e., size() == 0.
Definition: device_uvector.hpp:503
An uninitialized vector of elements in device memory.
Definition: device_uvector.hpp:69
std::size_t size() const noexcept
Returns the number of elements.
Definition: device_uvector.hpp:485
Definition: device_buffer.hpp:77
std::size_t capacity() const noexcept
Returns the number of elements that can be held in currently allocated storage.
Definition: device_uvector.hpp:397
void set_stream(cuda_stream_view stream) noexcept
Sets the stream to be used for deallocation.
Definition: device_buffer.hpp:362
const_iterator cend() const noexcept
Returns a const_iterator to the element following the last element of the vector.
Definition: device_uvector.hpp:470
device_uvector(device_uvector const &other, cuda_stream_view stream, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Construct a new device_uvector by deep copying the contents of another device_uvector.
Definition: device_uvector.hpp:134
std::int64_t ssize() const noexcept
Returns the signed number of elements.
Definition: device_uvector.hpp:490
cuda_stream_view stream() const noexcept
Returns stream most recently specified for allocation/deallocation.
Definition: device_buffer.hpp:351
device_uvector()=delete
Default constructor is deleted as it doesn't allow a stream argument.
value_type back_element(cuda_stream_view stream) const
Returns the last element.
Definition: device_uvector.hpp:349
void resize(std::size_t new_size, cuda_stream_view stream)
Resize the device memory allocation.
Definition: device_buffer.hpp:264
device_buffer release() noexcept
Release ownership of device memory storage.
Definition: device_uvector.hpp:389
iterator begin() noexcept
Returns an iterator to the first element.
Definition: device_uvector.hpp:432
void synchronize() const
Synchronize the viewed CUDA stream.
Definition: cuda_stream_view.hpp:81
void shrink_to_fit(cuda_stream_view stream)
Forces deallocation of unused device memory.
Definition: device_uvector.hpp:382
void const * data() const noexcept
Returns raw pointer to underlying device memory allocation.
Definition: device_buffer.hpp:310
void set_element_to_zero_async(std::size_t element_index, cuda_stream_view stream)
Asynchronously sets the specified element to zero in device memory.
Definition: device_uvector.hpp:256
const_pointer element_ptr(std::size_t element_index) const noexcept
Returns pointer to the specified element.
Definition: device_uvector.hpp:164
pointer element_ptr(std::size_t element_index) noexcept
Returns pointer to the specified element.
Definition: device_uvector.hpp:150
constexpr cudaStream_t value() const noexcept
Get the wrapped stream.
Definition: cuda_stream_view.hpp:57
value_type front_element(cuda_stream_view stream) const
Returns the first element.
Definition: device_uvector.hpp:333
void synchronize_no_throw() const noexcept
Synchronize the viewed CUDA stream. Does not throw if there is an error.
Definition: cuda_stream_view.hpp:88
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
Exception thrown when attempting to access outside of a defined range.
Definition: error.hpp:78
pointer data() noexcept
Returns pointer to underlying device storage.
Definition: device_uvector.hpp:410
void set_element(std::size_t element_index, T const &value, cuda_stream_view stream)
Performs a synchronous copy of v to the specified element in device memory.
Definition: device_uvector.hpp:293