ATLAS Offline Software
Loading...
Searching...
No Matches
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"
13
15
22
24
27
29
30#include <string>
31#include <mutex>
32#include <atomic>
33#include <utility>
34
49
51{
52 public:
53
54 CaloGPUHybridClusterProcessor(const std::string & name, ISvcLocator * pSvcLocator);
55 virtual ~CaloGPUHybridClusterProcessor() override = default;
56
57 virtual StatusCode initialize() override
58 {
60 }
61
62 virtual StatusCode initialize_non_CUDA() override;
63
64 virtual StatusCode initialize_CUDA() override;
65
66 virtual StatusCode execute(const EventContext & ctx) const override;
67 virtual StatusCode finalize() override;
68
69 private:
70
71
76 ToolHandle<ICaloClusterGPUConstantTransformer> m_transformConstantData{this, "ConstantDataToGPUTool", "", "Tool for transforming the constant data and sending it to the GPU"};
77
82 ToolHandleArray<CaloClusterCollectionProcessor> m_preGPUoperations{this, "BeforeGPUTools", {}, "Tools to be applied to the clusters on the CPU before processing them on the GPU"};
83
84
89 ToolHandle<ICaloClusterGPUInputTransformer> m_transformForGPU{this, "EventDataToGPUTool", "", "Tool for transforming the event data and sending it to the GPU"};
90
95 ToolHandleArray<CaloClusterGPUProcessor> m_GPUoperations{this, "GPUTools", {}, "Tools to be applied to the clusters on the GPU"};
96
101 ToolHandle<ICaloClusterGPUOutputTransformer> m_transformBackToCPU{this, "GPUToEventDataTool", {}, "Tool for getting the data from the GPU back to the CPU Athena data structures"};
102
107 ToolHandleArray<CaloClusterCollectionProcessor> m_postGPUoperations{this, "AfterGPUTools", {}, "Tools to be applied to the clusters on the CPU after returning from the GPU"};
108
109
113 Gaudi::Property<bool> m_doPlots{this, "DoPlots", false, "Do plots based on the plotter tool optionally provided."};
114
119 ToolHandle<ICaloClusterGPUPlotter> m_plotterTool{this, "PlotterTool", "", "An optional plotter, for testing and/or debugging purposes"};
120
123 Gaudi::Property<bool> m_writeTriggerSpecificInfo{this, "WriteTriggerSpecificInfo", false, "Write some trigger-specific decorations and use the trigger auxiliary container."};
124
127 SG::WriteDecorHandleKey<xAOD::CaloClusterContainer> m_mDecor_ncells {this, "Decor_ncells", "nCells", "Decorator containing the number of cells associated to a cluster"};
128
134 Gaudi::Property<size_t> m_numPreAllocatedGPUData{this, "NumPreAllocatedDataHolders", 0, "Number of event data holders to pre-allocate on GPU memory"};
135
138 SG::WriteHandleKey<xAOD::CaloClusterContainer> m_clusterOutput {this, "ClustersOutputName", "", "The name of the key in StoreGate for the output CaloClusterContainer"};
139
142 SG::WriteHandleKey<CaloClusterCellLinkContainer> m_clusterCellLinkOutput{this, "ClusterCellLinksOutputName", "", "The name of the key in StoreGate for the output CaloClusterCellLinkContainer"};
143
148 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)?"};
149
150
153 Gaudi::Property<bool> m_skipConversions {this, "SkipConversions", false, "If true, skip converting CPU to GPU data (useful if only instanting CPU tools)"};
154
160
166 {
167 private:
168 void * m_ptr;
169
170 public:
171
172 void allocate(const size_t size)
173 {
174 if (m_ptr == nullptr && size > 0)
175 {
177 }
178 }
179
181 m_ptr(nullptr)
182 {
183 }
186 {
187 m_ptr = other.m_ptr;
188 other.m_ptr = nullptr;
189 }
191
193 {
194 std::swap(m_ptr, other.m_ptr);
195 return (*this);
196 }
197
199 {
200 if (m_ptr != nullptr)
201 //This check might still be needed to ensure the code behaves on non-CUDA enabled platforms
202 //where some destructors might still be called with nullptr.
203 {
205 }
206 }
207
208 void * operator* ()
209 {
210 return m_ptr;
211 }
212
213 void * get_pointer()
214 {
215 return m_ptr;
216 }
217
218 };
219
225
233
238
240
244
245 mutable std::atomic<bool> m_constantDataSent;
246
247
251 mutable std::mutex m_mutex;
252
253};
254
255#endif //CALORECGPU_CALOGPUHYBRIDCLUSTERPROCESSOR_H
Base class for cluster processing tools called from CaloClusterMaker.
Handle class for reading a decoration on an object.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Define macros for attributes used to control the static checker.
An algorithm that can be simultaneously executed in multiple threads.
Base class to provide some basic common infrastructure for initializing CUDA only at the right place ...
std::atomic< bool > m_constantDataSent
A flag to signal that the constant data has been adequately sent to the GPU.
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...
virtual StatusCode initialize_non_CUDA() override
Initialization that does not invoke CUDA functions.
ToolHandle< ICaloClusterGPUConstantTransformer > m_transformConstantData
The tool that will convert the constant data from the CPU to the GPU.
ToolHandle< ICaloClusterGPUInputTransformer > m_transformForGPU
The tool that will actually convert the data from the CPU to the GPU.
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clusterOutput
The name of the key in StoreGate for the output CaloClusterContainer.
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_mDecor_ncells
Key to the handle for writing the number of cells as a decoration.
ToolHandle< ICaloClusterGPUPlotter > m_plotterTool
An optional plotter, for testing and/or debugging purposes.
Gaudi::Property< bool > m_skipConversions
If true, both constant and event data conversion is skipped.
size_t m_temporariesSize
The size of the temporary buffer to allocate for the GPU tools that will be called.
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_clusterCellLinkOutput
The name of the key in StoreGate for the output CaloClusterCellLinkContainer.
virtual StatusCode initialize_CUDA() override
Initialization that invokes CUDA functions.
ToolHandleArray< CaloClusterGPUProcessor > m_GPUoperations
Tools to be applied to the clusters on the GPU.
Gaudi::Property< bool > m_doPlots
If true, calls the plotter specified by m_plotterTool at every tool execution.
std::mutex m_mutex
This mutex is locked when sending the constant data on the first event to ensure thread safety.
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< bool > m_writeTriggerSpecificInfo
If true, writes some trigger-specific decorations.
ToolHandle< ICaloClusterGPUOutputTransformer > m_transformBackToCPU
The tool that will convert the data from the GPU back to the CPU.
virtual StatusCode initialize() override
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 ...
ToolHandleArray< CaloClusterCollectionProcessor > m_preGPUoperations
Tools to be applied to the clusters before being sent to the GPU for processing.
virtual ~CaloGPUHybridClusterProcessor() override=default
Gaudi::Property< bool > m_deferConstantDataToFirstEvent
If true, the constant data is only converted and sent to the GPU on the first event,...
ToolHandleArray< CaloClusterCollectionProcessor > m_postGPUoperations
Tools to be applied to the clusters after returning from the GPU.
CaloGPUHybridClusterProcessor(const std::string &name, ISvcLocator *pSvcLocator)
CaloGPUTimed(T *ptr)
Holds CPU and GPU versions of the geometry and cell noise information, which are assumed to be consta...
Definition DataHolders.h:27
Manages objects of type T in a thread-safe way, ensuring that there's an object available for each se...
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
void deallocate(void *address)
Deallocates address in GPU memory.
void * allocate(const size_t num)
Allocates and returns the address of num bytes from GPU memory.
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
simple_GPU_pointer_holder(const simple_GPU_pointer_holder &)=delete
simple_GPU_pointer_holder & operator=(const simple_GPU_pointer_holder &)=delete