20 #include <rmm/detail/error.hpp>
21 #include <rmm/detail/exec_check_disable.hpp>
29 #include <cuda/memory_resource>
77 using async_resource_ref = cuda::mr::async_resource_ref<cuda::mr::device_accessible>;
78 static_assert(std::is_trivially_copyable<T>::value,
79 "device_uvector only supports types that are trivially copyable.");
92 RMM_EXEC_CHECK_DISABLE
95 RMM_EXEC_CHECK_DISABLE
130 : _storage{elements_to_bytes(
size),
stream, mr}
146 : _storage{other._storage,
stream, mr}
160 assert(element_index <
size());
161 return data() + element_index;
174 assert(element_index <
size());
175 return data() + element_index;
221 if constexpr (std::is_same<value_type, bool>::value) {
227 if constexpr (std::is_fundamental<value_type>::value) {
234 RMM_CUDA_TRY(cudaMemcpyAsync(
324 RMM_CUDA_TRY(cudaMemcpyAsync(
422 [[nodiscard]] std::size_t
capacity() const noexcept
424 return bytes_to_elements(_storage.
capacity());
510 [[nodiscard]] std::size_t
size() const noexcept {
return bytes_to_elements(_storage.
size()); }
515 [[nodiscard]] std::int64_t
ssize() const noexcept
517 assert(
size() <
static_cast<std::size_t
>(std::numeric_limits<int64_t>::max()) &&
518 "Size overflows signed integer");
519 return static_cast<int64_t
>(
size());
556 [[nodiscard]] std::size_t constexpr elements_to_bytes(std::size_t num_elements)
const noexcept
561 [[nodiscard]] std::size_t constexpr bytes_to_elements(std::size_t num_bytes)
const noexcept
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
constexpr cudaStream_t value() const noexcept
Get the wrapped stream.
Definition: cuda_stream_view.hpp:75
void synchronize() const
Synchronize the viewed CUDA stream.
Definition: cuda_stream_view.hpp:108
void synchronize_no_throw() const noexcept
Synchronize the viewed CUDA stream. Does not throw if there is an error.
Definition: cuda_stream_view.hpp:115
RAII construct for device memory allocation.
Definition: device_buffer.hpp:84
cuda_stream_view stream() const noexcept
The stream most recently specified for allocation/deallocation.
Definition: device_buffer.hpp:397
void resize(std::size_t new_size, cuda_stream_view stream)
Resize the device memory allocation.
Definition: device_buffer.hpp:311
async_resource_ref memory_resource() const noexcept
The async_resource_ref used to allocate and deallocate.
Definition: device_buffer.hpp:415
std::size_t capacity() const noexcept
Returns actual size in bytes of device memory allocation.
Definition: device_buffer.hpp:392
void const * data() const noexcept
Const pointer to the device memory allocation.
Definition: device_buffer.hpp:355
void reserve(std::size_t new_capacity, cuda_stream_view stream)
Increase the capacity of the device memory allocation.
Definition: device_buffer.hpp:273
void set_stream(cuda_stream_view stream) noexcept
Sets the stream to be used for deallocation.
Definition: device_buffer.hpp:410
std::size_t size() const noexcept
The number of bytes.
Definition: device_buffer.hpp:365
void shrink_to_fit(cuda_stream_view stream)
Forces the deallocation of unused memory.
Definition: device_buffer.hpp:339
An uninitialized vector of elements in device memory.
Definition: device_uvector.hpp:76
const_iterator cend() const noexcept
Returns a const_iterator to the element following the last element of the vector.
Definition: device_uvector.hpp:495
std::size_t capacity() const noexcept
Returns the number of elements that can be held in currently allocated storage.
Definition: device_uvector.hpp:422
void resize(std::size_t new_size, cuda_stream_view stream)
Resizes the vector to contain new_size elements.
Definition: device_uvector.hpp:395
value_type * pointer
The type of the pointer returned by data()
Definition: device_uvector.hpp:87
const_pointer element_ptr(std::size_t element_index) const noexcept
Returns pointer to the specified element.
Definition: device_uvector.hpp:172
device_uvector(device_uvector const &other, cuda_stream_view stream, async_resource_ref 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:143
bool is_empty() const noexcept
true if the vector contains no elements, i.e. size() == 0
Definition: device_uvector.hpp:525
const_pointer data() const noexcept
Returns const pointer to underlying device storage.
Definition: device_uvector.hpp:445
std::size_t size() const noexcept
The number of elements in the vector.
Definition: device_uvector.hpp:510
pointer data() noexcept
Returns pointer to underlying device storage.
Definition: device_uvector.hpp:435
void shrink_to_fit(cuda_stream_view stream)
Forces deallocation of unused device memory.
Definition: device_uvector.hpp:407
iterator end() noexcept
Returns an iterator to the element following the last element of the vector.
Definition: device_uvector.hpp:485
void set_stream(cuda_stream_view stream) noexcept
Sets the stream to be used for deallocation.
Definition: device_uvector.hpp:551
std::size_t size_type
The type used for the size of the vector.
Definition: device_uvector.hpp:83
pointer element_ptr(std::size_t element_index) noexcept
Returns pointer to the specified element.
Definition: device_uvector.hpp:158
std::int64_t ssize() const noexcept
The signed number of elements in the vector.
Definition: device_uvector.hpp:515
T value_type
T; stored value type.
Definition: device_uvector.hpp:82
const_iterator cbegin() const noexcept
Returns a const_iterator to the first element.
Definition: device_uvector.hpp:466
value_type back_element(cuda_stream_view stream) const
Returns the last element.
Definition: device_uvector.hpp:357
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:264
const_pointer const_iterator
The type of the const iterator returned by cbegin()
Definition: device_uvector.hpp:90
device_buffer release() noexcept
Release ownership of device memory storage.
Definition: device_uvector.hpp:414
RMM_EXEC_CHECK_DISABLE device_uvector(device_uvector &&) noexcept=default
Default move constructor.
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:214
pointer iterator
The type of the iterator returned by begin()
Definition: device_uvector.hpp:89
value_type & reference
value_type&; reference type returned by operator[](size_type)
Definition: device_uvector.hpp:84
const_iterator end() const noexcept
Returns an iterator to the element following the last element of the vector.
Definition: device_uvector.hpp:505
void reserve(std::size_t new_capacity, cuda_stream_view stream)
Increases the capacity of the vector to new_capacity elements.
Definition: device_uvector.hpp:374
cuda_stream_view stream() const noexcept
Stream most recently specified for allocation/deallocation.
Definition: device_uvector.hpp:538
async_resource_ref memory_resource() const noexcept
The async_resource_ref used to allocate and deallocate the device storage.
Definition: device_uvector.hpp:530
value_type element(std::size_t element_index, cuda_stream_view stream) const
Returns the specified element from device memory.
Definition: device_uvector.hpp:319
value_type front_element(cuda_stream_view stream) const
Returns the first element.
Definition: device_uvector.hpp:341
value_type const * const_pointer
The type of the pointer returned by data() const.
Definition: device_uvector.hpp:88
value_type const & const_reference
Definition: device_uvector.hpp:86
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:301
const_iterator begin() const noexcept
Returns a const_iterator to the first element.
Definition: device_uvector.hpp:475
iterator begin() noexcept
Returns an iterator to the first element.
Definition: device_uvector.hpp:457
Exception thrown when attempting to access outside of a defined range.
Definition: error.hpp:112
device_memory_resource * get_current_device_resource()
Get the memory resource for the current device.
Definition: per_device_resource.hpp:207
Management of per-device device_memory_resources.