ATLAS Offline Software
Loading...
Searching...
No Matches
GPUClusterSorter Class Reference

Sorts clusters by ET (with possible cut) and creates the list of cells per cluster. More...

#include <GPUClusterSorter.h>

Inheritance diagram for GPUClusterSorter:
Collaboration diagram for GPUClusterSorter:

Public Member Functions

 GPUClusterSorter (const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode initialize () override
virtual StatusCode initialize_non_CUDA () override
 Initialization that does not invoke CUDA functions.
virtual StatusCode initialize_CUDA () override
 Initialization that invokes CUDA functions.
virtual StatusCode execute (const EventContext &ctx, const CaloRecGPU::ConstantDataHolder &constant_data, CaloRecGPU::EventDataHolder &event_data, void *temporary_buffer) const override
virtual StatusCode finalize () override
virtual ~GPUClusterSorter ()=default
void handle (const Incident &incident) override

Protected Member Functions

void record_times (const size_t event_num, const std::vector< size_t > &times) const
template<class ... Args>
void record_times (const size_t event_num, const size_t &value) const
template<class ... Args>
void record_times (const size_t event_num, const size_t &value, Args &&... args) const
void print_times (const std::string &header, const size_t time_size) const

Protected Attributes

std::shared_mutex m_timeMutex
 Mutex that is locked when recording times.
std::vector< size_t > m_times ATLAS_THREAD_SAFE
 Vector to hold execution times to be recorded if necessary.
std::vector< size_t > m_eventNumbers ATLAS_THREAD_SAFE
 Vector to hold the event numbers to be recorded if necessary.
Gaudi::Property< bool > m_measureTimes
 If true, times are recorded to the file given by m_timeFileName.
Gaudi::Property< std::string > m_timeFileName
 File to which times should be saved.

Private Member Functions

void record_times_helper (const size_t) const
template<class Arg>
void record_times_helper (const size_t index, Arg &&arg) const
template<class ... Args>
void record_times_helper (size_t index, Args &&... args) const

Private Attributes

Gaudi::Property< bool > m_cutClustersInAbsE {this, "ClusterCutsInAbsEt", true, "Do cluster cuts in Abs Et instead of Et"}
 if set to true cluster cuts are on \(|E|_\perp\), if false on \(E_\perp\).
Gaudi::Property< float > m_clusterETThreshold {this, "ClusterEtorAbsEtCut", 0.*CLHEP::MeV, "Cluster E_t or Abs E_t cut"}
 \(E_\perp\) cut on the clusters.
ServiceHandle< IGPUKernelSizeOptimizerSvcm_kernelSizeOptimizer { this, "KernelSizeOptimizer", "GPUKernelSizeOptimizerSvc", "CUDA kernel size optimization service." }
 Handle to the CUDA kernel block and grid size optimization service.

Detailed Description

Sorts clusters by ET (with possible cut) and creates the list of cells per cluster.

Author
Nuno Fernandes nuno..nosp@m.dos..nosp@m.santo.nosp@m.s.fe.nosp@m.rnand.nosp@m.es@c.nosp@m.ern.c.nosp@m.h
Date
26 October 2025

Definition at line 33 of file GPUClusterSorter.h.

Constructor & Destructor Documentation

◆ GPUClusterSorter()

GPUClusterSorter::GPUClusterSorter ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 16 of file GPUClusterSorter.cxx.

16 :
17 base_class(type, name, parent),
18 CaloGPUTimed(this)
19{
20}
CaloGPUTimed(T *ptr)

◆ ~GPUClusterSorter()

virtual GPUClusterSorter::~GPUClusterSorter ( )
virtualdefault

Member Function Documentation

◆ execute()

StatusCode GPUClusterSorter::execute ( const EventContext & ctx,
const CaloRecGPU::ConstantDataHolder & constant_data,
CaloRecGPU::EventDataHolder & event_data,
void * temporary_buffer ) const
overridevirtual

Definition at line 34 of file GPUClusterSorter.cxx.

36{
37 using clock_type = boost::chrono::thread_clock;
38 auto time_cast = [](const auto & before, const auto & after)
39 {
40 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
41 };
42
43 const auto start = clock_type::now();
44
45 const auto before_properties = clock_type::now();
46
48
49 const auto before_sort = clock_type::now();
50
51 sortClusters(event_data, constant_data, *(m_kernelSizeOptimizer.get()), m_measureTimes);
52
53 const auto before_finalize = clock_type::now();
54
55 finalizeClusterAssignment(event_data, constant_data, *(m_kernelSizeOptimizer.get()), m_measureTimes);
56
57 const auto end = clock_type::now();
58
60 {
61 record_times(ctx.evt(),
62 time_cast(start, before_properties),
63 time_cast(before_properties, before_sort),
64 time_cast(before_sort, before_finalize),
65 time_cast(before_finalize, end)
66 );
67 }
68
69
70 return StatusCode::SUCCESS;
71
72}
Gaudi::Property< bool > m_measureTimes
If true, times are recorded to the file given by m_timeFileName.
void record_times(const size_t event_num, const std::vector< size_t > &times) const
Gaudi::Property< float > m_clusterETThreshold
cut on the clusters.
Gaudi::Property< bool > m_cutClustersInAbsE
if set to true cluster cuts are on , if false on .
ServiceHandle< IGPUKernelSizeOptimizerSvc > m_kernelSizeOptimizer
Handle to the CUDA kernel block and grid size optimization service.
void sortClusters(CaloRecGPU::EventDataHolder &holder, const CaloRecGPU::ConstantDataHolder &instance_data, const IGPUKernelSizeOptimizer &optimizer, const bool synchronize=false, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream_to_use={})
void initialPropertiesCalculation(CaloRecGPU::EventDataHolder &holder, const CaloRecGPU::ConstantDataHolder &instance_data, const IGPUKernelSizeOptimizer &optimizer, const bool synchronize=false, const bool cut_in_absolute_ET=true, const float absolute_ET_threshold=-1, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream_to_use={})
void finalizeClusterAssignment(CaloRecGPU::EventDataHolder &holder, const CaloRecGPU::ConstantDataHolder &instance_data, const IGPUKernelSizeOptimizer &optimizer, const bool synchronize=false, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream_to_use={})

◆ finalize()

StatusCode GPUClusterSorter::finalize ( )
overridevirtual

Definition at line 74 of file GPUClusterSorter.cxx.

75{
77 {
78 print_times("Preprocessing Calculating_ET Sorting_Clusters Finalizing_Clusters", 4);
79 }
80 return StatusCode::SUCCESS;
81}
void print_times(const std::string &header, const size_t time_size) const

◆ handle()

void CaloGPUCUDAInitialization::handle ( const Incident & incident)
inlineoverrideinherited

Definition at line 66 of file CaloGPUCUDAInitialization.h.

67 {
68 const bool is_multiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
69 if (is_multiprocess && incident.type() == AthenaInterprocess::UpdateAfterFork::type())
70 {
71 if (!this->initialize_CUDA().isSuccess())
72 {
73 throw GaudiException("Failed to perform the CUDA initialization!",
74 "CaloGPUCUDAInitialization::handle",
75 StatusCode::FAILURE);
76 }
77 }
78 }
static const std::string & type()
Incident type.
Definition Incidents.h:49
virtual StatusCode initialize_CUDA()
Initialization that invokes CUDA functions.

◆ initialize()

virtual StatusCode GPUClusterSorter::initialize ( )
inlineoverridevirtual

Reimplemented from CaloGPUCUDAInitialization.

Definition at line 40 of file GPUClusterSorter.h.

◆ initialize_CUDA()

StatusCode GPUClusterSorter::initialize_CUDA ( )
overridevirtual

Initialization that invokes CUDA functions.

Reimplemented from CaloGPUCUDAInitialization.

Definition at line 28 of file GPUClusterSorter.cxx.

29{
31 return StatusCode::SUCCESS;
32}
void register_kernels(IGPUKernelSizeOptimizer &optimizer)

◆ initialize_non_CUDA()

StatusCode GPUClusterSorter::initialize_non_CUDA ( )
overridevirtual

Initialization that does not invoke CUDA functions.

Reimplemented from CaloGPUCUDAInitialization.

Definition at line 22 of file GPUClusterSorter.cxx.

23{
24 ATH_CHECK( m_kernelSizeOptimizer.retrieve() );
25 return StatusCode::SUCCESS;
26}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ print_times()

void CaloGPUTimed::print_times ( const std::string & header,
const size_t time_size ) const
inlineprotectedinherited

Definition at line 143 of file CaloGPUTimed.h.

144 {
145 std::shared_lock<std::shared_mutex> lock(m_timeMutex);
146
147 if (m_timeFileName.size() == 0)
148 {
149 return;
150 }
151
152 std::vector<size_t> indices(m_eventNumbers.size());
153
154 std::iota(indices.begin(), indices.end(), 0);
155 std::sort(indices.begin(), indices.end(), [&](size_t a, size_t b)
156 {
157 return m_eventNumbers[a] < m_eventNumbers[b];
158 }
159 );
160 std::ofstream out(m_timeFileName);
161
162 out << "Event_Number Total " << header << "\n";
163
164 for (const size_t idx : indices)
165 {
166 out << m_eventNumbers[idx] << " ";
167
168 size_t total = 0;
169
170 for (size_t i = 0; i < time_size; ++i)
171 {
172 total += m_times[idx * time_size + i];
173 }
174
175 out << total << " ";
176
177 for (size_t i = 0; i < time_size; ++i)
178 {
179 out << m_times[idx * time_size + i] << " ";
180 }
181 out << "\n";
182 }
183
184 out << std::endl;
185
186 out.close();
187 }
static Double_t a
Gaudi::Property< std::string > m_timeFileName
File to which times should be saved.
std::shared_mutex m_timeMutex
Mutex that is locked when recording times.
std::pair< long int, long int > indices
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ record_times() [1/3]

template<class ... Args>
void CaloGPUTimed::record_times ( const size_t event_num,
const size_t & value ) const
inlineprotectedinherited

Definition at line 105 of file CaloGPUTimed.h.

106 {
107 const size_t time_size = 1;
108
109 size_t old_size;
110
111 {
112 std::unique_lock<std::shared_mutex> lock(m_timeMutex);
113 old_size = m_times.size();
114 m_times.resize(old_size + time_size);
115 m_eventNumbers.push_back(event_num);
116 }
117 {
118 std::shared_lock<std::shared_mutex> lock(m_timeMutex);
119 record_times_helper(old_size, value);
120 }
121 }
void record_times_helper(const size_t) const

◆ record_times() [2/3]

template<class ... Args>
void CaloGPUTimed::record_times ( const size_t event_num,
const size_t & value,
Args &&... args ) const
inlineprotectedinherited

Definition at line 124 of file CaloGPUTimed.h.

125 {
126 const size_t time_size = sizeof...(args) + 1;
127
128 size_t old_size;
129
130 {
131 std::unique_lock<std::shared_mutex> lock(m_timeMutex);
132 old_size = m_times.size();
133 m_times.resize(old_size + time_size);
134 m_eventNumbers.push_back(event_num);
135 }
136 {
137 std::shared_lock<std::shared_mutex> lock(m_timeMutex);
138 record_times_helper(old_size, value, std::forward<Args>(args)...);
139 }
140
141 }

◆ record_times() [3/3]

void CaloGPUTimed::record_times ( const size_t event_num,
const std::vector< size_t > & times ) const
inlineprotectedinherited

Definition at line 86 of file CaloGPUTimed.h.

87 {
88 size_t old_size;
89 {
90 std::unique_lock<std::shared_mutex> lock(m_timeMutex);
91 old_size = m_times.size();
92 m_times.resize(old_size + times.size());
93 m_eventNumbers.push_back(event_num);
94 }
95 {
96 std::shared_lock<std::shared_mutex> lock(m_timeMutex);
97 for (size_t i = 0; i < times.size(); ++i)
98 {
99 m_times[old_size + i] = times[i];
100 }
101 }
102 }

◆ record_times_helper() [1/3]

template<class Arg>
void CaloGPUTimed::record_times_helper ( const size_t index,
Arg && arg ) const
inlineprivateinherited

Definition at line 70 of file CaloGPUTimed.h.

71 {
72 // coverity[missing_lock]
73 m_times[index] = std::forward<Arg>(arg);
74
75 //This is called within a function that holds the lock itself.
76 }
str index
Definition DeMoScan.py:362

◆ record_times_helper() [2/3]

void CaloGPUTimed::record_times_helper ( const size_t ) const
inlineprivateinherited

Definition at line 64 of file CaloGPUTimed.h.

65 {
66 //Do nothing
67 }

◆ record_times_helper() [3/3]

template<class ... Args>
void CaloGPUTimed::record_times_helper ( size_t index,
Args &&... args ) const
inlineprivateinherited

Definition at line 79 of file CaloGPUTimed.h.

80 {
81 (record_times_helper(index++, std::forward<Args>(args)), ...);
82 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/2]

std::vector<size_t> m_times CaloGPUTimed::ATLAS_THREAD_SAFE
mutableprotectedinherited

Vector to hold execution times to be recorded if necessary.

Definition at line 35 of file CaloGPUTimed.h.

◆ ATLAS_THREAD_SAFE [2/2]

std::vector<size_t> m_eventNumbers CaloGPUTimed::ATLAS_THREAD_SAFE
mutableprotectedinherited

Vector to hold the event numbers to be recorded if necessary.

Definition at line 40 of file CaloGPUTimed.h.

◆ m_clusterETThreshold

Gaudi::Property<float> GPUClusterSorter::m_clusterETThreshold {this, "ClusterEtorAbsEtCut", 0.*CLHEP::MeV, "Cluster E_t or Abs E_t cut"}
private

\(E_\perp\) cut on the clusters.

The clusters have to pass this cut (which is on \(E_\perp\) or \(|E|_\perp\) of the cluster depending on the above switch) in order to be inserted into the CaloClusterContainer.

Definition at line 73 of file GPUClusterSorter.h.

73{this, "ClusterEtorAbsEtCut", 0.*CLHEP::MeV, "Cluster E_t or Abs E_t cut"};

◆ m_cutClustersInAbsE

Gaudi::Property<bool> GPUClusterSorter::m_cutClustersInAbsE {this, "ClusterCutsInAbsEt", true, "Do cluster cuts in Abs Et instead of Et"}
private

if set to true cluster cuts are on \(|E|_\perp\), if false on \(E_\perp\).

Default is true.

Definition at line 64 of file GPUClusterSorter.h.

64{this, "ClusterCutsInAbsEt", true, "Do cluster cuts in Abs Et instead of Et"};

◆ m_kernelSizeOptimizer

ServiceHandle<IGPUKernelSizeOptimizerSvc> GPUClusterSorter::m_kernelSizeOptimizer { this, "KernelSizeOptimizer", "GPUKernelSizeOptimizerSvc", "CUDA kernel size optimization service." }
private

Handle to the CUDA kernel block and grid size optimization service.

Definition at line 76 of file GPUClusterSorter.h.

76{ this, "KernelSizeOptimizer", "GPUKernelSizeOptimizerSvc", "CUDA kernel size optimization service." };

◆ m_measureTimes

Gaudi::Property<bool> CaloGPUTimed::m_measureTimes
protectedinherited

If true, times are recorded to the file given by m_timeFileName.

Defaults to false.

Definition at line 46 of file CaloGPUTimed.h.

◆ m_timeFileName

Gaudi::Property<std::string> CaloGPUTimed::m_timeFileName
protectedinherited

File to which times should be saved.

Definition at line 50 of file CaloGPUTimed.h.

◆ m_timeMutex

std::shared_mutex CaloGPUTimed::m_timeMutex
mutableprotectedinherited

Mutex that is locked when recording times.

Definition at line 32 of file CaloGPUTimed.h.


The documentation for this class was generated from the following files: