QMCPACK
DeviceManager Class Reference

orchestrate platforms (programming models) and set up the default device on each platform More...

+ Collaboration diagram for DeviceManager:

Public Member Functions

 DeviceManager (int local_rank, int local_size)
 constructor More...
 
 ~DeviceManager ()
 
int getDefaultDeviceNum () const
 
int getNumDevices () const
 

Static Public Member Functions

static void initializeGlobalDeviceManager (int local_rank, int local_size)
 initialize the global instance of DeviceManager arguments are the same as the constructor More...
 
static const DeviceManagergetGlobal ()
 global instance accessor More...
 

Private Attributes

int default_device_num
 the id of default device. Must be defined before platform device manager objects More...
 
int num_devices
 the number of devices. Must be defined before platform device manager objects More...
 

Static Private Attributes

static std::unique_ptr< DeviceManagerglobal
 the global singleton which can be used to query default devices and all the captured devices. More...
 

Detailed Description

orchestrate platforms (programming models) and set up the default device on each platform

Currently support CUDA, OpenMP, SYCL

Each platform provides its own device manager class. Each individual device manager initializes all the devices visible to the process and also set the default device. The first initialized platform selects the default device for the current process and all the rest platforms follow that choice.

The device manager on each platform may be constomized to store a list of known device numbers or a list of context device handles depending on the need.

DeviceManager assumes there is only one type of accelerators although they may support multiple platforms. Under this assumption, the numbers of devices captured on all the platforms must agree.

DeviceManager::global is intended to the per-process global instance and should be initialized after MPI initialization in main().

Definition at line 50 of file DeviceManager.h.

Constructor & Destructor Documentation

◆ DeviceManager()

DeviceManager ( int  local_rank,
int  local_size 
)

constructor

Parameters
local_rankthe rank id of the node local MPI communicator
local_sizethe size of the node local MPI communicator

Definition at line 22 of file DeviceManager.cpp.

References qmcplusplus::app_warning(), and DeviceManager::num_devices.

23  : default_device_num(-1),
24  num_devices(0)
25 #if defined(ENABLE_CUDA)
26  , cuda_dm_(default_device_num, num_devices, local_rank, local_size)
27 #endif
28 #if defined(ENABLE_OFFLOAD)
29  , omptarget_dm_(default_device_num, num_devices, local_rank, local_size)
30 #endif
31 #if defined(ENABLE_SYCL)
32  , sycl_dm_(default_device_num, num_devices, local_rank, local_size)
33 #endif
34 {
35  if (num_devices > 0)
36  {
37  if (local_size % num_devices != 0)
38  app_warning() << "The number of MPI ranks on the node is not divisible by the number of accelerators. "
39  << "Imbalanced load may cause performance loss.\n";
40  }
41 }
std::ostream & app_warning()
Definition: OutputManager.h:69
int default_device_num
the id of default device. Must be defined before platform device manager objects
Definition: DeviceManager.h:86
int num_devices
the number of devices. Must be defined before platform device manager objects
Definition: DeviceManager.h:88

◆ ~DeviceManager()

~DeviceManager ( )
default

Member Function Documentation

◆ getDefaultDeviceNum()

int getDefaultDeviceNum ( ) const
inline

Definition at line 62 of file DeviceManager.h.

References DeviceManager::default_device_num.

62 { return default_device_num; }
int default_device_num
the id of default device. Must be defined before platform device manager objects
Definition: DeviceManager.h:86

◆ getGlobal()

const DeviceManager & getGlobal ( )
static

global instance accessor

Definition at line 57 of file DeviceManager.cpp.

References DeviceManager::global.

Referenced by QMCMain::QMCMain().

58 {
59  if (!global)
60  throw std::runtime_error("DeviceManager::getGlobal the global instance was not initialized.");
61  return *global;
62 }
static std::unique_ptr< DeviceManager > global
the global singleton which can be used to query default devices and all the captured devices...
Definition: DeviceManager.h:84

◆ getNumDevices()

int getNumDevices ( ) const
inline

Definition at line 63 of file DeviceManager.h.

References DeviceManager::num_devices.

Referenced by QMCMain::QMCMain().

63 { return num_devices; }
int num_devices
the number of devices. Must be defined before platform device manager objects
Definition: DeviceManager.h:88

◆ initializeGlobalDeviceManager()

void initializeGlobalDeviceManager ( int  local_rank,
int  local_size 
)
static

initialize the global instance of DeviceManager arguments are the same as the constructor

Definition at line 47 of file DeviceManager.cpp.

References DeviceManager::global.

Referenced by main(), and QMCMain::QMCMain().

48 {
49  // throw error on subsequent calls to initializeGlobalDeviceManager
50  // if the desired behavior is no-op. std::call_once can be used.
51  if (global)
52  throw std::runtime_error(
53  "DeviceManager::initializeGlobalDeviceManager the global instance cannot be initialized again.");
54  global = std::make_unique<DeviceManager>(local_rank, local_size);
55 }
static std::unique_ptr< DeviceManager > global
the global singleton which can be used to query default devices and all the captured devices...
Definition: DeviceManager.h:84

Member Data Documentation

◆ default_device_num

int default_device_num
private

the id of default device. Must be defined before platform device manager objects

Definition at line 86 of file DeviceManager.h.

Referenced by DeviceManager::getDefaultDeviceNum().

◆ global

std::unique_ptr< DeviceManager > global
staticprivate

the global singleton which can be used to query default devices and all the captured devices.

Definition at line 84 of file DeviceManager.h.

Referenced by DeviceManager::getGlobal(), and DeviceManager::initializeGlobalDeviceManager().

◆ num_devices

int num_devices
private

the number of devices. Must be defined before platform device manager objects

Definition at line 88 of file DeviceManager.h.

Referenced by DeviceManager::DeviceManager(), and DeviceManager::getNumDevices().


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