ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaExamples
AthExHIP
src
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
15
#include "
AthenaBaseComps/AthCheckMacros.h
"
16
#include "
AthenaBaseComps/AthMessaging.h
"
17
#include "
AthenaInterprocess/Incidents.h
"
18
19
20
namespace
AthHIPExamples
{
26
27
class
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
{
51
ATH_CHECK
(this->
initialize_global
());
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
{
62
ATH_CHECK
(this->
initialize_worker
());
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
AthCheckMacros.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
AthMessaging.h
Incidents.h
AthHIPExamples::DeviceStateHandler
Base class to provide common infrastructure for handling multiprocess state transitions for GPU.
Definition
DeviceStateHandler.h:28
AthHIPExamples::DeviceStateHandler::stop
virtual StatusCode stop()
Definition
DeviceStateHandler.h:68
AthHIPExamples::DeviceStateHandler::m_is_child
bool m_is_child
Definition
DeviceStateHandler.h:82
AthHIPExamples::DeviceStateHandler::stop_worker
virtual StatusCode stop_worker()
clean up
Definition
DeviceStateHandler.h:44
AthHIPExamples::DeviceStateHandler::initialize_global
virtual StatusCode initialize_global()
Glocal initialization.
Definition
DeviceStateHandler.h:32
AthHIPExamples::DeviceStateHandler::initialize
virtual StatusCode initialize()
Definition
DeviceStateHandler.h:49
AthHIPExamples::DeviceStateHandler::~DeviceStateHandler
virtual ~DeviceStateHandler()=default
AthHIPExamples::DeviceStateHandler::initialize_worker
virtual StatusCode initialize_worker()
Initialization per process.
Definition
DeviceStateHandler.h:38
AthHIPExamples::DeviceStateHandler::handle
void handle(const Incident &incident) override
Definition
DeviceStateHandler.h:86
AthenaInterprocess::UpdateAfterFork::type
static const std::string & type()
Incident type.
Definition
Incidents.h:49
ServiceHandle
Definition
ClusterMakerTool.h:36
AthHIPExamples
Definition
DeviceStateHandler.h:20
Generated on
for ATLAS Offline Software by
1.17.0