-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommunications.cu
291 lines (280 loc) · 10.8 KB
/
communications.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include "vars.h"
extern int socketrayout;
extern int socketrayinc;
extern int *socketreduceout;
extern int *socketreduceinc;
extern int *socketreduceoutdispl;
extern int *socketreduceincdispl;
extern int *socketsendcomm;
extern int *socketrecvcomm;
extern int *socketsendcommdispl;
extern int *socketrecvcommdispl;
extern int *socketsendmap;
extern int *socketreducedispl;
extern int *socketreduceindex;
extern int *socketraydispl;
extern int *socketrayindex;
extern int *socketpackmap;
extern int *socketunpackmap;
extern int noderayout;
extern int noderayinc;
extern int *nodereduceout;
extern int *nodereduceinc;
extern int *nodereduceoutdispl;
extern int *nodereduceincdispl;
extern int *nodesendcomm;
extern int *noderecvcomm;
extern int *nodesendcommdispl;
extern int *noderecvcommdispl;
extern int *nodesendmap;
extern int *nodereducedispl;
extern int *nodereduceindex;
extern int *noderaydispl;
extern int *noderayindex;
extern int *nodepackmap;
extern int *nodeunpackmap;
extern int numthreads;
extern int numproc;
extern int myid;
extern MPI_Comm MPI_COMM_BATCH;
extern int numproc_batch;
extern int myid_batch;
extern MPI_Comm MPI_COMM_DATA;
extern int numproc_data;
extern int myid_data;
extern MPI_Comm MPI_COMM_NODE;
extern int numproc_node;
extern int myid_node;
extern int numnode;
extern MPI_Comm MPI_COMM_SOCKET;
extern int numproc_socket;
extern int myid_socket;
extern int numsocket;
extern int *socketpackmap_d;
extern int *socketunpackmap_d;
extern int *socketreducedispl_d;
extern int *socketreduceindex_d;
extern int *nodepackmap_d;
extern int *nodeunpackmap_d;
extern int *nodereducedispl_d;
extern int *nodereduceindex_d;
extern int *raypackmap_d;
extern int *rayunpackmap_d;
extern int *noderaydispl_d;
extern int *noderayindex_d;
extern COMMPREC *socketreducesendbuff_d;
extern COMMPREC *socketreducerecvbuff_d;
extern COMMPREC *nodereducesendbuff_d;
extern COMMPREC *nodereducerecvbuff_d;
extern COMMPREC *nodesendbuff_d;
extern COMMPREC *noderecvbuff_d;
extern COMMPREC *nodesendbuff_h;
extern COMMPREC *noderecvbuff_h;
extern int numdevice;
extern int mydevice;
int *socketrecvbuffdispl_p;
COMMPREC **socketrecvbuff_p;
int *socketrecvdevice_p;
int *noderecvbuffdispl_p;
COMMPREC **noderecvbuff_p;
int *noderecvdevice_p;
long proj_intersocket = 0;
long proj_internode = 0;
long proj_interhost = 0;
long back_intersocket = 0;
long back_internode = 0;
long back_interhost = 0;
void communications(){
MPI_Request sendrequest[numproc_data];
MPI_Request recvrequest[numproc_data];
socketrecvbuff_p = new COMMPREC*[numproc_socket];
socketrecvbuffdispl_p = new int[numproc_socket];
cudaIpcMemHandle_t sockethandle[numproc_socket];
{
int sendcount = 0;
int recvcount = 0;
//RECEIVER SENDS MEMORY HANDLE
for(int precv = 0; precv < numproc_socket; precv++)
if(socketrecvcomm[precv]){
MPI_Issend(&socketrecvcommdispl[precv],1,MPI_INT,precv,1,MPI_COMM_SOCKET,sendrequest+sendcount);
sendcount++;
if(myid_socket!=precv){
cudaIpcGetMemHandle(&sockethandle[precv],socketreducerecvbuff_d);
MPI_Issend(&sockethandle[precv],sizeof(cudaIpcMemHandle_t),MPI_BYTE,precv,0,MPI_COMM_SOCKET,recvrequest+recvcount);
recvcount++;
}
else
socketrecvbuff_p[precv] = socketreducerecvbuff_d;
}
//SENDER OPENS MEMORY HANDLE
for(int psend = 0; psend < numproc_socket; psend++)
if(socketsendcomm[psend]){
MPI_Recv(&socketrecvbuffdispl_p[psend],1,MPI_INT,psend,1,MPI_COMM_SOCKET,MPI_STATUS_IGNORE);
if(myid_socket!=psend){
cudaIpcMemHandle_t temphandle;
MPI_Recv(&temphandle,sizeof(cudaIpcMemHandle_t),MPI_BYTE,psend,0,MPI_COMM_SOCKET,MPI_STATUS_IGNORE);
cudaIpcOpenMemHandle((void**)&socketrecvbuff_p[psend],temphandle,cudaIpcMemLazyEnablePeerAccess);
}
}
MPI_Waitall(sendcount,sendrequest,MPI_STATUSES_IGNORE);
MPI_Waitall(recvcount,recvrequest,MPI_STATUSES_IGNORE);
}
//RECEIVER DEVICE ID
socketrecvdevice_p = new int[numproc_socket];
for(int p = 0; p < numproc_socket; p++)
socketrecvdevice_p[p] = ((myid/numproc_socket)*numproc_socket+p)%numdevice;
//SOCKET IPC WARM-UP
{
{
cudaDeviceSynchronize();
MPI_Barrier(MPI_COMM_SOCKET);
double time = MPI_Wtime();
for(int psend = 0; psend < numproc_socket; psend++){
if(socketsendcomm[psend]){
cudaMemcpyPeerAsync(socketrecvbuff_p[psend]+socketrecvbuffdispl_p[psend]*FFACTOR,socketrecvdevice_p[psend],socketreducesendbuff_d+socketsendcommdispl[psend]*FFACTOR,mydevice,sizeof(COMMPREC)*socketsendcomm[psend]*FFACTOR);
if(psend != myid_socket)
proj_intersocket += socketsendcomm[psend];
}
}
cudaDeviceSynchronize();
MPI_Barrier(MPI_COMM_SOCKET);
MPI_Allreduce(MPI_IN_PLACE,&proj_intersocket,1,MPI_LONG,MPI_SUM,MPI_COMM_DATA);
if(myid==0)printf("proj socket warmup time %e\n",MPI_Wtime()-time);
}
{
cudaDeviceSynchronize();
MPI_Barrier(MPI_COMM_SOCKET);
double time = MPI_Wtime();
for(int psend = 0; psend < numproc_socket; psend++)
if(socketsendcomm[psend]){
cudaMemcpyPeerAsync(socketreducesendbuff_d+socketsendcommdispl[psend]*FFACTOR,mydevice,socketrecvbuff_p[psend]+socketrecvbuffdispl_p[psend]*FFACTOR,socketrecvdevice_p[psend],sizeof(COMMPREC)*socketsendcomm[psend]*FFACTOR);
if(psend != myid_socket)
back_intersocket += socketsendcomm[psend];
}
cudaDeviceSynchronize();
MPI_Barrier(MPI_COMM_SOCKET);
MPI_Allreduce(MPI_IN_PLACE,&back_intersocket,1,MPI_LONG,MPI_SUM,MPI_COMM_DATA);
if(myid==0)printf("back socket warmup time %e\n",MPI_Wtime()-time);
}
}
noderecvbuff_p = new COMMPREC*[numproc_node];
noderecvbuffdispl_p = new int[numproc_node];
cudaIpcMemHandle_t nodehandle[numproc_node];
{
int sendcount = 0;
int recvcount = 0;
//RECEIVER SENDS MEMORY HANDLE
for(int precv = 0; precv < numproc_node; precv++)
if(noderecvcomm[precv]){
MPI_Issend(&noderecvcommdispl[precv],1,MPI_INT,precv,1,MPI_COMM_NODE,sendrequest+sendcount);
sendcount++;
if(myid_node!=precv){
cudaIpcGetMemHandle(&nodehandle[precv],nodereducerecvbuff_d);
MPI_Issend(&nodehandle[precv],sizeof(cudaIpcMemHandle_t),MPI_BYTE,precv,0,MPI_COMM_NODE,recvrequest+recvcount);
recvcount++;
}
else
noderecvbuff_p[precv] = nodereducerecvbuff_d;
}
//SENDER OPENS MEMORY HANDLE
for(int psend = 0; psend < numproc_node; psend++)
if(nodesendcomm[psend]){
MPI_Recv(&noderecvbuffdispl_p[psend],1,MPI_INT,psend,1,MPI_COMM_NODE,MPI_STATUS_IGNORE);
if(myid_node!=psend){
cudaIpcMemHandle_t temphandle;
MPI_Recv(&temphandle,sizeof(cudaIpcMemHandle_t),MPI_BYTE,psend,0,MPI_COMM_NODE,MPI_STATUS_IGNORE);
cudaIpcOpenMemHandle((void**)&noderecvbuff_p[psend],temphandle,cudaIpcMemLazyEnablePeerAccess);
}
}
MPI_Waitall(sendcount,sendrequest,MPI_STATUSES_IGNORE);
MPI_Waitall(recvcount,recvrequest,MPI_STATUSES_IGNORE);
}
//RECEIVER DEVICE ID
noderecvdevice_p = new int[numproc_node];
for(int p = 0; p < numproc_node; p++)
noderecvdevice_p[p] = ((myid/numproc_node)*numproc_node+p)%numdevice;
//NODE IPC WARM-UP
{
{
cudaDeviceSynchronize();
MPI_Barrier(MPI_COMM_NODE);
double time = MPI_Wtime();
for(int psend = 0; psend < numproc_node; psend++){
if(nodesendcomm[psend]){
cudaMemcpyPeerAsync(noderecvbuff_p[psend]+noderecvbuffdispl_p[psend]*FFACTOR,noderecvdevice_p[psend],nodereducesendbuff_d+nodesendcommdispl[psend]*FFACTOR,mydevice,sizeof(COMMPREC)*nodesendcomm[psend]*FFACTOR);
if(psend/numproc_socket != myid_node/numproc_socket)
proj_internode += nodesendcomm[psend];
}
}
cudaDeviceSynchronize();
MPI_Barrier(MPI_COMM_NODE);
if(myid==0)printf("proj node warmup time %e\n",MPI_Wtime()-time);
MPI_Allreduce(MPI_IN_PLACE,&proj_internode,1,MPI_LONG,MPI_SUM,MPI_COMM_DATA);
}
{
cudaDeviceSynchronize();
MPI_Barrier(MPI_COMM_NODE);
double time = MPI_Wtime();
for(int psend = 0; psend < numproc_node; psend++)
if(nodesendcomm[psend]){
cudaMemcpyPeerAsync(nodereducesendbuff_d+nodesendcommdispl[psend]*FFACTOR,mydevice,noderecvbuff_p[psend]+noderecvbuffdispl_p[psend]*FFACTOR,noderecvdevice_p[psend],sizeof(COMMPREC)*nodesendcomm[psend]*FFACTOR);
if(psend/numproc_socket != myid_node/numproc_socket)
back_internode += nodesendcomm[psend];
}
cudaDeviceSynchronize();
MPI_Barrier(MPI_COMM_NODE);
if(myid==0)printf("back node warmup time %e\n",MPI_Wtime()-time);
MPI_Allreduce(MPI_IN_PLACE,&back_internode,1,MPI_LONG,MPI_SUM,MPI_COMM_DATA);
}
}
//HOST IPC WARM-UP
{
{
MPI_Barrier(MPI_COMM_DATA);
double chtime = MPI_Wtime();
int sendcount = 0;
int recvcount = 0;
for(int p = 0; p < numproc_data; p++)
if(nodereduceout[p]){
MPI_Issend(nodesendbuff_h+nodereduceoutdispl[p]*FFACTOR,nodereduceout[p]*FFACTOR*sizeof(COMMPREC),MPI_BYTE,p,0,MPI_COMM_DATA,sendrequest+sendcount);
sendcount++;
if(p/numproc_node != myid_data/numproc_node)
proj_interhost += nodereduceout[p];
}
for(int p = 0; p < numproc_data; p++){
if(nodereduceinc[p]){
MPI_Irecv(noderecvbuff_h+nodereduceincdispl[p]*FFACTOR,nodereduceinc[p]*FFACTOR*sizeof(COMMPREC),MPI_BYTE,p,0,MPI_COMM_DATA,recvrequest+recvcount);
recvcount++;
}
}
MPI_Waitall(sendcount,sendrequest,MPI_STATUSES_IGNORE);
MPI_Waitall(recvcount,recvrequest,MPI_STATUSES_IGNORE);
MPI_Barrier(MPI_COMM_DATA);
if(myid==0)printf("proj host time %e\n",MPI_Wtime()-chtime);
MPI_Allreduce(MPI_IN_PLACE,&proj_interhost,1,MPI_LONG,MPI_SUM,MPI_COMM_DATA);
}
{
MPI_Barrier(MPI_COMM_DATA);
double chtime = MPI_Wtime();
int sendcount = 0;
int recvcount = 0;
for(int p = 0; p < numproc_data; p++)
if(nodereduceout[p]){
MPI_Irecv(nodesendbuff_h+nodereduceoutdispl[p]*FFACTOR,nodereduceout[p]*FFACTOR*sizeof(COMMPREC),MPI_BYTE,p,0,MPI_COMM_DATA,sendrequest+sendcount);
sendcount++;
}
for(int p = 0; p < numproc_data; p++)
if(nodereduceinc[p]){
MPI_Issend(noderecvbuff_h+nodereduceincdispl[p]*FFACTOR,nodereduceinc[p]*FFACTOR*sizeof(COMMPREC),MPI_BYTE,p,0,MPI_COMM_DATA,recvrequest+recvcount);
recvcount++;
if(p/numproc_node != myid_data/numproc_node)
back_interhost += nodereduceinc[p];
}
MPI_Waitall(sendcount,sendrequest,MPI_STATUSES_IGNORE);
MPI_Waitall(recvcount,recvrequest,MPI_STATUSES_IGNORE);
MPI_Barrier(MPI_COMM_DATA);
if(myid==0)printf("back host time %e\n",MPI_Wtime()-chtime);
MPI_Allreduce(MPI_IN_PLACE,&back_interhost,1,MPI_LONG,MPI_SUM,MPI_COMM_DATA);
}
}
}