26#include "boost/chrono/chrono.hpp"
27#include "boost/chrono/thread_clock.hpp"
51 bool any_failed =
false;
53 auto retrieve_and_report = [&](
auto & var,
const auto &
type,
bool & falsify_if_empty)
57 falsify_if_empty =
false;
60 else if (var.retrieve().isFailure())
105 return StatusCode::FAILURE;
122 return StatusCode::SUCCESS;
160 return StatusCode::SUCCESS;
170 ATH_CHECK( cluster_collection.
record (std::make_unique<xAOD::CaloClusterContainer>(), std::make_unique<xAOD::CaloClusterTrigAuxContainer> () ));
200 ATH_MSG_ERROR(
"Could not get valid Event Data Holder! Event: " << ctx.evt() );
201 return StatusCode::FAILURE;
213 if (!temporaries_data_ptr_holder)
215 ATH_MSG_ERROR(
"temporaries_data_ptr_holder is null in CaloGPUHybridClusterProcessor::execute" );
216 return StatusCode::FAILURE;
223 ATH_MSG_ERROR(
"Could not get valid temporary buffer holder! Event: " << ctx.evt() );
224 return StatusCode::FAILURE;
230 using clock_type = boost::chrono::thread_clock;
231 auto time_cast = [](
const auto & before,
const auto & after)
233 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
236 std::vector<size_t> times;
238 size_t plot_time = 0;
245 times.reserve(time_size);
250 auto t1 = clock_type::now();
252 auto t2 = clock_type::now();
255 plot_time += time_cast(t1, t2);
261 auto t1 = clock_type::now();
262 ATH_CHECK( pre_GPU_tool->execute(ctx, cluster_collection_ptr) );
263 auto t2 = clock_type::now();
266 times.push_back(time_cast(t1, t2));
270 auto t3 = clock_type::now();
272 auto t4 = clock_type::now();
275 plot_time += time_cast(t3, t4);
282 auto t3 = clock_type::now();
284 auto t4 = clock_type::now();
287 times.push_back(time_cast(t3, t4));
293 auto t1 = clock_type::now();
295 auto t2 = clock_type::now();
298 plot_time += time_cast(t1, t2);
304 auto t5 = clock_type::now();
305 ATH_CHECK( GPU_tool->execute(ctx, constant_data_holder, *event_data_ptr, temporaries_data_ptr_holder->
get_pointer()) );
306 auto t6 = clock_type::now();
309 times.push_back(time_cast(t5, t6));
313 auto t3 = clock_type::now();
314 ATH_CHECK(
m_plotterTool->update_plots(ctx, constant_data_holder, cluster_collection_ptr, *event_data_ptr, GPU_tool.get()) );
315 auto t4 = clock_type::now();
318 plot_time += time_cast(t3, t4);
325 auto t7 = clock_type::now();
327 auto t8 = clock_type::now();
330 times.push_back(time_cast(t7, t8));
336 auto t1 = clock_type::now();
338 auto t2 = clock_type::now();
341 plot_time += time_cast(t1, t2);
347 auto t9 = clock_type::now();
348 ATH_CHECK( post_GPU_tool->execute(ctx, cluster_collection_ptr) );
349 auto t10 = clock_type::now();
352 times.push_back(time_cast(t9, t10));
356 auto t3 = clock_type::now();
358 auto t4 = clock_type::now();
361 plot_time += time_cast(t3, t4);
368 auto t1 = clock_type::now();
370 auto t2 = clock_type::now();
373 plot_time += time_cast(t1, t2);
386 decor_handle(*cl) = 0;
390 decor_handle(*cl) = cell_links->
size();
395 ATH_MSG_DEBUG(
"Created cluster container with " << cluster_collection->size() <<
" clusters");
405 times.push_back(plot_time);
410 return StatusCode::SUCCESS;
417 std::string header_string;
419 auto add_name_to_string = [&](
const auto & obj)
421 std::string rep = obj->name();
422 std::replace(rep.begin(), rep.end(),
' ',
'_');
423 header_string += rep +
" ";
428 add_name_to_string(pre_GPU_tool);
438 add_name_to_string(GPU_tool);
448 add_name_to_string(post_GPU_tool);
464 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
Helpers for checking error return status codes and reporting errors.
Header file to be included by clients of the Monitored infrastructure.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
Bookkeeping of cells that make up a cluster Simplified replacement for CaloCellLink,...
size_t size() const
size method
static StatusCode AddContainerWriteHandle(SG::WriteHandle< xAOD::CaloClusterContainer > &clusColl)
Creates a new xAOD::CaloClusterContainer in the given WriteHandle + CaloClusterAuxContainer and recor...
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
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.
virtual StatusCode finalize() override
ToolHandle< ICaloClusterGPUOutputTransformer > m_transformBackToCPU
The tool that will convert the data from the GPU back to the CPU.
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.
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)
Gaudi::Property< bool > m_measureTimes
If true, times are recorded to the file given by m_timeFileName.
void print_times(const std::string &header, const size_t time_size) const
void record_times(const size_t event_num, const std::vector< size_t > ×) const
Holds CPU and GPU versions of the geometry and cell noise information, which are assumed to be consta...
Holds the mutable per-event information (clusters and cells) and provides utilities to convert betwee...
void allocate(const bool also_GPU=true)
const T * get(size_type n) const
Access an element, as an rvalue.
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
A simple RAII wrapper to ensure proper allocation and deallocation of GPU memory in a void * for the ...
void allocate(const size_t size)