Container for a single object of type T in device memory.
More...
#include <device_scalar.hpp>
Public Types | |
| using | value_type = typename device_uvector< T >::value_type |
| T, the type of the scalar element. | |
| using | size_type = typename device_uvector< T >::size_type |
| The type used for the size. | |
| using | reference = typename device_uvector< T >::reference |
| value_type& | |
| using | const_reference = typename device_uvector< T >::const_reference |
| const value_type& | |
| using | pointer = typename device_uvector< T >::pointer |
| The type of the pointer returned by data() | |
| using | const_pointer = typename device_uvector< T >::const_pointer |
Public Member Functions | |
| device_scalar (device_scalar &&) noexcept=default | |
| Default move constructor. | |
| device_scalar & | operator= (device_scalar &&) noexcept=default |
| Default move assignment operator. More... | |
| device_scalar (device_scalar const &)=delete | |
| Copy ctor is deleted as it doesn't allow a stream argument. | |
| device_scalar & | operator= (device_scalar const &)=delete |
| Copy assignment is deleted as it doesn't allow a stream argument. | |
| device_scalar ()=delete | |
| Default constructor is deleted as it doesn't allow a stream argument. | |
| device_scalar (cuda_stream_view stream, device_async_resource_ref mr=mr::get_current_device_resource_ref()) | |
Construct a new uninitialized device_scalar. More... | |
| device_scalar (value_type const &initial_value, cuda_stream_view stream, device_async_resource_ref mr=mr::get_current_device_resource_ref()) | |
Construct a new device_scalar with an initial value. More... | |
| device_scalar (device_scalar const &other, cuda_stream_view stream, device_async_resource_ref mr=mr::get_current_device_resource_ref()) | |
Construct a new device_scalar by deep copying the contents of another device_scalar, using the specified stream and memory resource. More... | |
| value_type | value (cuda_stream_view stream) const |
| Copies the value from device to host, synchronizes, and returns the value. More... | |
| void | set_value_async (value_type const &value, cuda_stream_view stream) |
Sets the value of the device_scalar to the value of v. More... | |
| void | set_value_async (value_type &&, cuda_stream_view)=delete |
| void | set_value_to_zero_async (cuda_stream_view stream) |
Sets the value of the device_scalar to zero on the specified stream. More... | |
| pointer | data () noexcept |
| Returns pointer to object in device memory. More... | |
| const_pointer | data () const noexcept |
| Returns const pointer to object in device memory. More... | |
| constexpr size_type | size () const noexcept |
| The size of the scalar: always 1. More... | |
| cuda_stream_view | stream () const noexcept |
| Stream associated with the device memory allocation. More... | |
| void | set_stream (cuda_stream_view stream) noexcept |
| Sets the stream to be used for deallocation. More... | |
Container for a single object of type T in device memory.
T must be trivially copyable.
| T | The object's type |
| using rmm::device_scalar< T >::const_pointer = typename device_uvector<T>::const_pointer |
The type of the iterator returned by data() const
|
inlineexplicit |
Construct a new uninitialized device_scalar.
Does not synchronize the stream.
cudaStreamWaitEvent()).| rmm::bad_alloc | if allocating the device memory fails. |
| stream | Stream on which to perform asynchronous allocation. |
| mr | Optional, resource with which to allocate. |
|
inlineexplicit |
Construct a new device_scalar with an initial value.
Does not synchronize the stream.
cudaStreamWaitEvent()).| rmm::bad_alloc | if allocating the device memory for initial_value fails. |
| rmm::cuda_error | if copying initial_value to device memory fails. |
| initial_value | The initial value of the object in device memory. |
| stream | Optional, stream on which to perform allocation and copy. |
| mr | Optional, resource with which to allocate. |
|
inline |
Construct a new device_scalar by deep copying the contents of another device_scalar, using the specified stream and memory resource.
| rmm::bad_alloc | If creating the new allocation fails. |
| rmm::cuda_error | if copying from other fails. |
| other | The device_scalar 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_scalar |
|
inlinenoexcept |
Returns const pointer to object in device memory.
cudaStreamWaitEvent() or cudaStreamSynchronize()), otherwise there may be a race condition.
|
inlinenoexcept |
Returns pointer to object in device memory.
cudaStreamWaitEvent() or cudaStreamSynchronize()), otherwise there may be a race condition.
|
defaultnoexcept |
Default move assignment operator.
|
inlinenoexcept |
Sets the stream to be used for deallocation.
| stream | Stream to be used for deallocation |
|
inline |
Sets the value of the device_scalar to the value of v.
This specialization for fundamental types is optimized to use cudaMemsetAsync when v is zero.
cudaStreamWaitEvent() or cudaStreamSynchronize()) before and after calling this function, otherwise there may be a race condition.This function does not synchronize stream before returning. Therefore, the object referenced by v should not be destroyed or modified until stream has been synchronized. Otherwise, behavior is undefined.
Example:
| rmm::cuda_error | if copying value to device memory fails. |
| value | The host value which will be copied to device |
| stream | CUDA stream on which to perform the copy |
|
inline |
Sets the value of the device_scalar to zero on the specified stream.
cudaStreamWaitEvent() or cudaStreamSynchronize()) before and after calling this function, otherwise there may be a race condition.This function does not synchronize stream before returning.
| stream | CUDA stream on which to perform the copy |
|
inlineconstexprnoexcept |
The size of the scalar: always 1.
|
inlinenoexcept |
Stream associated with the device memory allocation.
|
inline |
Copies the value from device to host, synchronizes, and returns the value.
Synchronizes stream after copying the data from device to host.
cudaStreamWaitEvent() or cudaStreamSynchronize()) before calling this function, otherwise there may be a race condition.| rmm::cuda_error | If the copy fails. |
| rmm::cuda_error | If synchronizing stream fails. |
| stream | CUDA stream on which to perform the copy and synchronize. |