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

class to create a CUDA device 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

 cudaDeviceAllocator () noexcept
 Constructs a device allocator object.
 
 cudaDeviceAllocator (const cudaDeviceAllocator &) noexcept
 Constructs a device allocator object from another device allocator object.
 
template<typename U >
 cudaDeviceAllocator (const cudaDeviceAllocator< U > &) noexcept
 Constructs a device allocator object from another device allocator object with a different element type.
 
 ~cudaDeviceAllocator () 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, const_reference)
 ignored to avoid de-referencing device pointer from the host
 
void destroy (pointer)
 ignored to avoid de-referencing device pointer from the host
 
template<typename U >
bool operator== (const cudaDeviceAllocator< U > &) const noexcept
 compares two allocator of different types using ==
 
template<typename U >
bool operator!= (const cudaDeviceAllocator< U > &) const noexcept
 compares two allocator of different types using !=
 

Detailed Description

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

class to create a CUDA device allocator

Template Parameters
Telement type

A cudaDeviceAllocator enables device-specific 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::cudaDeviceAllocator< 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::cudaDeviceAllocator< 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::cudaDeviceAllocator< 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.

◆ deallocate()

template<typename T >
void tf::cudaDeviceAllocator< 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

◆ max_size()

template<typename T >
size_type tf::cudaDeviceAllocator< 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::cudaDeviceAllocator< T >::operator!= ( const cudaDeviceAllocator< U > &  ) const
inlinenoexcept

compares two allocator of different types using !=

Device 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::cudaDeviceAllocator< T >::operator== ( const cudaDeviceAllocator< U > &  ) const
inlinenoexcept

compares two allocator of different types using ==

Device 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: