QMCPACK
DeviceManager.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2021 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #include "DeviceManager.h"
15 #include <memory>
16 #include <stdexcept>
17 #include "Host/OutputManager.h"
18 
19 namespace qmcplusplus
20 {
21 
22 DeviceManager::DeviceManager(int local_rank, int local_size)
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 }
42 
44 
45 std::unique_ptr<DeviceManager> DeviceManager::global;
46 
47 void DeviceManager::initializeGlobalDeviceManager(int local_rank, int local_size)
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 }
56 
58 {
59  if (!global)
60  throw std::runtime_error("DeviceManager::getGlobal the global instance was not initialized.");
61  return *global;
62 }
63 } // namespace qmcplusplus
std::ostream & app_warning()
Definition: OutputManager.h:69
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Declaration of OutputManager class.
DeviceManager(int local_rank, int local_size)
constructor
if(c->rank()==0)
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
static const DeviceManager & getGlobal()
global instance accessor
orchestrate platforms (programming models) and set up the default device on each platform ...
Definition: DeviceManager.h:50
static void initializeGlobalDeviceManager(int local_rank, int local_size)
initialize the global instance of DeviceManager arguments are the same as the constructor ...
int num_devices
the number of devices. Must be defined before platform device manager objects
Definition: DeviceManager.h:88