ATLAS Offline Software
CaloGPUHybridClusterProcessor.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 //
4 // Dear emacs, this is -*- c++ -*-
5 //
6 
7 #ifndef CALORECGPU_CALOGPUHYBRIDCLUSTERPROCESSOR_H
8 #define CALORECGPU_CALOGPUHYBRIDCLUSTERPROCESSOR_H
9 
10 
12 #include "GaudiKernel/ToolHandle.h"
14 
16 
22 #include "CaloRecGPU/DataHolders.h"
23 
25 
28 
30 
31 #include <string>
32 #include <mutex>
33 #include <atomic>
34 #include <utility>
35 
52 {
53  public:
54 
55  CaloGPUHybridClusterProcessor(const std::string & name, ISvcLocator * pSvcLocator);
56  virtual ~CaloGPUHybridClusterProcessor() override = default;
57 
58  virtual StatusCode initialize() override
59  {
61  }
62 
63  virtual StatusCode initialize_non_CUDA() override;
64 
65  virtual StatusCode initialize_CUDA() override;
66 
67  virtual StatusCode execute(const EventContext & ctx) const override;
68  virtual StatusCode finalize() override;
69 
70  private:
71 
72 
77  ToolHandle<ICaloClusterGPUConstantTransformer> m_transformConstantData{this, "ConstantDataToGPUTool", "", "Tool for transforming the constant data and sending it to the GPU"};
78 
83  ToolHandleArray<CaloClusterCollectionProcessor> m_preGPUoperations{this, "BeforeGPUTools", {}, "Tools to be applied to the clusters on the CPU before processing them on the GPU"};
84 
85 
90  ToolHandle<ICaloClusterGPUInputTransformer> m_transformForGPU{this, "EventDataToGPUTool", "", "Tool for transforming the event data and sending it to the GPU"};
91 
96  ToolHandleArray<CaloClusterGPUProcessor> m_GPUoperations{this, "GPUTools", {}, "Tools to be applied to the clusters on the GPU"};
97 
102  ToolHandle<ICaloClusterGPUOutputTransformer> m_transformBackToCPU{this, "GPUToEventDataTool", {}, "Tool for getting the data from the GPU back to the CPU Athena data structures"};
103 
108  ToolHandleArray<CaloClusterCollectionProcessor> m_postGPUoperations{this, "AfterGPUTools", {}, "Tools to be applied to the clusters on the CPU after returning from the GPU"};
109 
110 
114  Gaudi::Property<bool> m_doPlots{this, "DoPlots", false, "Do plots based on the plotter tool optionally provided."};
115 
120  ToolHandle<ICaloClusterGPUPlotter> m_plotterTool{this, "PlotterTool", "", "An optional plotter, for testing and/or debugging purposes"};
121 
122 
125  Gaudi::Property<bool> m_doMonitoring{this, "DoMonitoring", false, "Do monitoring."};
126  Gaudi::Property<bool> m_monitorCells{this, "MonitorCells", false, "Whether to monitor cells too."};
127  Gaudi::Property<float> m_monitoring1thr { this, "Thr1", 2, "First Threshold to pass for cell monitoring" };
128  Gaudi::Property<float> m_monitoring2thr { this, "Thr2", 4, "Second Threshold to pass for cell monitoring" };
129 
130 
131  // adding noise handle for monitoring purposes
132  SG::ReadCondHandleKey<CaloNoise> m_noiseCDOKey{this, "CaloNoiseKey", "totalNoise", "SG Key of CaloNoise data object"};
133 
136  ToolHandle<GenericMonitoringTool> m_moniTool { this, "MonitoringTool", "", "Monitoring tool" };
137 
139  SG::ReadDecorHandleKey<xAOD::EventInfo> m_avgMuKey { this, "averageInteractionsPerCrossingKey", "EventInfo.averageInteractionsPerCrossing", "Decoration for Average Interaction Per Crossing" };
140 
143  Gaudi::Property<bool> m_writeTriggerSpecificInfo{this, "WriteTriggerSpecificInfo", false, "Write some trigger-specific decorations and use the trigger auxiliary container."};
144 
147  SG::WriteDecorHandleKey<xAOD::CaloClusterContainer> m_mDecor_ncells {this, "Decor_ncells", "nCells", "Decorator containing the number of cells associated to a cluster"};
148 
154  Gaudi::Property<size_t> m_numPreAllocatedGPUData{this, "NumPreAllocatedDataHolders", 0, "Number of event data holders to pre-allocate on GPU memory"};
155 
159  SG::ReadHandleKey<CaloCellContainer> m_cellsKey {this, "CellsName", "", "Name(s) of Cell Containers"};
160 
163  SG::WriteHandleKey<xAOD::CaloClusterContainer> m_clusterOutput {this, "ClustersOutputName", "", "The name of the key in StoreGate for the output CaloClusterContainer"};
164 
167  SG::WriteHandleKey<CaloClusterCellLinkContainer> m_clusterCellLinkOutput{this, "ClusterCellLinksOutputName", "", "The name of the key in StoreGate for the output CaloClusterCellLinkContainer"};
168 
173  Gaudi::Property<bool> m_deferConstantDataToFirstEvent {this, "DeferConstantDataPreparationToFirstEvent", true, "Convert and send event data on first event instead of during initialize (needed for exporting geometry and noise properly)?"};
174 
175 
178  Gaudi::Property<bool> m_skipConversions {this, "SkipConversions", false, "If true, skip converting CPU to GPU data (useful if only instanting CPU tools)"};
179 
185 
191  {
192  private:
193  void * m_ptr;
194 
195  public:
196 
197  void allocate(const size_t size)
198  {
199  if (m_ptr == nullptr && size > 0)
200  {
202  }
203  }
204 
206  m_ptr(nullptr)
207  {
208  }
211  {
212  m_ptr = other.m_ptr;
213  other.m_ptr = nullptr;
214  }
216 
218  {
219  std::swap(m_ptr, other.m_ptr);
220  return (*this);
221  }
222 
224  {
225  if (m_ptr != nullptr)
226  //This check might still be needed to ensure the code behaves on non-CUDA enabled platforms
227  //where some destructors might still be called with nullptr.
228  {
230  }
231  }
232 
233  void * operator* ()
234  {
235  return m_ptr;
236  }
237 
238  void * get_pointer()
239  {
240  return m_ptr;
241  }
242 
243  };
244 
250 
258 
265 
270  mutable std::atomic<bool> m_constantDataSent;
271 
272 
277 
278 };
279 
280 #endif //CALORECGPU_CALOGPUHYBRIDCLUSTERPROCESSOR_H
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
CaloGPUHybridClusterProcessor::m_transformBackToCPU
ToolHandle< ICaloClusterGPUOutputTransformer > m_transformBackToCPU
The tool that will convert the data from the GPU back to the CPU.
Definition: CaloGPUHybridClusterProcessor.h:102
CaloGPUHybridClusterProcessor::m_skipConversions
Gaudi::Property< bool > m_skipConversions
If true, both constant and event data conversion is skipped.
Definition: CaloGPUHybridClusterProcessor.h:178
CaloGPUHybridClusterProcessor::finalize
virtual StatusCode finalize() override
Definition: CaloGPUHybridClusterProcessor.cxx:562
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::allocate
void allocate(const size_t size)
Definition: CaloGPUHybridClusterProcessor.h:197
CaloGPUHybridClusterProcessor::ATLAS_THREAD_SAFE
CaloRecGPU::Helpers::separate_thread_holder< simple_GPU_pointer_holder > m_temporariesThreadedHolder ATLAS_THREAD_SAFE
A way to reduce allocations over multiple threads by keeping a cache of previously allocated objects ...
Definition: CaloGPUHybridClusterProcessor.h:249
CaloGPUHybridClusterProcessor::m_temporariesSize
size_t m_temporariesSize
The size of the temporary buffer to allocate for the GPU tools that will be called.
Definition: CaloGPUHybridClusterProcessor.h:257
CaloGPUHybridClusterProcessor::m_doMonitoring
Gaudi::Property< bool > m_doMonitoring
If true, uses the monitoring tool specified by m_monitorTool.
Definition: CaloGPUHybridClusterProcessor.h:125
CaloGPUHybridClusterProcessor::m_avgMuKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_avgMuKey
Event input: To get <mu> from Event Info.
Definition: CaloGPUHybridClusterProcessor.h:139
CaloGPUHybridClusterProcessor::m_writeTriggerSpecificInfo
Gaudi::Property< bool > m_writeTriggerSpecificInfo
If true, writes some trigger-specific decorations.
Definition: CaloGPUHybridClusterProcessor.h:143
CaloGPUHybridClusterProcessor::m_plotterTool
ToolHandle< ICaloClusterGPUPlotter > m_plotterTool
An optional plotter, for testing and/or debugging purposes.
Definition: CaloGPUHybridClusterProcessor.h:120
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::simple_GPU_pointer_holder
simple_GPU_pointer_holder(simple_GPU_pointer_holder &&other)
Definition: CaloGPUHybridClusterProcessor.h:210
SG::ReadHandleKey< CaloCellContainer >
CaloGPUHybridClusterProcessor::m_GPUoperations
ToolHandleArray< CaloClusterGPUProcessor > m_GPUoperations
Tools to be applied to the clusters on the GPU.
Definition: CaloGPUHybridClusterProcessor.h:96
CaloGPUHybridClusterProcessor::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: CaloGPUHybridClusterProcessor.cxx:179
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::~simple_GPU_pointer_holder
~simple_GPU_pointer_holder()
Definition: CaloGPUHybridClusterProcessor.h:223
CaloGPUHybridClusterProcessor::initialize_CUDA
virtual StatusCode initialize_CUDA() override
Initialization that invokes CUDA functions.
Definition: CaloGPUHybridClusterProcessor.cxx:141
CaloGPUTimed
Base class to provide some basic common infrastructure for timing measurements...
Definition: CaloGPUTimed.h:25
CaloGPUHybridClusterProcessor::m_monitoring1thr
Gaudi::Property< float > m_monitoring1thr
Definition: CaloGPUHybridClusterProcessor.h:127
CaloGPUHybridClusterProcessor::CaloGPUHybridClusterProcessor
CaloGPUHybridClusterProcessor(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloGPUHybridClusterProcessor.cxx:31
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CaloRecGPU::CUDA_Helpers::deallocate
void deallocate(void *address)
Deallocates address in GPU memory.
CaloGPUHybridClusterProcessor::m_doPlots
Gaudi::Property< bool > m_doPlots
If true, calls the plotter specified by m_plotterTool at every tool execution.
Definition: CaloGPUHybridClusterProcessor.h:114
CaloGPUHybridClusterProcessor::initialize_non_CUDA
virtual StatusCode initialize_non_CUDA() override
Initialization that does not invoke CUDA functions.
Definition: CaloGPUHybridClusterProcessor.cxx:40
CaloGPUCUDAInitialization::initialize
virtual StatusCode initialize()
Definition: CaloGPUCUDAInitialization.h:44
CaloGPUHybridClusterProcessor::m_monitoring2thr
Gaudi::Property< float > m_monitoring2thr
Definition: CaloGPUHybridClusterProcessor.h:128
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CaloGPUHybridClusterProcessor::m_noiseCDOKey
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
Definition: CaloGPUHybridClusterProcessor.h:132
CaloGPUHybridClusterProcessor::m_moniTool
ToolHandle< GenericMonitoringTool > m_moniTool
Monitoring tool.
Definition: CaloGPUHybridClusterProcessor.h:136
GenericMonitoringTool.h
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::simple_GPU_pointer_holder
simple_GPU_pointer_holder()
Definition: CaloGPUHybridClusterProcessor.h:205
CaloGPUHybridClusterProcessor::ATLAS_THREAD_SAFE
CaloRecGPU::Helpers::separate_thread_holder< CaloRecGPU::EventDataHolder > m_eventDataThreadedHolder ATLAS_THREAD_SAFE
A way to reduce allocations over multiple threads by keeping a cache of previously allocated objects ...
Definition: CaloGPUHybridClusterProcessor.h:184
CaloGPUHybridClusterProcessor::m_mutex
std::mutex m_mutex
This mutex is locked when sending the constant data on the first event to ensure thread safety.
Definition: CaloGPUHybridClusterProcessor.h:276
SG::WriteHandleKey< xAOD::CaloClusterContainer >
WriteDecorHandleKey.h
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::operator*
void * operator*()
Definition: CaloGPUHybridClusterProcessor.h:233
CaloGPUHybridClusterProcessor::ATLAS_THREAD_SAFE
CaloRecGPU::ConstantDataHolder m_constantData ATLAS_THREAD_SAFE
Constant data, common for all events and persisted throughout the run.
Definition: CaloGPUHybridClusterProcessor.h:264
CaloClusterGPUProcessor.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::get_pointer
void * get_pointer()
Definition: CaloGPUHybridClusterProcessor.h:238
CaloGPUHybridClusterProcessor::m_deferConstantDataToFirstEvent
Gaudi::Property< bool > m_deferConstantDataToFirstEvent
If true, the constant data is only converted and sent to the GPU on the first event,...
Definition: CaloGPUHybridClusterProcessor.h:173
CaloGPUHybridClusterProcessor::m_monitorCells
Gaudi::Property< bool > m_monitorCells
Definition: CaloGPUHybridClusterProcessor.h:126
CaloGPUCUDAInitialization
Base class to provide some basic common infrastructure for initializing CUDA only at the right place ...
Definition: CaloGPUCUDAInitialization.h:28
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::operator=
simple_GPU_pointer_holder & operator=(const simple_GPU_pointer_holder &)=delete
CaloGPUHybridClusterProcessor
Algorithm to reconstruct CaloCluster objects with GPU acceleration, providing interoperability for ca...
Definition: CaloGPUHybridClusterProcessor.h:52
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
CaloGPUHybridClusterProcessor::initialize
virtual StatusCode initialize() override
Definition: CaloGPUHybridClusterProcessor.h:58
CaloGPUHybridClusterProcessor::m_constantDataSent
std::atomic< bool > m_constantDataSent
A flag to signal that the constant data has been adequately sent to the GPU.
Definition: CaloGPUHybridClusterProcessor.h:270
CaloClusterGPUTransformers.h
CaloGPUHybridClusterProcessor::m_clusterCellLinkOutput
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_clusterCellLinkOutput
The name of the key in StoreGate for the output CaloClusterCellLinkContainer.
Definition: CaloGPUHybridClusterProcessor.h:167
AthReentrantAlgorithm.h
CaloRecGPU::CUDA_Helpers::allocate
void * allocate(const size_t num)
Allocates and returns the address of num bytes from GPU memory.
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::simple_GPU_pointer_holder
simple_GPU_pointer_holder(const simple_GPU_pointer_holder &)=delete
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CaloGPUHybridClusterProcessor::m_cellsKey
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
vector of names of the cell containers to use as input.
Definition: CaloGPUHybridClusterProcessor.h:159
CaloRecGPU::Helpers::separate_thread_holder< CaloRecGPU::EventDataHolder >
CaloNoise.h
CaloClusterCollectionProcessor.h
Base class for cluster processing tools called from CaloClusterMaker.
CaloGPUHybridClusterProcessor::m_postGPUoperations
ToolHandleArray< CaloClusterCollectionProcessor > m_postGPUoperations
Tools to be applied to the clusters after returning from the GPU.
Definition: CaloGPUHybridClusterProcessor.h:108
SG::ReadCondHandleKey< CaloNoise >
CaloGPUHybridClusterProcessor::m_mDecor_ncells
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_mDecor_ncells
Key to the handle for writing the number of cells as a decoration.
Definition: CaloGPUHybridClusterProcessor.h:147
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder
A simple RAII wrapper to ensure proper allocation and deallocation of GPU memory in a void * for the ...
Definition: CaloGPUHybridClusterProcessor.h:191
CaloGPUHybridClusterProcessor::simple_GPU_pointer_holder::m_ptr
void * m_ptr
Definition: CaloGPUHybridClusterProcessor.h:193
CaloGPUHybridClusterProcessor::~CaloGPUHybridClusterProcessor
virtual ~CaloGPUHybridClusterProcessor() override=default
CaloClusterContainer.h
CaloRecGPU::ConstantDataHolder
Definition: DataHolders.h:19
ReadDecorHandle.h
Handle class for reading a decoration on an object.
CaloGPUTimed.h
CaloGPUHybridClusterProcessor::m_numPreAllocatedGPUData
Gaudi::Property< size_t > m_numPreAllocatedGPUData
Number of events for which to pre-allocate space on GPU memory (should ideally be set to the expected...
Definition: CaloGPUHybridClusterProcessor.h:154
CaloGPUHybridClusterProcessor::m_preGPUoperations
ToolHandleArray< CaloClusterCollectionProcessor > m_preGPUoperations
Tools to be applied to the clusters before being sent to the GPU for processing.
Definition: CaloGPUHybridClusterProcessor.h:83
SG::ReadDecorHandleKey
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Definition: StoreGate/StoreGate/ReadDecorHandleKey.h:85
checker_macros.h
Define macros for attributes used to control the static checker.
DataHolders.h
CaloGPUHybridClusterProcessor::m_clusterOutput
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clusterOutput
The name of the key in StoreGate for the output CaloClusterContainer.
Definition: CaloGPUHybridClusterProcessor.h:163
CaloGPUCUDAInitialization.h
CaloGPUHybridClusterProcessor::m_transformConstantData
ToolHandle< ICaloClusterGPUConstantTransformer > m_transformConstantData
The tool that will convert the constant data from the CPU to the GPU.
Definition: CaloGPUHybridClusterProcessor.h:77
CaloGPUHybridClusterProcessor::m_transformForGPU
ToolHandle< ICaloClusterGPUInputTransformer > m_transformForGPU
The tool that will actually convert the data from the CPU to the GPU.
Definition: CaloGPUHybridClusterProcessor.h:90