ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Types | Private Attributes | List of all members
CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT > Class Template Reference

Wrapper for SG::ArenaHandle with pre-fetching. More...

#include <CaloPrefetch.h>

Inheritance diagram for CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT >:
Collaboration diagram for CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT >:

Public Types

typedef Base::pointer pointer
 Pointer to an element. More...
 
typedef Base::iterator iterator
 Iterators over elements. More...
 
typedef Base::const_iterator const_iterator
 
typedef ALLOC::template initParams< T, false, true > defaultParams_t
 The class that initializes the default parameter set. More...
 
typedef ALLOC alloc_t
 The Allocator we use. More...
 

Public Member Functions

 ArenaHandlePrefetch ()
 Make. More...
 
void * allocate ()
 Return space for new element, then allocate and prefetch one more. More...
 
void erase ()
 Free all allocated elements. More...
 
iterator begin ()
 Starting iterator. More...
 
const_iterator begin () const
 Starting const iterator. More...
 
iterator end ()
 Ending iterator. More...
 
const_iterator end () const
 Ending const iterator. More...
 
void free (pointer p)
 Free an element. More...
 
void resetTo (pointer p)
 Reset pool back to a previous state. More...
 
const ALLOC::Params & params () const
 Return our Allocator's parameters. More...
 
void reset ()
 Free all allocated elements (of this type in the current Arena). More...
 
void reserve (size_t size)
 Set the total number of elements cached by the allocator (in the current Arena). More...
 
ArenaAllocatorBase::Stats stats () const
 Return the statistics block for this allocator, for the current Arena. More...
 

Static Public Member Functions

static std::unique_ptr< ArenaAllocatorBase > makeAllocator (const typename ALLOC::Params &params)
 Internal helper: create a new Allocator instance. More...
 

Protected Member Functions

ALLOC * allocator ()
 Return our current Allocator. More...
 
const ALLOC * allocator () const
 Return our current Allocator. More...
 
ArenaAllocatorBase * baseAllocator ()
 Return the current Allocator which we are referencing. More...
 
const ArenaAllocatorBase * baseAllocator () const
 Return the current Allocator which we are referencing. More...
 

Static Protected Member Functions

template<class HANDLE , class DEFPARAMS >
static size_t makeIndex (const typename ALLOC::Params *params)
 Find the index for creating an allocator. More...
 

Private Types

typedef SG::ArenaHandle< T, ALLOC > Base
 

Private Attributes

void * m_buf [COUNT]
 
LockedAllocator m_allocator
 The associated allocator object. More...
 

Detailed Description

template<class T, class ALLOC, int COUNT = 1>
class CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT >

Wrapper for SG::ArenaHandle with pre-fetching.

This class wraps SG::ArenaHandle and adds pre-fetching capability. Number of prefetched allocations is specified as a template argument so it must be a compile-time constant. By default a single allocation is pre-fetched, for tighter loops or if one allocates more than one item in the loop larger count can be specified.

Definition at line 102 of file CaloPrefetch.h.

Member Typedef Documentation

◆ alloc_t

template<typename ALLOC >
typedef ALLOC SG::ArenaHandleBaseAllocT< ALLOC >::alloc_t
inherited

The Allocator we use.

Definition at line 57 of file ArenaHandleBaseAllocT.h.

◆ Base

template<class T , class ALLOC , int COUNT = 1>
typedef SG::ArenaHandle<T, ALLOC> CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT >::Base
private

Definition at line 104 of file CaloPrefetch.h.

◆ const_iterator

template<class T , class ALLOC >
typedef Base::const_iterator SG::ArenaHandle< T, ALLOC >::const_iterator
inherited

Definition at line 84 of file ArenaHandle.h.

◆ defaultParams_t

template<class T , class ALLOC >
typedef ALLOC::template initParams<T, false, true> SG::ArenaHandle< T, ALLOC >::defaultParams_t
inherited

The class that initializes the default parameter set.

Definition at line 97 of file ArenaHandle.h.

◆ iterator

template<class T , class ALLOC >
typedef Base::iterator SG::ArenaHandle< T, ALLOC >::iterator
inherited

Iterators over elements.

(May only be instantiated if the underlying Allocator supports them.)

Definition at line 83 of file ArenaHandle.h.

◆ pointer

template<class T , class ALLOC >
typedef Base::pointer SG::ArenaHandle< T, ALLOC >::pointer
inherited

Pointer to an element.

Definition at line 79 of file ArenaHandle.h.

Constructor & Destructor Documentation

◆ ArenaHandlePrefetch()

template<class T , class ALLOC , int COUNT = 1>
CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT >::ArenaHandlePrefetch ( )
inline

Make.

Definition at line 111 of file CaloPrefetch.h.

111  : Base()
112  {
113  for (int i = 0; i != COUNT; ++ i) {
114  m_buf[i] = Base::allocate();
115  }
116  for (int i = 0; i != COUNT; ++ i) {
117  CxxUtils::prefetchN<sizeof(T)>(m_buf[i]);
118  }
119  }

Member Function Documentation

◆ allocate()

template<class T , class ALLOC , int COUNT = 1>
void* CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT >::allocate ( )
inline

Return space for new element, then allocate and prefetch one more.

Definition at line 124 of file CaloPrefetch.h.

125  {
126  void* res = m_buf[0];
127  std::move(m_buf + 1, m_buf + COUNT, m_buf);
128  m_buf[COUNT-1] = Base::allocate();
129  CxxUtils::prefetchN<sizeof(T)>(m_buf[COUNT-1]);
130  return res;
131  }

◆ allocator() [1/2]

template<typename ALLOC >
ALLOC* SG::ArenaHandleBaseAllocT< ALLOC >::allocator ( )
protectedinherited

Return our current Allocator.

◆ allocator() [2/2]

template<typename ALLOC >
const ALLOC* SG::ArenaHandleBaseAllocT< ALLOC >::allocator ( ) const
protectedinherited

Return our current Allocator.

◆ baseAllocator() [1/2]

ArenaAllocatorBase* SG::ArenaHandleBase::baseAllocator ( )
protectedinherited

Return the current Allocator which we are referencing.

This may cause a new Allocator to be created.

◆ baseAllocator() [2/2]

const ArenaAllocatorBase* SG::ArenaHandleBase::baseAllocator ( ) const
protectedinherited

Return the current Allocator which we are referencing.

This may cause a new Allocator to be created.

◆ begin() [1/2]

template<class T , class ALLOC >
iterator SG::ArenaHandleBaseT< T, ALLOC >::begin ( )
inherited

Starting iterator.

This will iterate over all allocated elements (in unspecified order). It is at least a forward_iterator. This may only be instantiated if the underlying Allocator supports iterators.

◆ begin() [2/2]

template<class T , class ALLOC >
const_iterator SG::ArenaHandleBaseT< T, ALLOC >::begin ( ) const
inherited

Starting const iterator.

This will iterate over all allocated elements (in unspecified order). It is at least a forward_iterator. This may only be instantiated if the underlying Allocator supports iterators.

◆ end() [1/2]

template<class T , class ALLOC >
iterator SG::ArenaHandleBaseT< T, ALLOC >::end ( )
inherited

Ending iterator.

This may only be instantiated if the underlying Allocator supports iterators.

◆ end() [2/2]

template<class T , class ALLOC >
const_iterator SG::ArenaHandleBaseT< T, ALLOC >::end ( ) const
inherited

Ending const iterator.

This may only be instantiated if the underlying Allocator supports iterators.

◆ erase()

template<class T , class ALLOC , int COUNT = 1>
void CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT >::erase ( )
inline

Free all allocated elements.

Definition at line 136 of file CaloPrefetch.h.

136  {
137  Base::erase();
138  for (int i = 0; i != COUNT; ++ i) {
139  m_buf[i] = Base::allocate();
140  }
141  for (int i = 0; i != COUNT; ++ i) {
142  CxxUtils::prefetchN<sizeof(T)>(m_buf[i]);
143  }
144  }

◆ free()

template<class T , class ALLOC >
void SG::ArenaHandleBaseT< T, ALLOC >::free ( pointer  p)
inherited

Free an element.

Parameters
pThe element to be freed.

clear() will be called on the element at this point, if it has been defined.

This may only be instantiated if it's supported by the underlying Allocator.

◆ makeAllocator()

template<class T , class ALLOC >
static std::unique_ptr<ArenaAllocatorBase> SG::ArenaHandle< T, ALLOC >::makeAllocator ( const typename ALLOC::Params &  params)
staticinherited

Internal helper: create a new Allocator instance.

Parameters
paramsThe parameters for the Allocator.

◆ makeIndex()

template<typename ALLOC >
template<class HANDLE , class DEFPARAMS >
static size_t SG::ArenaHandleBaseAllocT< ALLOC >::makeIndex ( const typename ALLOC::Params *  params)
staticprotectedinherited

Find the index for creating an allocator.

Parameters
paramsPointer to the supplied parameters. If null, use the result of DEFPARAMS().

We look up in the registry the Allocator name we get from params (if this is blank, a name is derived from ALLOC). If not found, then we register Allocator and return the new index.

◆ params()

template<typename ALLOC >
const ALLOC::Params& SG::ArenaHandleBaseAllocT< ALLOC >::params ( ) const
inherited

Return our Allocator's parameters.

◆ reserve()

void SG::ArenaHandleBase::reserve ( size_t  size)
inherited

Set the total number of elements cached by the allocator (in the current Arena).

Parameters
sizeThe desired pool size.

This allows changing the number of elements that are currently free but cached. Any allocated elements are not affected by this call.

If size is greater than the total number of elements currently cached, then more will be allocated. This will preferably done with a single block, but that is not guaranteed; in addition, the allocator may allocate more elements than is requested.

If size is smaller than the total number of elements currently cached, as many blocks as possible will be released back to the system. It may not be possible to release the number of elements requested; this should be implemented on a best-effort basis.

Definition at line 111 of file ArenaHandleBase.cxx.

112 {
113  return baseAllocator()->reserve (size);
114 }

◆ reset()

void SG::ArenaHandleBase::reset ( )
inherited

Free all allocated elements (of this type in the current Arena).

All elements allocated in the current Arena by our associated Allocator are returned to the free state. clear should be called on them if it was provided. The elements may continue to be cached internally, without returning to the system.

Definition at line 71 of file ArenaHandleBase.cxx.

72 {
73  return baseAllocator()->reset();
74 }

◆ resetTo()

template<class T , class ALLOC >
void SG::ArenaHandleBaseT< T, ALLOC >::resetTo ( pointer  p)
inherited

Reset pool back to a previous state.

Parameters
pThe pointer back to which to reset.

This will free (a la reset) the element p and all elements that have been allocated after it from this allocator.

This may only be instantiated if it's supported by the underlying Allocator.

◆ stats()

ArenaAllocatorBase::Stats SG::ArenaHandleBase::stats ( ) const
inherited

Return the statistics block for this allocator, for the current Arena.

Definition at line 121 of file ArenaHandleBase.cxx.

122 {
123  return baseAllocator()->stats();
124 }

Member Data Documentation

◆ m_allocator

LockedAllocator SG::ArenaHandleBase::m_allocator
privateinherited

The associated allocator object.

Definition at line 160 of file ArenaHandleBase.h.

◆ m_buf

template<class T , class ALLOC , int COUNT = 1>
void* CaloPrefetch::ArenaHandlePrefetch< T, ALLOC, COUNT >::m_buf[COUNT]
private

Definition at line 147 of file CaloPrefetch.h.


The documentation for this class was generated from the following file:
SG::ArenaHandleBase::baseAllocator
ArenaAllocatorBase * baseAllocator()
Return the current Allocator which we are referencing.
SG::ArenaAllocatorBase::stats
virtual Stats stats() const =0
Return the statistics block for this allocator.
SG::ArenaHandle::allocate
void * allocate()
Allocate a new element.
SG::ArenaHandleBase::erase
void erase()
Free all allocated elements and release memory back to the system (of this type in the current Arena)...
Definition: ArenaHandleBase.cxx:87
SG::ArenaAllocatorBase::reserve
virtual void reserve(size_t size)=0
Set the total number of elements cached by the allocator.
CaloPrefetch::ArenaHandlePrefetch::m_buf
void * m_buf[COUNT]
Definition: CaloPrefetch.h:147
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
lumiFormat.i
int i
Definition: lumiFormat.py:85
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
CaloPrefetch::ArenaHandlePrefetch::Base
SG::ArenaHandle< T, ALLOC > Base
Definition: CaloPrefetch.h:104
SG::ArenaAllocatorBase::reset
virtual void reset()=0
Free all allocated elements.