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