ATLAS Offline Software
Loading...
Searching...
No Matches
AthCUDA::GPUSystemInfoSvc Class Reference

#include <GPUSystemInfoSvc.h>

Inheritance diagram for AthCUDA::GPUSystemInfoSvc:
Collaboration diagram for AthCUDA::GPUSystemInfoSvc:

Public Member Functions

virtual StatusCode initialize () override
virtual void handle (const Incident &) override
virtual const std::vector< DeviceInfo > & getAvailableDevices () const override

Private Member Functions

void readAvailableDevices ()

Private Attributes

std::vector< DeviceInfom_deviceInfo
bool m_wasChecked {}
std::once_flag m_readDevicesOnceFlag

Detailed Description

Definition at line 18 of file GPUSystemInfoSvc.h.

Member Function Documentation

◆ getAvailableDevices()

const std::vector< DeviceInfo > & AthCUDA::GPUSystemInfoSvc::getAvailableDevices ( ) const
overridevirtual

Definition at line 35 of file GPUSystemInfoSvc.cxx.

35 {
36 if (m_wasChecked == false) {
37 ATH_MSG_WARNING("Function was called before service initialization!");
38 }
39 return m_deviceInfo;
40 }
#define ATH_MSG_WARNING(x)
std::vector< DeviceInfo > m_deviceInfo

◆ handle()

void AthCUDA::GPUSystemInfoSvc::handle ( const Incident & )
overridevirtual

Definition at line 30 of file GPUSystemInfoSvc.cxx.

30 {
32 ATH_MSG_DEBUG("GPU availability check in UpdateAfterFork " << std::boolalpha << (m_deviceInfo.size() > 0));
33 }
#define ATH_MSG_DEBUG(x)

◆ initialize()

StatusCode AthCUDA::GPUSystemInfoSvc::initialize ( )
overridevirtual

Definition at line 13 of file GPUSystemInfoSvc.cxx.

13 {
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 {
24
25 ATH_MSG_DEBUG("GPU availability check in initialize " << std::boolalpha << (m_deviceInfo.size() > 0));
26 return StatusCode::SUCCESS;
27 }
28 }
static const std::string & type()
Incident type.
Definition Incidents.h:49

◆ readAvailableDevices()

void AthCUDA::GPUSystemInfoSvc::readAvailableDevices ( )
private

Definition at line 42 of file GPUSystemInfoSvc.cxx.

42 {
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 return;
69 }
70
71 m_wasChecked = true;
72 });
73 }
std::once_flag m_readDevicesOnceFlag

Member Data Documentation

◆ m_deviceInfo

std::vector<DeviceInfo> AthCUDA::GPUSystemInfoSvc::m_deviceInfo
private

Definition at line 27 of file GPUSystemInfoSvc.h.

◆ m_readDevicesOnceFlag

std::once_flag AthCUDA::GPUSystemInfoSvc::m_readDevicesOnceFlag
private

Definition at line 29 of file GPUSystemInfoSvc.h.

◆ m_wasChecked

bool AthCUDA::GPUSystemInfoSvc::m_wasChecked {}
private

Definition at line 28 of file GPUSystemInfoSvc.h.

28{};

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