Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
SharedDevPtr< T > Class Template Reference

Wraps a device pointer while providing shared object semantics. More...

#include <shared.h>

Public Types

typedef T * wrapped_ref_type
 

Public Member Functions

__host__ __device__ SharedDevPtr ()
 Default constructor (creates an "empty" instance)
 
template<typename Deleter >
__host__ SharedDevPtr (T *ptr, Deleter d)
 Primary constructor.
 
__host__ __device__ ~SharedDevPtr () noexcept
 Destructor.
 
__host__ __device__ SharedDevPtr (const SharedDevPtr &other) noexcept
 
__host__ __device__ SharedDevPtr (SharedDevPtr &&other) noexcept
 
__host__ __device__ SharedDevPtroperator= (const SharedDevPtr &other) noexcept
 
__host__ __device__ SharedDevPtroperator= (SharedDevPtr &&other) noexcept
 
__host__ __device__ void swap (SharedDevPtr &other) noexcept
 swap the contents of this and other
 
__host__ __device__ void reset () noexcept
 Release ownership of the owned resource (if any)
 
__host__ __device__ __forceinline__ T * get () const noexcept
 Return the stored pointer.
 
__host__ __device__ operator bool () const noexcept
 
__device__ __forceinline__ T & operator* () const noexcept
 Dereference the stored pointer.
 
__device__ __forceinline__ T & operator[] (std::ptrdiff_t idx) const
 Dereference the stored pointer.
 

Detailed Description

template<typename T>
class SharedDevPtr< T >

Wraps a device pointer while providing shared object semantics.

At a high level, this analogous to shared_ptr, but for device pointers.

Constructor & Destructor Documentation

◆ SharedDevPtr()

template<typename T >
template<typename Deleter >
__host__ SharedDevPtr< T >::SharedDevPtr ( T *  ptr,
Deleter  d 
)
inline

Primary constructor.

d is a callback function-like object that is used deallocate ptr when all SharedDevPtr instances that wrap ptr release ownership. The callback will be invoked as d(ptr)

Parameters
ptrthe device pointer to be managed by the constructed instance
dA deleter instance used to destroy the handle
Warning
Passing a ptr that is already owned by another SharedDevPtr leads to undefined behavior

Member Function Documentation

◆ operator bool()

template<typename T >
__host__ __device__ SharedDevPtr< T >::operator bool ( ) const
inlineexplicitnoexcept

check if the wrapped pointer is a nullptr

◆ operator*()

template<typename T >
__device__ __forceinline__ T & SharedDevPtr< T >::operator* ( ) const
inlinenoexcept

Dereference the stored pointer.

Note
For less experienced C++ developers, this is the way to override the pointer dereference syntax. Suppose you have a SharedDevPtr instance called my_ptr. This method lets you write *my_ptr, which is equivalent to *(my_ptr.get())

◆ operator[]()

template<typename T >
__device__ __forceinline__ T & SharedDevPtr< T >::operator[] ( std::ptrdiff_t  idx) const
inline

Dereference the stored pointer.

Note
For less experienced C++ developers, this is the way to override the pointer subscripting syntax. Suppose you have a SharedDevPtr instance called my_ptr. This method lets you write my_ptr[i] (where i is a non-negative index), which is equivalent to (my_ptr.get())[i]

◆ reset()

template<typename T >
__host__ __device__ void SharedDevPtr< T >::reset ( )
noexcept

Release ownership of the owned resource (if any)

This is equivalent to SharedDevPtr().swap(*this);


The documentation for this class was generated from the following file: