|
| | host_ptr ()=default |
| | Construct an empty handle that owns and points to nothing.
|
| | host_ptr (std::nullptr_t) noexcept |
| | Construct an empty handle from nullptr (mirrors std::shared_ptr).
|
template<typename U>
requires std::is_convertible_v<U*, T*> |
| | host_ptr (U *ptr) |
| | Take ownership of ptr, deleting it with delete when the last reference drops.
|
template<typename U, typename Deleter>
requires std::is_convertible_v<U*, T*> |
| | host_ptr (U *ptr, Deleter deleter) |
| | Take ownership of ptr, invoking deleter(ptr) when the last reference drops.
|
| template<typename Deleter> |
| | host_ptr (std::nullptr_t, Deleter deleter) |
| | Own no object but carry a deleter to invoke with nullptr (mirrors std::shared_ptr).
|
template<typename U, typename Deleter>
requires std::is_convertible_v<U*, T*> |
| | host_ptr (std::unique_ptr< U, Deleter > &&owner) |
| | Adopt the object owned by a std::unique_ptr.
|
| | host_ptr (const T &value) |
| | Construct a fresh T by copying value (convenience beyond std::shared_ptr).
|
| | host_ptr (T &&value) |
| | Construct a fresh T by moving value (convenience beyond std::shared_ptr).
|
| template<typename... Args> |
| | host_ptr (std::in_place_t, Args &&... args) |
| | Construct a fresh T in place, forwarding args to its constructor.
|
| | host_ptr (const host_ptr &)=default |
| | Shallow copy: shares ownership. Trivially device-copyable.
|
| | host_ptr (host_ptr &&)=default |
template<typename U>
requires std::is_convertible_v<U*, T*> |
| | host_ptr (const host_ptr< U > &other) |
| | Converting copy: host_ptr<Base> from host_ptr<Derived> (shares ownership, retypes the pointer).
|
template<typename U>
requires std::is_convertible_v<U*, T*> |
| | host_ptr (host_ptr< U > &&other) |
| | Converting move.
|
| template<typename U> |
| | host_ptr (const host_ptr< U > &other, T *ptr) |
| | Aliasing constructor: shares other's ownership but points at ptr (which need not be other's object).
|
| | ~host_ptr () |
| | Release this handle's ownership; runs the disposer if this was the last reference.
|
| host_ptr & | operator= (const host_ptr &other) |
| host_ptr & | operator= (host_ptr &&other) noexcept |
template<typename U>
requires std::is_convertible_v<U*, T*> |
| host_ptr & | operator= (const host_ptr< U > &other) |
template<typename U>
requires std::is_convertible_v<U*, T*> |
| host_ptr & | operator= (host_ptr< U > &&other) |
| host_ptr & | operator= (std::nullptr_t) noexcept |
| void | reset () noexcept |
| | Become empty, releasing ownership (runs the disposer if this was the last reference).
|
template<typename U>
requires std::is_convertible_v<U*, T*> |
| void | reset (U *ptr) |
| | Replace the managed object with ownership of ptr (deleted with delete).
|
template<typename U, typename Deleter>
requires std::is_convertible_v<U*, T*> |
| void | reset (U *ptr, Deleter deleter) |
| | Replace the managed object with ownership of ptr and a custom deleter.
|
| template<typename... Args> |
| void | emplace (Args &&... args) |
| | Replace the managed object with a fresh T constructed from args (convenience).
|
| void | swap (host_ptr &other) noexcept |
| | Swap ownership and pointer with another handle.
|
template<typename T>
class mundy::host_ptr< T >
host_ptr<T> is, semantically, a std::shared_ptr<T> that survives being captured by value into a device kernel: were device support not a concern, a plain std::shared_ptr<T> would be used instead. It mirrors std::shared_ptr in ownership model and interface — owning raw-pointer construction, custom deleters, unique_ptr adoption, the aliasing constructor, Derived→Base conversions, the pointer casts, ordering/hashing/owner_before, and reset — with the single deliberate omission of weak_ptr/enable_shared_from_this.
- How the device-copyability works
- A host_ptr is a Kokkos::View (the device-copyable, reference-counted allocation) holding a small type-erased control block, plus a typed T* ptr_. The View supplies the reference count — atomic on the host, with tracking disabled inside kernels, so a copy captured into a kernel is a cheap non-owning handle and the owner must outlive the kernel. The hand-rolled control block supplies only type-erased destruction (the disposer), so deleters, adoption, aliasing, and polymorphism all work without std::shared_ptr. The value lives in host memory and is accessible only on the host: the accessors are not KOKKOS_FUNCTION, so dereferencing on the device is a compile error.
- Template Parameters
-
| T | Host-resident pointed-to type. |