Taskflow  3.2.0-Master-Branch
Loading...
Searching...
No Matches
tf::cudaUSMAllocator< T > Class Template Reference

class to create a unified shared memory (USM) allocator More...

#include <cuda_memory.hpp>

Classes

struct  rebind
 its member type U is the equivalent allocator type to allocate elements of type U More...
 

Public Types

using value_type = T
 element type
 
using pointer = T *
 element pointer type
 
using reference = T &
 element reference type
 
using const_pointer = const T *
 const element pointer type
 
using const_reference = const T &
 constant element reference type
 
using size_type = std::size_t
 size type
 
using difference_type = std::ptrdiff_t
 pointer difference type
 

Public Member Functions

 cudaUSMAllocator () noexcept
 Constructs a device allocator object.
 
 cudaUSMAllocator (const cudaUSMAllocator &) noexcept
 Constructs a device allocator object from another device allocator object.
 
template<typename U >
 cudaUSMAllocator (const cudaUSMAllocator< U > &) noexcept
 Constructs a device allocator object from another device allocator object with a different element type.
 
 ~cudaUSMAllocator () noexcept
 Destructs the device allocator object.
 
pointer address (reference x)
 Returns the address of x.
 
const_pointer address (const_reference x) const
 Returns the address of x.
 
pointer allocate (size_type n, std::allocator< void >::const_pointer=0)
 allocates block of storage.
 
void deallocate (pointer ptr, size_type)
 Releases a block of storage previously allocated with member allocate and not yet released.
 
size_type max_size () const noexcept
 returns the maximum number of elements that could potentially be allocated by this allocator
 
void construct (pointer ptr, const_reference val)
 Constructs an element object on the location pointed by ptr.
 
void destroy (pointer ptr)
 destroys in-place the object pointed by ptr
 
template<typename U >
bool operator== (const cudaUSMAllocator< U > &) const noexcept
 compares two allocator of different types using ==
 
template<typename U >
bool operator!= (const cudaUSMAllocator< U > &) const noexcept
 compares two allocator of different types using !=
 

Detailed Description

template<typename T>
class tf::cudaUSMAllocator< T >

class to create a unified shared memory (USM) allocator

Template Parameters
Telement type

A cudaUSMAllocator enables using unified shared memory (USM) allocation for standard library containers. It is typically passed as template parameter when declaring standard library containers (e.g. std::vector).

Member Function Documentation

◆ address() [1/2]

template<typename T >
const_pointer tf::cudaUSMAllocator< T >::address ( const_reference  x) const
inline

Returns the address of x.

This effectively means returning &x.

Parameters
xreference to an object
Returns
a pointer to the object

◆ address() [2/2]

template<typename T >
pointer tf::cudaUSMAllocator< T >::address ( reference  x)
inline

Returns the address of x.

This effectively means returning &x.

Parameters
xreference to an object
Returns
a pointer to the object

◆ allocate()

template<typename T >
pointer tf::cudaUSMAllocator< T >::allocate ( size_type  n,
std::allocator< void >::const_pointer  = 0 
)
inline

allocates block of storage.

Attempts to allocate a block of storage with a size large enough to contain n elements of member type, value_type, and returns a pointer to the first element.

The storage is aligned appropriately for object of type value_type, but they are not constructed.

The block of storage is allocated using cudaMalloc and throws std::bad_alloc if it cannot allocate the total amount of storage requested.

Parameters
nnumber of elements (each of size sizeof(value_type)) to be allocated
Returns
a pointer to the initial element in the block of storage.

◆ construct()

template<typename T >
void tf::cudaUSMAllocator< T >::construct ( pointer  ptr,
const_reference  val 
)
inline

Constructs an element object on the location pointed by ptr.

Parameters
ptrpointer to a location with enough storage soace to contain an element of type value_type
valvalue to initialize the constructed element to

◆ deallocate()

template<typename T >
void tf::cudaUSMAllocator< T >::deallocate ( pointer  ptr,
size_type   
)
inline

Releases a block of storage previously allocated with member allocate and not yet released.

The elements in the array are not destroyed by a call to this member function.

Parameters
ptrpointer to a block of storage previously allocated with allocate

◆ destroy()

template<typename T >
void tf::cudaUSMAllocator< T >::destroy ( pointer  ptr)
inline

destroys in-place the object pointed by ptr

Notice that this does not deallocate the storage for the element but calls its destructor.

Parameters
ptrpointer to the object to be destroye

◆ max_size()

template<typename T >
size_type tf::cudaUSMAllocator< T >::max_size ( ) const
inlinenoexcept

returns the maximum number of elements that could potentially be allocated by this allocator

A call to member allocate with the value returned by this function can still fail to allocate the requested storage.

Returns
the nubmer of elements that might be allcoated as maximum by a call to member allocate

◆ operator!=()

template<typename T >
template<typename U >
bool tf::cudaUSMAllocator< T >::operator!= ( const cudaUSMAllocator< U > &  ) const
inlinenoexcept

compares two allocator of different types using !=

USM allocators of different types are always equal to each other because the storage allocated by the allocator a1 can be deallocated through a2.

◆ operator==()

template<typename T >
template<typename U >
bool tf::cudaUSMAllocator< T >::operator== ( const cudaUSMAllocator< U > &  ) const
inlinenoexcept

compares two allocator of different types using ==

USM allocators of different types are always equal to each other because the storage allocated by the allocator a1 can be deallocated through a2.


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