ATLAS Offline Software
CaloPrefetch.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef CALOEVENT_CALOPREFETCH_H
8 #define CALOEVENT_CALOPREFETCH_H
9 //--------------------------------------------------------------------------
10 // File and Version Information:
11 // $Id$
12 //------------------------------------------------------------------------
13 
14 #include "CxxUtils/prefetch.h"
15 #include "CaloEvent/CaloCell.h"
17 #include <cstddef>
18 
19 // ---------------------
20 // -- Class Interface --
21 // ---------------------
22 
33 namespace CaloPrefetch {
34 
35 
45 template <typename Iter>
46 inline
47 void nextDDE(Iter iter, Iter endIter)
48 {
49  if (++iter != endIter) {
50  // Get DDE, cell itself is expected to be in the cache already
51  CxxUtils::prefetchObj((*iter)->caloDDE());
52  if (++iter != endIter) {
53  // prefetch cell two steps ahead
54  CxxUtils::prefetchObj<CaloCell>(*iter);
55  }
56  }
57 }
58 
70 template <typename Iter>
71 inline
72 void nextDDE(Iter iter, Iter endIter, int count)
73 {
74  for (int i = 0; i != count; ++ i) {
75  if (++iter != endIter) {
76  // Get DDE, cell itself is expected to be in the cache already
77  CxxUtils::prefetchObj((*iter)->caloDDE());
78  } else {
79  return;
80  }
81  }
82  for (int i = 0; i != count; ++ i) {
83  if (++iter != endIter) {
84  // prefetch cell two steps ahead
85  CxxUtils::prefetchObj<CaloCell>(*iter);
86  } else {
87  return;
88  }
89  }
90 }
91 
101 template <class T, class ALLOC, int COUNT=1>
102 class ArenaHandlePrefetch : public SG::ArenaHandle<T, ALLOC>{
103 
105 
106 public:
107 
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  }
120 
124  void* allocate()
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  }
132 
136  void erase() {
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  }
145 
146 private:
147  void* m_buf[COUNT];
148 };
149 
150 } // namespace CaloPrefetch
151 
152 
153 #endif // CALOEVENT_CALOPREFETCH_H
CaloPrefetch::ArenaHandlePrefetch
Wrapper for SG::ArenaHandle with pre-fetching.
Definition: CaloPrefetch.h:102
SG::ArenaHandle
User interface for allocating memory.
Definition: ArenaHandle.h:73
ArenaHandle.h
User interface for allocating memory. See Arena.h for an overview of the arena-based memory allocator...
SG::ArenaHandle::allocate
void * allocate()
Allocate a new element.
CaloCell.h
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
CaloPrefetch::ArenaHandlePrefetch::m_buf
void * m_buf[COUNT]
Definition: CaloPrefetch.h:147
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloPrefetch
This software was developed for the ATLAS project.
Definition: CaloPrefetch.h:33
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
CaloPrefetch::ArenaHandlePrefetch::allocate
void * allocate()
Return space for new element, then allocate and prefetch one more.
Definition: CaloPrefetch.h:124
CxxUtils::prefetchObj
void prefetchObj(const T *ptr)
Generic prefetch of the object of specific types (sizes).
Definition: prefetch.h:108
CaloPrefetch::ArenaHandlePrefetch::ArenaHandlePrefetch
ArenaHandlePrefetch()
Make.
Definition: CaloPrefetch.h:111
CaloPrefetch::nextDDE
void nextDDE(Iter iter, Iter endIter)
Prefetch next CaloDDE.
Definition: CaloPrefetch.h:47
prefetch.h
Functions to prefetch blocks of memory.
CaloPrefetch::ArenaHandlePrefetch::erase
void erase()
Free all allocated elements.
Definition: CaloPrefetch.h:136