ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthCUDA
AthCUDAServices
src
GPUSystemInfoSvc.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
AthenaInterprocess/Incidents.h
"
6
#include "GaudiKernel/IIncidentSvc.h"
7
#include "GaudiKernel/ConcurrencyFlags.h"
8
#include "
GPUSystemInfoSvc.h
"
9
#include <cuda_runtime.h>
10
11
namespace
AthCUDA
{
12
13
StatusCode
GPUSystemInfoSvc::initialize
() {
14
const
bool
isMultiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
15
if
(isMultiprocess) {
16
SmartIF<IIncidentSvc> incsvc{service(
"IncidentSvc"
)};
17
incsvc->addListener(
this
,
AthenaInterprocess::UpdateAfterFork::type
(), 1000);
// high priority- before other GPU functions
18
19
ATH_MSG_DEBUG
(
"In multiprocess mode the CUDA context will be only checked after fork"
);
20
return
StatusCode::SUCCESS;
21
}
22
else
{
23
readAvailableDevices
();
24
25
ATH_MSG_DEBUG
(
"GPU availability check in initialize "
<< std::boolalpha << (
m_deviceInfo
.size() > 0));
26
return
StatusCode::SUCCESS;
27
}
28
}
29
30
void
GPUSystemInfoSvc::handle
(
const
Incident&) {
31
readAvailableDevices
();
32
ATH_MSG_DEBUG
(
"GPU availability check in UpdateAfterFork "
<< std::boolalpha << (
m_deviceInfo
.size() > 0));
33
}
34
35
const
std::vector<DeviceInfo>&
GPUSystemInfoSvc::getAvailableDevices
()
const
{
36
if
(
m_wasChecked
==
false
) {
37
ATH_MSG_WARNING
(
"Function was called before service initialization!"
);
38
}
39
return
m_deviceInfo
;
40
}
41
42
void
GPUSystemInfoSvc::readAvailableDevices
() {
43
std::call_once(
m_readDevicesOnceFlag
, [
this
]() {
44
std::string cudaErrorStr;
45
46
int
deviceCount = 0;
47
cudaError_t
error
= cudaGetDeviceCount(&deviceCount);
48
if
(
error
!= cudaSuccess) {
49
cudaErrorStr = cudaGetErrorString(
error
);
50
ATH_MSG_DEBUG
(
"Error in cudaGetDeviceCount "
<< cudaErrorStr);
51
}
52
53
for
(
int
i = 0; i < deviceCount; i++) {
54
cudaDeviceProp prop;
55
error
= cudaGetDeviceProperties(&prop, i);
56
57
if
(
error
!= cudaSuccess) {
58
cudaErrorStr = cudaGetErrorString(
error
);
59
ATH_MSG_DEBUG
(
"Error in cudaGetDeviceProperties for device "
<< i <<
" "
<< cudaErrorStr);
60
continue
;
61
}
62
m_deviceInfo
.emplace_back(i, prop.name, prop.major, prop.minor);
63
}
64
65
66
if
(
m_deviceInfo
.empty()) {
67
ATH_MSG_DEBUG
(
"No CUDA Devices not available"
);
68
}
69
70
m_wasChecked
=
true
;
71
});
72
}
73
}
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
GPUSystemInfoSvc.h
Incidents.h
AthCUDA::GPUSystemInfoSvc::initialize
virtual StatusCode initialize() override
Definition
GPUSystemInfoSvc.cxx:13
AthCUDA::GPUSystemInfoSvc::m_deviceInfo
std::vector< DeviceInfo > m_deviceInfo
Definition
GPUSystemInfoSvc.h:27
AthCUDA::GPUSystemInfoSvc::getAvailableDevices
virtual const std::vector< DeviceInfo > & getAvailableDevices() const override
Definition
GPUSystemInfoSvc.cxx:35
AthCUDA::GPUSystemInfoSvc::handle
virtual void handle(const Incident &) override
Definition
GPUSystemInfoSvc.cxx:30
AthCUDA::GPUSystemInfoSvc::m_wasChecked
bool m_wasChecked
Definition
GPUSystemInfoSvc.h:28
AthCUDA::GPUSystemInfoSvc::readAvailableDevices
void readAvailableDevices()
Definition
GPUSystemInfoSvc.cxx:42
AthCUDA::GPUSystemInfoSvc::m_readDevicesOnceFlag
std::once_flag m_readDevicesOnceFlag
Definition
GPUSystemInfoSvc.h:29
AthenaInterprocess::UpdateAfterFork::type
static const std::string & type()
Incident type.
Definition
Incidents.h:49
AthCUDA
Definition
Info.h:14
error
Definition
IImpactPoint3dEstimator.h:72
Generated on
for ATLAS Offline Software by
1.17.0