ATLAS Offline Software
Loading...
Searching...
No Matches
DeviceStateHandler.h
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3//
4// Dear emacs, this is -*- c++ -*-
5//
6
7#ifndef ATHEXHIP_HIPSTATEHANDLER_H
8#define ATHEXHIP_HIPSTATEHANDLER_H
9
10#include "GaudiKernel/IIncidentListener.h"
11#include "GaudiKernel/IIncidentSvc.h"
12#include "GaudiKernel/ConcurrencyFlags.h"
13#include "GaudiKernel/ServiceHandle.h"
14
18
19
26
27class DeviceStateHandler : virtual public ::IIncidentListener
28{
29 protected:
30
32 virtual StatusCode initialize_global()
33 {
34 return StatusCode::SUCCESS;
35 }
36
38 virtual StatusCode initialize_worker()
39 {
40 return StatusCode::SUCCESS;
41 }
42
44 virtual StatusCode stop_worker()
45 {
46 return StatusCode::SUCCESS;
47 }
48
49 virtual StatusCode initialize()
50 {
52
53 const bool is_multiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
54
55 if (is_multiprocess)
56 {
57 ServiceHandle<IIncidentSvc> incidentSvc("IncidentSvc","DeviceStateHandler");
58 incidentSvc->addListener(this, AthenaInterprocess::UpdateAfterFork::type());
59 }
60 else
61 {
63 }
64
65 return StatusCode::SUCCESS;
66 }
67
68 virtual StatusCode stop() {
69 const bool is_multiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
70
71 if (!is_multiprocess) {
72 ATH_CHECK(this->stop_worker());
73 } else {
74 if (m_is_child){
75 ATH_CHECK(this->stop_worker());
76 }
77 }
78
79 return StatusCode::SUCCESS;
80 }
81
82 bool m_is_child = false;
83
84 public:
85
86 void handle(const Incident & incident) override
87 {
88 const bool is_multiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
89 if (is_multiprocess && incident.type() == AthenaInterprocess::UpdateAfterFork::type())
90 {
91 m_is_child = true;
92 if (!this->initialize_worker().isSuccess())
93 {
94 throw GaudiException("Failed to initialize the device setup!",
95 "DeviceStateHandler::handle",
96 StatusCode::FAILURE);
97 }
98 }
99 }
100
101 virtual ~DeviceStateHandler() = default;
102
103};
104
105} // namespace AthHIPExamples
106
107#endif //ATHEXHIP_HIPSTATEHANDLER_H
#define ATH_CHECK
Evaluate an expression and check for errors.
Base class to provide common infrastructure for handling multiprocess state transitions for GPU.
virtual StatusCode stop_worker()
clean up
virtual StatusCode initialize_global()
Glocal initialization.
virtual ~DeviceStateHandler()=default
virtual StatusCode initialize_worker()
Initialization per process.
void handle(const Incident &incident) override
static const std::string & type()
Incident type.
Definition Incidents.h:49