openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
Public Types | Public Member Functions | List of all members
limpet::TargetAllocator< T > Struct Template Reference

Allocator structure for dynamically allocating memory on multiple targets. More...

#include <target.h>

Collaboration diagram for limpet::TargetAllocator< T >:

Public Types

typedef T value_type
 type to allocate More...
 

Public Member Functions

 TargetAllocator (Target target, bool always_managed=false)
 Construct a TargetAllocator. More...
 
Target get_target () const
 Get the target for this allocator. More...
 
void set_target (Target new_target)
 Set a new target for this allocator. More...
 
T * allocate (std::size_t n, bool do_zero=true)
 Allocate memory for type T. More...
 
void deallocate (T *ptr, std::size_t n=0)
 Deallocate memory pointed by ptr. More...
 

Detailed Description

template<typename T>
struct limpet::TargetAllocator< T >

Allocator structure for dynamically allocating memory on multiple targets.

This tries to respect the standard C++ allocator trait as much as possible but is not yet used like one.

Definition at line 104 of file target.h.

Member Typedef Documentation

◆ value_type

template<typename T>
typedef T limpet::TargetAllocator< T >::value_type

type to allocate

Definition at line 105 of file target.h.

Constructor & Destructor Documentation

◆ TargetAllocator()

template<typename T>
limpet::TargetAllocator< T >::TargetAllocator ( Target  target,
bool  always_managed = false 
)
inline

Construct a TargetAllocator.

Parameters
targettarget this allocator will allocate on
always_managedif true, always use managed memory management for GPU targets

Definition at line 114 of file target.h.

Member Function Documentation

◆ allocate()

template<typename T>
T* limpet::TargetAllocator< T >::allocate ( std::size_t  n,
bool  do_zero = true 
)
inline

Allocate memory for type T.

Parameters
nnumber of objects of type T to allocate (size of the array)
Returns
a pointer to the allocated memory
Note
the allocated memory depends on this allocator's target, so using the returned pointer in the wrong context can result in an error (for example, dereferencing a GPU device pointer in CPU code)

Definition at line 154 of file target.h.

Here is the caller graph for this function:

◆ deallocate()

template<typename T>
void limpet::TargetAllocator< T >::deallocate ( T *  ptr,
std::size_t  n = 0 
)
inline

Deallocate memory pointed by ptr.

Parameters
ptrpointer to the memory to deallocate
nsize of the memory to deallocate. This is set to 0 by default because it isn't needed for the function to work, but is required to fit with the allocator trait interface.

Definition at line 250 of file target.h.

Here is the caller graph for this function:

◆ get_target()

template<typename T>
Target limpet::TargetAllocator< T >::get_target ( ) const
inline

Get the target for this allocator.

Returns
this allocator's target

Definition at line 125 of file target.h.

◆ set_target()

template<typename T>
void limpet::TargetAllocator< T >::set_target ( Target  new_target)
inline

Set a new target for this allocator.

Parameters
new_targetnew target

Definition at line 134 of file target.h.


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