-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass.c
244 lines (216 loc) · 7.36 KB
/
pass.c
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
//#include <iostream>
//#include <fstream>
//#include <ctime>
#include <stdio.h>
//extern "C" {
#include <coprthr.h>
#include <coprthr_cc.h>
#include <coprthr_thread.h>
#include <coprthr_mpi.h>
//}
#include "passing.h"
#define ECORES 16 /// Not great - CORECOUNT is defined as the same thing in ringTopo16.c
//using namespace std;
int main()
{
int i; /// Uncomment when using debug
int n;
clock_t tstart, tend;
// std::filebuf fbuf;
// fbuf.open("pass.csv", std::ios::out);
// std::ostream fout(&fbuf);
// char strInfo[128];
int host_debug[DEBUG_BUFFER];
// int * host_debug = (int*)malloc(DEBUG_BUFFER*sizeof(int));
pass_args args;
int dd = coprthr_dopen(COPRTHR_DEVICE_E32,COPRTHR_O_THREAD);
// std::cout << "dd=" << dd << "\n";
printf("epiphany dev:%i\n", dd);
if (dd<0)
{
// std::cout << "device open failed\n";
printf("Device open failed.\n");
exit(0);
}
coprthr_program_t prg = coprthr_cc_read_bin("./passing.e32", 0);
// coprthr_kernel_t thr_passUni = (coprthr_sym_t)coprthr_getsym(prg,"k_passUni");
// coprthr_sym_t thr_mpiPassUni = (coprthr_sym_t)coprthr_getsym(prg,"k_mpiPassUni");
// coprthr_sym_t thr_mpiMulti = clsym(stdacc, openHandle, "k_mpiPassMulti", CLLD_NOW);
// coprthr_sym_t thr_Multi = (coprthr_sym_t)coprthr_getsym(prg, "k_passMulti");
// coprthr_sym_t thr_mpiBroadcast = clsym(stdacc, openHandle, "k_mpiPassBroadcast", CLLD_NOW);
coprthr_kernel_t thr_Broadcast = (coprthr_sym_t)coprthr_getsym(prg,"k_passBroadcast");
coprthr_mem_t dev_debug = (coprthr_mem_t)coprthr_dmalloc(dd, DEBUG_BUFFER*sizeof(int), 0); /// Allocate some space on the epiphany for debug
for (i=0; i<DEBUG_BUFFER; i++)
host_debug[i] = -1;
for (i=0; i<32; i++) /// testing
host_debug[i] = 0;
coprthr_dwrite(dd, dev_debug, 0, host_debug, DEBUG_BUFFER*sizeof(int), COPRTHR_E_WAIT);
args.debug = coprthr_memptr(dev_debug, 0);
// for (n=1; n<=16; n++)
for (n=3; n<=3; n=n+2)
{
//std::cout << "n is equal to: " << n << "\n";
args.n = n; /// passed to all kernels
/// unicast
/*
printf("about to call Unipass.\n");
tstart = clock();
// coprthr_dexec(dd, ECORES, thr_passUni, &args, COPRTHR_E_WAIT); // wait for the documentaiton for this call
coprthr_mpiexec(dd, ECORES, thr_passUni, &args, sizeof(pass_args), 0);
tend = clock();
printf("forked - MPI Unicast. Exec time was: %i\n", (int)(tend - tstart));
// fout << n << "," << "unicast," << (tend - tstart) << endl;
coprthr_dread(dd, dev_debug, 0, host_debug, DEBUG_BUFFER*sizeof(int), COPRTHR_E_NOWAIT);
/// Uncomment to use debug as output
i = 0;
while (i<DEBUG_BUFFER)
{
// if (host_debug[i] != -1)
if (i < (16*5))
{
// fout << host_debug[i++];
printf("%d, ", host_debug[i++]);
if ((i%(16*n)) == 0)
// fout << std::endl;
printf("\n");
else
printf("'");
// fout << ",";
}
else
break;
}
printf("\n");
// fout << endl;
// fout.flush();
*/
/// MPI unicast
/// Uncomment if using debug
/*
tstart = clock();
coprthr_mpiexec(dd, ECORES, thr_mpiPassUni, &args, sizeof(args), 0);
tend = clock();
// std::cout << "forked - MPI Unicast\n";
printf("forked - MPI Unicast. Exec time was: %i\n", (int)(tend - tstart));
// fout << n << "," << "mpi unicast," << (tend - tstart) << "\n";
coprthr_dread(dd, dev_debug, 0, host_debug, DEBUG_BUFFER*sizeof(int),COPRTHR_E_WAIT);
// printf("Read return data from shared memory\n");
/// Uncomment to use debug as output
i = 0;
while (i<DEBUG_BUFFER)
{
if (host_debug[i] != -1)
// if (i < (16*5))
{
// fout << host_debug[i++];
printf("%d, ", host_debug[i++]);
if ((i%(16*n)) == 0)
// fout << std::endl;
printf("\n");
else
printf("'");
// fout << ",";
}
else
break;
}
printf("\neod\n");
// fout << std::endl;
// fout.flush();
*/
/// multicast
/*
/// Uncomment if using debug
tstart = clock();
coprthr_mpiexec(dd, ECORES, krnMulti, &args, sizeof(args), 0);
tend = clock();
// cout <<
printf("forked - Multicast. Exec time was: %i\n", (int)(tend - tstart));
// fout << n << "," << "multicast," << (tend - tstart) << endl;
coprthr_dread(dd, dev_debug, 0, host_debug, DEBUG_BUFFER*sizeof(int),COPRTHR_E_WAIT);
*/
/// Uncomment to use debug as output
/* i = 0;
while (i<DEBUG_BUFFER)
{
if (debug[i] != -1)
{
fout << debug[i++];
if ((i%(16*n)) == 0)
fout << endl;
else
fout << ",";
}
else
break;
}
fout << endl; */
// fout.flush();
/// broardcast
/// Uncomment if using debug
// for (i=0; i<DEBUG_BUFFER; i++)
// debug[i] = -1;
// clmsync(stdacc, 0, debug, CL_MEM_DEVICE|CL_EVENT_WAIT);
//
// tstart = clock();
// clforka(stdacc, 0, krnBroadcast, &ndr, CL_EVENT_WAIT, n, debug);
// cout << "forked - Broadcast\n";
// tend = clock();
//
// fout << n << "," << "broadcast," << (tend - tstart) << endl;
// clmsync(stdacc, 0, debug, CL_MEM_HOST|CL_EVENT_WAIT);
/// Uncomment to use debug as output
/* i = 0;
while (i<DEBUG_BUFFER)
{
if (debug[i] != -1)
{
fout << debug[i++];
if ((i%(16*n)) == 0)
fout << endl;
else
fout << ",";
}
else
break;
}
fout << endl;
*/
// fout.flush();
/// broardcast - No Wait
/// Uncomment if using debug
printf("about to call broadcast.\n");
tstart = clock();
// coprthr_dexec(dd, ECORES, thr_passUni, &args, COPRTHR_E_WAIT); // wait for the documentaiton for this call
coprthr_mpiexec(dd, ECORES, thr_Broadcast, &args, sizeof(pass_args), 0);
tend = clock();
printf("forked - Broadcast - no wait. Exec time was: %i\n", (int)(tend - tstart));
// fout << n << "," << "unicast," << (tend - tstart) << endl;
coprthr_dread(dd, dev_debug, 0, host_debug, DEBUG_BUFFER*sizeof(int), COPRTHR_E_NOWAIT);
/// Uncomment to use debug as output
/// First Retrieve the debug output from the cores - TODO
i = 0;
while (i<DEBUG_BUFFER)
{
if (host_debug[i] != -1)
// if (i < (16*5))
{
// fout << host_debug[i++];
printf("%d, ", host_debug[i++]);
if ((i%(16*n)) == 0)
// fout << std::endl;
printf("\n");
else
printf("'");
// fout << ",";
}
else
break;
}
// fout.flush();
}
printf("closing device\n");
coprthr_dclose(dd);
// fbuf.close();
return 0;
}