9 #include <rmm/detail/export.hpp>
14 #include <type_traits>
33 static_assert(std::is_trivially_copyable_v<T>,
"Scalar type must be trivially copyable");
44 RMM_EXEC_CHECK_DISABLE
47 RMM_EXEC_CHECK_DISABLE
89 : _storage{1, stream, std::move(mr)}
115 : _storage{1, stream, std::move(mr)}
117 set_value_async(initial_value, stream);
124 cuda::mr::any_resource<cuda::mr::device_accessible> mr =
142 : _storage{other._storage, stream, std::move(mr)}
164 return _storage.front_element(stream);
202 _storage.set_element_async(0, value, stream);
225 _storage.set_element_to_zero_async(
value_type{0}, stream);
276 static_assert(std::is_constructible_v<device_scalar<int>,
int const&, cuda_stream_view>);
277 static_assert(std::is_constructible_v<device_scalar<int>,
280 cuda::mr::any_resource<cuda::mr::device_accessible>>);
281 static_assert(!std::is_constructible_v<device_scalar<int>,
int, cuda_stream_view>);
282 static_assert(!std::is_constructible_v<device_scalar<int>,
int const, cuda_stream_view>);
283 static_assert(!std::is_constructible_v<device_scalar<int>,
286 cuda::mr::any_resource<cuda::mr::device_accessible>>);
287 static_assert(!std::is_constructible_v<device_scalar<int>,
290 cuda::mr::any_resource<cuda::mr::device_accessible>>);
291 static_assert([]<
typename Scalar>(Scalar*) {
292 return requires(Scalar& scalar,
int value, cuda_stream_view stream) {
293 scalar.set_value_async(value, stream);
294 } && requires(Scalar& scalar,
int const value, cuda_stream_view stream) {
295 scalar.set_value_async(value, stream);
296 } && !requires(Scalar& scalar,
int value, cuda_stream_view stream) {
297 scalar.set_value_async(std::move(value), stream);
298 } && !requires(Scalar& scalar,
int const value, cuda_stream_view stream) {
299 scalar.set_value_async(std::move(value), stream);
301 }(
static_cast<device_scalar<int>*
>(
nullptr)));
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:28
Container for a single object of type T in device memory.
Definition: device_scalar.hpp:31
typename device_uvector< T >::value_type value_type
T, the type of the scalar element.
Definition: device_scalar.hpp:35
constexpr size_type size() const noexcept
The size of the scalar: always 1.
Definition: device_scalar.hpp:258
device_scalar(value_type const &initial_value, cuda_stream_view stream, cuda::mr::any_resource< cuda::mr::device_accessible > mr=mr::get_current_device_resource_ref())
Construct a new device_scalar with an initial value.
Definition: device_scalar.hpp:111
const_pointer data() const noexcept
Returns const pointer to object in device memory.
Definition: device_scalar.hpp:250
typename device_uvector< T >::const_reference const_reference
const value_type&
Definition: device_scalar.hpp:38
typename device_uvector< T >::size_type size_type
The type used for the size.
Definition: device_scalar.hpp:36
device_scalar(device_scalar &&) noexcept=default
Default move constructor.
device_scalar(device_scalar const &other, cuda_stream_view stream, cuda::mr::any_resource< cuda::mr::device_accessible > mr=mr::get_current_device_resource_ref())
Construct a new device_scalar by deep copying the contents of another device_scalar,...
Definition: device_scalar.hpp:138
void set_stream(cuda_stream_view stream) noexcept
Sets the stream to be used for deallocation.
Definition: device_scalar.hpp:270
typename device_uvector< T >::const_pointer const_pointer
Definition: device_scalar.hpp:42
cuda_stream_view stream() const noexcept
Stream associated with the device memory allocation.
Definition: device_scalar.hpp:263
pointer data() noexcept
Returns pointer to object in device memory.
Definition: device_scalar.hpp:238
value_type value(cuda_stream_view stream) const
Copies the value from device to host, synchronizes, and returns the value.
Definition: device_scalar.hpp:162
void set_value_to_zero_async(cuda_stream_view stream)
Sets the value of the device_scalar to zero on the specified stream.
Definition: device_scalar.hpp:223
void set_value_async(value_type const &value, cuda_stream_view stream)
Sets the value of the device_scalar to the value of v.
Definition: device_scalar.hpp:200
typename device_uvector< T >::pointer pointer
The type of the pointer returned by data()
Definition: device_scalar.hpp:40
typename device_uvector< T >::reference reference
value_type&
Definition: device_scalar.hpp:37
An uninitialized vector of elements in device memory.
Definition: device_uvector.hpp:70
value_type * pointer
The type of the pointer returned by data()
Definition: device_uvector.hpp:80
std::size_t size_type
The type used for the size of the vector.
Definition: device_uvector.hpp:76
T value_type
Stored value type.
Definition: device_uvector.hpp:75
value_type & reference
Reference type returned by operator[](size_type)
Definition: device_uvector.hpp:77
value_type const * const_pointer
The type of the pointer returned by data() const.
Definition: device_uvector.hpp:81
value_type const & const_reference
Constant reference type returned by operator[](size_type) const.
Definition: device_uvector.hpp:79
device_async_resource_ref get_current_device_resource_ref()
Get the device_async_resource_ref for the current device.
Definition: per_device_resource.hpp:187
Management of per-device memory resources.