-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGEMM_chunked_wrong.jdf
More file actions
341 lines (265 loc) · 10.3 KB
/
GEMM_chunked_wrong.jdf
File metadata and controls
341 lines (265 loc) · 10.3 KB
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
extern "C" %{
/**
* This second example shows how to create a simple jdf that has only one single task.
* JDF syntax
* parsec_JDFNAME_New()
* parsec_context_add_taskpool()
* parsec_data_collection_init()
*
* Can play with the HelloWorld bounds to show embarissingly parallel algorithm.
*
* @version 3.0
* @email parsec-users@icl.utk.edu
*
*/
/* Paste code to allocate a matrix in desc if cond_init is true */
#define PASTE_CODE_ALLOCATE_MATRIX(DC, COND, TYPE, INIT_PARAMS) \
TYPE##_t DC; \
if(COND) { \
TYPE##_init INIT_PARAMS; \
DC.mat = parsec_data_allocate((size_t)DC.super.nb_local_tiles * \
(size_t)DC.super.bsiz * \
(size_t)parsec_datadist_getsizeoftype(DC.super.mtype)); \
parsec_data_collection_set_key((parsec_data_collection_t*)&DC, #DC); \
}
#include <math.h>
#include "parsec.h"
#include "parsec/data_dist/matrix/matrix.h"
#include "parsec/data_dist/matrix/two_dim_rectangle_cyclic.h"
#define CHUNK_SIZE_X 2
#define CHUNK_SIZE_Y 2
#define CHUNK_SIZE_Z 2
#define MATRIX_M 4 // M rows
#define MATRIX_N 4 // N columns
#define MATRIX_K 8 // depth
#define TILE_SIZE 8
#define CHUNK_NUMBER_X (MATRIX_M/CHUNK_SIZE_X)
#define CHUNK_NUMBER_Y (MATRIX_N/CHUNK_SIZE_Y)
#define CHUNK_NUMBER_Z (MATRIX_K/CHUNK_SIZE_Z)
%}
descA [ type="parsec_matrix_block_cyclic_t*" ]
descB [ type="parsec_matrix_block_cyclic_t*" ]
descC [ type="parsec_matrix_block_cyclic_t*" ]
rank [ type="int" ]
nodes [ type="int" ]
matrix_size_m [ type="int" ] // row number
matrix_size_n [ type="int" ] // column number
matrix_size_k [ type="int" ]
chunk_number_x [ type="int" ]
chunk_number_y [ type="int" ]
chunk_number_z [ type="int" ]
chunk_size_x [ type="int" ]
chunk_size_y [ type="int" ]
chunk_size_z [ type="int" ]
FillA(m, k)
m = 0 .. matrix_size_m-1
k = 0 .. matrix_size_k-1
: descA(m, k)
RW A <- descA(m, k)
-> A GEMM(m, 0 .. matrix_size_n-1, k, m/chunk_number_x, 0 .. chunk_number_y-1, 0)
BODY
//int rank = this_task->parsec_context->my_rank;
double *matA = A;
printf("process %d fills matrix A at coordinates %d, %d\n", rank, m, k);
for(int i=0;i<TILE_SIZE*TILE_SIZE;++i)
{
//matA[i] = (double)((151+i+i*i*8)%256);
matA[i] = 1;
}
END
FillB(k, n)
n = 0 .. matrix_size_n-1
k = 0 .. matrix_size_k-1
: descB(k, n)
RW B <- descB(k, n)
-> B GEMM(0 .. matrix_size_m-1, n, k, 0 .. chunk_number_x-1, n/chunk_number_y, 0)
BODY
double *matB = B;
for(int i=0;i<TILE_SIZE*TILE_SIZE;++i)
{
//matB[i] = (double)((151+i+i*i*8)%256);
matB[i] = 1;
}
END
/*
Sync(x, y, z)
x = 0 .. chunk_number_x-1
y = 0 .. chunk_number_y-1
z = 0 .. chunk_number_z-1
// TODO check
: descC(x, y)
CTL X <- X GEMM(
x*chunk_size_x .. (x+1)*chunk_size_x-1,
y*chunk_size_y .. (y+1)*chunk_size_y-1,
(z+1)*chunk_size_z-1,
x, y, z)
-> X GEMM(
x*chunk_size_x .. (x+1)*chunk_size_x-1,
y*chunk_size_y .. (y+1)*chunk_size_y-1,
(z+1)*chunk_size_z,
x, y, z+1)
BODY
//printf("Syncing ... (%d, %d, %d) (depends on (%d-%d, %d-%d, %d))\n", x, y, z,
// x*chunk_size_x, (x+1)*chunk_size_x-1,
// y*chunk_size_y, (y+1)*chunk_size_y-1,
// (z+1)*chunk_size_z-1);
printf("Syncing ... (%d, %d, %d) (will liberate GEMM(%d-%d, %d-%d, %d, %d, %d, %d))\n", x, y, z,
x*chunk_size_x, (x+1)*chunk_size_x-1,
y*chunk_size_y, (y+1)*chunk_size_y-1,
(z+1)*chunk_size_z,
x, y, z+1);
END
*/
GEMM(m, n, k, x, y, z)
m = 0 .. matrix_size_m-1
n = 0 .. matrix_size_n-1
k = 0 .. matrix_size_k-1
x = 0 .. chunk_number_x-1
y = 0 .. chunk_number_y-1
z = 0 .. chunk_number_z-1
: descC(m, n)
/*
READ A <- A FillA(m, k)
READ B <- B FillB(k, n)
RW C <- (k==0) ? descC(m, n) : C GEMM(m, n, k-1)
-> (k<matrix_size_k-1) ? C GEMM(m, n, k+1) : C PrintC(m, n)
// old
RW C <- (k==0) ? descC(m, n) : C GEMM(m, n, k-1, x, y, (k%chunk_size_z==0)?-1:z)
-> (k<matrix_size_k-1) ? C GEMM(m, n, k+1, x, y, (k%chunk_size_z==chunk_size_z-1)?-1:z)// : C PrintC(m, n)
*/
READ A <- A FillA(m, k)
READ B <- B FillB(k, n)
/*
RW C <- (k==0) ? descC(m, n) : C GEMM(m, n, k-1, x, y, (k-1)/chunk_size_z)
-> (k<matrix_size_k-1) ? C GEMM(m, n, k+1, x, y, (k+1)/chunk_size_z)
*/
RW C <- (k==0) ? descC(m, n) : C GEMM(m, n, k-1, x, y, z)
-> (k<matrix_size_k-1) ? C GEMM(m, n, k+1, x, y, z) : C PrintC(m, n)
/*
CTL X <- (k%chunk_size_z==0 && k != 0) ? X Sync(x, y, z-1)
-> (k%chunk_size_z==chunk_size_z-1 && k != matrix_size_k-1) ? X Sync(x, y, z)
*/
BODY
//printf("[GEMM] process %d is at coordinates %d, %d, (k=%d), chunk=(%d, %d, %d)\n", rank, m, n, k, x, y, z);
printf("[GEMM] GEMM(%d, %d, %d, %d, %d, %d) will liberate GEMM(%d, %d, %d, %d, %d, %d)\n",
m, n, k, x, y, z,
m, n, k+1, x, y, (k+1)/chunk_size_z);
double *matA = A;
double *matB = B;
double *matC = C;
for(int i=0;i<TILE_SIZE;++i)
{
for(int j=0;j<TILE_SIZE;++j)
{
for(int k=0;k<TILE_SIZE;++k)
{
matC[i+j*TILE_SIZE] += matA[i+k*TILE_SIZE]*matB[k+j*TILE_SIZE];
}
}
}
END
PrintC(m, n)
m = 0 .. matrix_size_m-1
n = 0 .. matrix_size_n-1
: descC(m, n)
READ C <- C GEMM(m, n, matrix_size_k-1, m/chunk_number_x, n/chunk_number_y, chunk_number_z-1)
BODY
double *matC = C;
printf("process %d matC %d, %d = %f\n", rank, m, n, matC[0]);
END
extern "C" %{
int main(int argc, char *argv[])
{
parsec_context_t* parsec;
int rc;
int rank, world;
parsec_test_taskpool_t *tp;
//int mycounter;
parsec_arena_datatype_t adt;
parsec_datatype_t otype;
#if defined(PARSEC_HAVE_MPI)
{
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
}
MPI_Comm_size(MPI_COMM_WORLD, &world);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#else
world = 1;
rank = 0;
#endif
parsec = parsec_init(-1, &argc, &argv);
//mycounter = 300 + rank;
int test_data = 0;
int nodes = world;
//int KP = sqrt(nodes);
//int KQ = nodes/KP;
int KP = 2;
int KQ = 2;
PASTE_CODE_ALLOCATE_MATRIX(descA, true, parsec_matrix_block_cyclic, (
&descA,
PARSEC_MATRIX_DOUBLE,
PARSEC_MATRIX_TILE,
rank,
TILE_SIZE, TILE_SIZE, /* Tile size */
MATRIX_M*TILE_SIZE, MATRIX_K*TILE_SIZE, /* Global matrix size (what is stored)*/
0, 0, /* Staring point in the global matrix */
MATRIX_M, MATRIX_K, /* Submatrix size (the one concerned by the computation */
KP, KQ, /* process process grid*/
1, 1, /* k-cyclicity */
0, 0) /* starting point on the process grid*/
);
PASTE_CODE_ALLOCATE_MATRIX(descB, true, parsec_matrix_block_cyclic, (
&descB,
PARSEC_MATRIX_DOUBLE,
PARSEC_MATRIX_TILE,
rank,
TILE_SIZE, TILE_SIZE, /* Tile size */
MATRIX_K*TILE_SIZE, MATRIX_N*TILE_SIZE, /* Global matrix size (what is stored)*/
0, 0, /* Staring point in the global matrix */
MATRIX_K, MATRIX_N, /* Submatrix size (the one concerned by the computation */
KP, KQ, /* process process grid*/
1, 1, /* k-cyclicity */
0, 0) /* starting point on the process grid*/
);
PASTE_CODE_ALLOCATE_MATRIX(descC, true, parsec_matrix_block_cyclic, (
&descC,
PARSEC_MATRIX_DOUBLE,
PARSEC_MATRIX_TILE,
rank,
TILE_SIZE, TILE_SIZE, /* Tile size */
MATRIX_M*TILE_SIZE, MATRIX_N*TILE_SIZE, /* Global matrix size (what is stored)*/
0, 0, /* Staring point in the global matrix */
MATRIX_M, MATRIX_N, /* Submatrix size (the one concerned by the computation */
KP, KQ, /* process process grid*/
1, 1, /* k-cyclicity */
0, 0) /* starting point on the process grid*/
);
parsec_translate_matrix_type(PARSEC_MATRIX_DOUBLE, &otype);
parsec_add2arena_rect(&adt, otype,
descC.super.mb, descC.super.nb, descC.super.mb);
tp = (parsec_test_taskpool_t*)parsec_test_new(&descA, &descB, &descC, rank, world, MATRIX_M, MATRIX_N, MATRIX_K, CHUNK_NUMBER_X, CHUNK_NUMBER_Y, CHUNK_NUMBER_Z, CHUNK_SIZE_X, CHUNK_SIZE_Y, CHUNK_SIZE_Z);
assert( NULL != tp );
tp->arenas_datatypes[PARSEC_test_DEFAULT_ADT_IDX] = adt;
PARSEC_OBJ_RETAIN(adt.arena);
rc = parsec_context_add_taskpool( parsec, (parsec_taskpool_t*)tp );
PARSEC_CHECK_ERROR(rc, "parsec_context_add_taskpool");
rc = parsec_context_start(parsec);
PARSEC_CHECK_ERROR(rc, "parsec_context_start");
rc = parsec_context_wait(parsec);
PARSEC_CHECK_ERROR(rc, "parsec_context_wait");
printf("final : %f\n", ((double*)(descA.mat))[0]);
parsec_taskpool_free(&tp->super);
parsec_data_free(descA.mat);
parsec_tiled_matrix_destroy( (parsec_tiled_matrix_t*)&descA);
parsec_data_free(descB.mat);
parsec_tiled_matrix_destroy( (parsec_tiled_matrix_t*)&descB);
parsec_data_free(descC.mat);
parsec_tiled_matrix_destroy( (parsec_tiled_matrix_t*)&descC);
parsec_fini(&parsec);
#if defined(PARSEC_HAVE_MPI)
MPI_Finalize();
#endif
return 0;
}
%}