Class thrust::device_ptr

device_ptr is a pointer-like object which points to an object that resides in memory associated with the device system.

device_ptr has pointer semantics: it may be dereferenced safely from anywhere, including the host, and may be manipulated with pointer arithmetic.

device_ptr can be created with device_new, device_malloc, device_malloc_allocator, device_allocator, or device_pointer_cast, or by explicitly calling its constructor with a raw pointer.

The raw pointer contained in a device_ptr may be obtained via get member function or the raw_pointer_cast free function.

Algorithms operating on device_ptr types will automatically be dispatched to the device system.

Note: device_ptr is not a smart pointer; it is the programmer’s responsibility to deallocate memory pointed to by device_ptr.

Inherits From: thrust::pointer< T, thrust::device_system_tag, thrust::device_reference< T >, thrust::device_ptr< T > >

See:

#include <thrust/device_ptr.h>
template <typename T> class thrust::device_ptr { public:   /* Construct a null device_ptr. */  _CCCL_HOST_DEVICE   device_ptr();
   /* Construct a null device_ptr. */  _CCCL_HOST_DEVICE   device_ptr(std::nullptr_t);
   /* Construct a device_ptr from a raw pointer which is convertible to T*. */  template <typename U>   explicit _CCCL_HOST_DEVICE   device_ptr(U * ptr);
   /* Copy construct a device_ptr from another device_ptr whose pointer type is convertible to T*. */  template <typename U>   _CCCL_HOST_DEVICE   device_ptr(device_ptr< U > const & other);
   /* Set this device_ptr to point to the same object as another device_ptr whose pointer type is convertible to T*. */  template <typename U>   _CCCL_HOST_DEVICE device_ptr &   operator=(device_ptr< U > const & other);
   /* Set this device_ptr to null. */  _CCCL_HOST_DEVICE device_ptr &   operator=(std::nullptr_t);
   /* Return the raw pointer that this device_ptr points to. */  _CCCL_HOST_DEVICE T *   get() const; };

Member Functions

Function thrust::device_ptr::device_ptr

_CCCL_HOST_DEVICE device_ptr(); Construct a null device_ptr.

Postconditions: get() == nullptr.

Function thrust::device_ptr::device_ptr

_CCCL_HOST_DEVICE device_ptr(std::nullptr_t); Construct a null device_ptr.

Function Parameters: ptr: A null pointer.

Postconditions: get() == nullptr.

Function thrust::device_ptr::device_ptr

template <typename U> explicit _CCCL_HOST_DEVICE device_ptr(U * ptr); Construct a device_ptr from a raw pointer which is convertible to T*.

Template Parameters: U: A type whose pointer is convertible to T*.

Function Parameters: ptr: A raw pointer to a U in device memory to construct from.

Preconditions:

  • std::is_convertible_v<U*, T*> == true.
  • ptr points to a location in device memory.

Postconditions: get() == nullptr.

Function thrust::device_ptr::device_ptr

template <typename U> _CCCL_HOST_DEVICE device_ptr(device_ptr< U > const & other); Copy construct a device_ptr from another device_ptr whose pointer type is convertible to T*.

Template Parameters: U: A type whose pointer is convertible to T*.

Function Parameters: other: A device_ptr to a U to construct from.

Preconditions: std::is_convertible_v<U*, T*> == true.

Postconditions: get() == other.get().

Function thrust::device_ptr::operator=

template <typename U> _CCCL_HOST_DEVICE device_ptr & operator=(device_ptr< U > const & other); Set this device_ptr to point to the same object as another device_ptr whose pointer type is convertible to T*.

Template Parameters: U: A type whose pointer is convertible to T*.

Function Parameters: other: A device_ptr to a U to assign from.

Preconditions: std::is_convertible_v<U*, T*> == true.

Postconditions: get() == other.get().

Returns: *this.

Function thrust::device_ptr::operator=

_CCCL_HOST_DEVICE device_ptr & operator=(std::nullptr_t); Set this device_ptr to null.

Function Parameters: ptr: A null pointer.

Postconditions: get() == nullptr.

Returns: *this.

Function thrust::device_ptr::get

_CCCL_HOST_DEVICE T * get() const; Return the raw pointer that this device_ptr points to.