NAMD
DeviceCUDA.h
Go to the documentation of this file.
1 #ifndef DEVICECUDA_H
2 #define DEVICECUDA_H
3 
4 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
5 #ifdef NAMD_CUDA
6 #include <cuda_runtime.h>
7 #endif
8 #ifdef NAMD_HIP
9 #include "HipDefines.h"
10 #include <hip/hip_runtime.h>
11 #endif
12 #define CUDA_PME_SPREADCHARGE_EVENT 90
13 #define CUDA_PME_GATHERFORCE_EVENT 91
14 #define CUDA_BONDED_KERNEL_EVENT 92
15 #define CUDA_DEBUG_EVENT 93
16 #define CUDA_NONBONDED_KERNEL_EVENT 94
17 #define CUDA_GBIS1_KERNEL_EVENT 95
18 #define CUDA_GBIS2_KERNEL_EVENT 96
19 #define CUDA_GBIS3_KERNEL_EVENT 97
20 
21 #define CUDA_EVENT_ID_POLL_REMOTE 98
22 #define CUDA_TRACE_POLL_REMOTE \
23  traceUserEvent(CUDA_EVENT_ID_POLL_REMOTE)
24 #define CUDA_EVENT_ID_POLL_LOCAL 99
25 #define CUDA_TRACE_POLL_LOCAL \
26  traceUserEvent(CUDA_EVENT_ID_POLL_LOCAL)
27 #define CUDA_EVENT_ID_BASE 100
28 #define CUDA_TRACE_REMOTE(START,END) \
29  do { int dev; cudaGetDevice(&dev); traceUserBracketEvent( \
30  CUDA_EVENT_ID_BASE + 2 * dev, START, END); } while (0)
31 #define CUDA_TRACE_LOCAL(START,END) \
32  do { int dev; cudaGetDevice(&dev); traceUserBracketEvent( \
33  CUDA_EVENT_ID_BASE + 2 * dev + 1, START, END); } while (0)
34 
35 //
36 // Class that handles PE <=> CUDA device mapping
37 //
38 class DeviceCUDA {
39 
40 private:
41  // Command line argument settings
42  char *devicelist;
43  int usedevicelist;
44  int devicesperreplica;
45  int ignoresharing;
46  int mergegrids;
47  int nomergegrids;
48  int nostreaming;
49 
50  // Number of devices on this physical node
51  int deviceCount;
52 
53  // Number of devices on this physical node that are used for computation
54  int ndevices;
55 
56  // List of device IDs on this physical node that are used for computation
57  int *devices;
58 
59  // Number of devices that are used for computation by this node
60  int nnodedevices;
61 
62  // List of device IDs that are used for computation by this node
63  int *nodedevices;
64 
65  // True when GPU is shared between PEs
66  bool sharedGpu;
67  // Index of next GPU sharing this GPU
68  int nextPeSharingGpu;
69  // Index of the master PE for this GPU
70  int masterPe;
71  // Number of PEs that share this GPU
72  int numPesSharingDevice;
73  // List of PEs that share this GPU
74  int *pesSharingDevice;
75  // True when what???
76  int gpuIsMine;
77 
78  // Device ID for this Pe
79  int deviceID;
80 
81  // Device properties for all devices on this node
82  cudaDeviceProp* deviceProps;
83 
84  void register_user_events();
85 
86 public:
87  DeviceCUDA();
88  ~DeviceCUDA();
89 
90  void initialize();
91 
92  int getDeviceCount() {return deviceCount;}
93  int getNumDevice() {return nnodedevices;}
94 
95  bool device_shared_with_pe(int pe);
96  bool one_device_per_node();
97 
98  int getNoStreaming() {return nostreaming;}
99  int getNoMergeGrids() {return nomergegrids;}
100  int getMergeGrids() {return mergegrids;}
101  void setMergeGrids(const int val) {mergegrids = val;}
102 
103  bool getSharedGpu() {return sharedGpu;}
104  int getNextPeSharingGpu() {return nextPeSharingGpu;}
105  int getMasterPe() {return masterPe;}
106  int getNumPesSharingDevice() {return numPesSharingDevice;}
107  int getPesSharingDevice(const int i) {return pesSharingDevice[i];}
108 
109  int getGpuIsMine() {return gpuIsMine;}
110  void setGpuIsMine(const int val) {gpuIsMine = val;}
111 
112  int getDeviceID() {return deviceID;}
113  int getDeviceIDbyRank(int rank) {return nodedevices[rank];}
114  int getDeviceIDforPe(int pe);
115  int getMasterPeForDeviceID(int deviceID);
116 
117  int getMaxNumThreads();
118  int getMaxNumBlocks();
119 };
120 #endif //NAMD_CUDA
121 
122 #endif // DEVICECUDA_H
void initialize()
Definition: DeviceCUDA.C:89
int getDeviceCount()
Definition: DeviceCUDA.h:92
int getMaxNumThreads()
Definition: DeviceCUDA.C:413
bool getSharedGpu()
Definition: DeviceCUDA.h:103
void setMergeGrids(const int val)
Definition: DeviceCUDA.h:101
int getNumDevice()
Definition: DeviceCUDA.h:93
int getMergeGrids()
Definition: DeviceCUDA.h:100
void setGpuIsMine(const int val)
Definition: DeviceCUDA.h:110
int getMasterPe()
Definition: DeviceCUDA.h:105
int getMasterPeForDeviceID(int deviceID)
Definition: DeviceCUDA.C:385
bool device_shared_with_pe(int pe)
Definition: DeviceCUDA.C:392
int getPesSharingDevice(const int i)
Definition: DeviceCUDA.h:107
int getMaxNumBlocks()
Definition: DeviceCUDA.C:419
int getDeviceID()
Definition: DeviceCUDA.h:112
int getNoMergeGrids()
Definition: DeviceCUDA.h:99
int getNextPeSharingGpu()
Definition: DeviceCUDA.h:104
int getDeviceIDbyRank(int rank)
Definition: DeviceCUDA.h:113
int getNoStreaming()
Definition: DeviceCUDA.h:98
int getGpuIsMine()
Definition: DeviceCUDA.h:109
bool one_device_per_node()
Definition: DeviceCUDA.C:402
int getDeviceIDforPe(int pe)
Definition: DeviceCUDA.C:378
int getNumPesSharingDevice()
Definition: DeviceCUDA.h:106