QMCPACK
DeviceManager.h
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 #ifndef QMCPLUSPLUS_DEVICEMANAGER_H
15 #define QMCPLUSPLUS_DEVICEMANAGER_H
16 
17 #include <memory>
18 #include <config.h>
19 #if defined(ENABLE_CUDA)
20 #include "CUDA/CUDADeviceManager.h"
21 #endif
22 #if defined(ENABLE_OFFLOAD)
24 #endif
25 #if defined(ENABLE_SYCL)
26 #include "SYCL/SYCLDeviceManager.h"
27 #endif
28 
29 namespace qmcplusplus
30 {
31 
32 /** orchestrate platforms (programming models) and set up the default device on each platform
33  *
34  * Currently support CUDA, OpenMP, SYCL
35  *
36  * Each platform provides its own device manager class. Each individual device manager
37  * initializes all the devices visible to the process and also set the default device.
38  * The first initialized platform selects the default device for the current process and all the rest
39  * platforms follow that choice.
40  *
41  * The device manager on each platform may be constomized to store a list of known device numbers or
42  * a list of context device handles depending on the need.
43  *
44  * DeviceManager assumes there is only one type of accelerators although they may support multiple
45  * platforms. Under this assumption, the numbers of devices captured on all the platforms must agree.
46  *
47  * DeviceManager::global is intended to the per-process global instance and should be initialized
48  * after MPI initialization in main().
49  */
51 {
52 public:
53  /** constructor
54  * @param local_rank the rank id of the node local MPI communicator
55  * @param local_size the size of the node local MPI communicator
56  */
57  DeviceManager(int local_rank, int local_size);
58 
60 
61  // accessors
62  int getDefaultDeviceNum() const { return default_device_num; }
63  int getNumDevices() const { return num_devices; }
64 
65 #if defined(ENABLE_CUDA)
66  const auto& getCUDADM() const { return cuda_dm_; }
67 #endif
68 #if defined(ENABLE_OFFLOAD)
69  const auto& getOMPDM() const { return omptarget_dm_; }
70 #endif
71 #if defined(ENABLE_SYCL)
72  const auto& getSYCLDM() const { return sycl_dm_; }
73 #endif
74 
75  /** initialize the global instance of DeviceManager
76  * arguments are the same as the constructor
77  */
78  static void initializeGlobalDeviceManager(int local_rank, int local_size);
79  /// global instance accessor
80  static const DeviceManager& getGlobal();
81 
82 private:
83  /// the global singleton which can be used to query default devices and all the captured devices.
84  static std::unique_ptr<DeviceManager> global;
85  /// the id of default device. Must be defined before platform device manager objects
87  /// the number of devices. Must be defined before platform device manager objects
89 #if defined(ENABLE_CUDA)
90  /// CUDA device manager object
91  CUDADeviceManager cuda_dm_;
92 #endif
93 #if defined(ENABLE_OFFLOAD)
94  /// OpenMP device manager object
95  OMPDeviceManager omptarget_dm_;
96 #endif
97 #if defined(ENABLE_SYCL)
98  /// SYCL device manager object
99  SYCLDeviceManager sycl_dm_;
100 #endif
101 };
102 
103 } // namespace qmcplusplus
104 
105 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
DeviceManager(int local_rank, int local_size)
constructor
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
OpenMP device manager.
int default_device_num
the id of default device. Must be defined before platform device manager objects
Definition: DeviceManager.h:86
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