1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : main.c (for convol application) |
---|
3 | // Date : june 2014 |
---|
4 | // author : Alain Greiner |
---|
5 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
6 | // This multi-threaded application application implements a 2D convolution product. |
---|
7 | // The convolution kernel is [201]*[35] pixels, but it can be factored in two |
---|
8 | // independant line and column convolution products. |
---|
9 | // It can run on a multi-processors, multi-clusters architecture, with one thread |
---|
10 | // per processor. |
---|
11 | // |
---|
12 | // The (1024 * 1024) pixels image is read from a file (2 bytes per pixel). |
---|
13 | // |
---|
14 | // - number of clusters containing processors must be power of 2 no larger than 256. |
---|
15 | // - number of processors per cluster must be power of 2 no larger than 8. |
---|
16 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
17 | |
---|
18 | #include "stdio.h" |
---|
19 | #include "stdlib.h" |
---|
20 | #include "user_barrier.h" |
---|
21 | #include "malloc.h" |
---|
22 | |
---|
23 | #define USE_SQT_BARRIER 1 |
---|
24 | #define VERBOSE 0 |
---|
25 | #define SUPER_VERBOSE 0 |
---|
26 | |
---|
27 | #define X_SIZE_MAX 16 |
---|
28 | #define Y_SIZE_MAX 16 |
---|
29 | #define PROCS_MAX 8 |
---|
30 | #define CLUSTERS_MAX (X_SIZE_MAX * Y_SIZE_MAX) |
---|
31 | |
---|
32 | #define INITIAL_DISPLAY_ENABLE 0 |
---|
33 | #define FINAL_DISPLAY_ENABLE 1 |
---|
34 | |
---|
35 | #define PIXEL_SIZE 2 |
---|
36 | #define NL 1024 |
---|
37 | #define NP 1024 |
---|
38 | #define NB_PIXELS (NP * NL) |
---|
39 | #define FRAME_SIZE (NB_PIXELS * PIXEL_SIZE) |
---|
40 | |
---|
41 | #define TA(c,l,p) (A[c][((NP) * (l)) + (p)]) |
---|
42 | #define TB(c,p,l) (B[c][((NL) * (p)) + (l)]) |
---|
43 | #define TC(c,l,p) (C[c][((NP) * (l)) + (p)]) |
---|
44 | #define TD(c,l,p) (D[c][((NP) * (l)) + (p)]) |
---|
45 | #define TZ(c,l,p) (Z[c][((NP) * (l)) + (p)]) |
---|
46 | |
---|
47 | #define max(x,y) ((x) > (y) ? (x) : (y)) |
---|
48 | #define min(x,y) ((x) < (y) ? (x) : (y)) |
---|
49 | |
---|
50 | // global instrumentation counters (cluster_id, lpid] |
---|
51 | |
---|
52 | unsigned int START[CLUSTERS_MAX][PROCS_MAX]; |
---|
53 | unsigned int H_BEG[CLUSTERS_MAX][PROCS_MAX]; |
---|
54 | unsigned int H_END[CLUSTERS_MAX][PROCS_MAX]; |
---|
55 | unsigned int V_BEG[CLUSTERS_MAX][PROCS_MAX]; |
---|
56 | unsigned int V_END[CLUSTERS_MAX][PROCS_MAX]; |
---|
57 | unsigned int D_BEG[CLUSTERS_MAX][PROCS_MAX]; |
---|
58 | unsigned int D_END[CLUSTERS_MAX][PROCS_MAX]; |
---|
59 | |
---|
60 | // global synchronization barrier |
---|
61 | |
---|
62 | #if USE_SQT_BARRIER |
---|
63 | giet_sqt_barrier_t barrier; |
---|
64 | #else |
---|
65 | giet_barrier_t barrier; |
---|
66 | #endif |
---|
67 | |
---|
68 | volatile unsigned int barrier_init_ok = 0; |
---|
69 | volatile unsigned int load_image_ok = 0; |
---|
70 | volatile unsigned int instrumentation_ok = 0; |
---|
71 | |
---|
72 | // global pointers on distributed buffers in all clusters |
---|
73 | unsigned short * GA[CLUSTERS_MAX]; |
---|
74 | int * GB[CLUSTERS_MAX]; |
---|
75 | int * GC[CLUSTERS_MAX]; |
---|
76 | int * GD[CLUSTERS_MAX]; |
---|
77 | unsigned char * GZ[CLUSTERS_MAX]; |
---|
78 | |
---|
79 | /////////////////////////////////////////// |
---|
80 | __attribute__ ((constructor)) void main() |
---|
81 | /////////////////////////////////////////// |
---|
82 | { |
---|
83 | ////////////////////////////////// |
---|
84 | // convolution kernel parameters |
---|
85 | // The content of this section is |
---|
86 | // Philips proprietary information. |
---|
87 | /////////////////////////////////// |
---|
88 | |
---|
89 | int vnorm = 115; |
---|
90 | int vf[35] = { 1, 1, 2, 2, 2, |
---|
91 | 2, 3, 3, 3, 4, |
---|
92 | 4, 4, 4, 5, 5, |
---|
93 | 5, 5, 5, 5, 5, |
---|
94 | 5, 5, 4, 4, 4, |
---|
95 | 4, 3, 3, 3, 2, |
---|
96 | 2, 2, 2, 1, 1 }; |
---|
97 | |
---|
98 | int hrange = 100; |
---|
99 | int hnorm = 201; |
---|
100 | |
---|
101 | unsigned int date = 0; |
---|
102 | |
---|
103 | int c; // cluster index for loops |
---|
104 | int l; // line index for loops |
---|
105 | int p; // pixel index for loops |
---|
106 | int z; // vertical filter index for loops |
---|
107 | |
---|
108 | // plat-form parameters |
---|
109 | unsigned int x_size; // number of clusters in a row |
---|
110 | unsigned int y_size; // number of clusters in a column |
---|
111 | unsigned int nprocs; // number of processors per cluster |
---|
112 | |
---|
113 | giet_procs_number( &x_size , &y_size , &nprocs ); |
---|
114 | |
---|
115 | // processor identifiers |
---|
116 | unsigned int x; // x coordinate |
---|
117 | unsigned int y; // y coordinate |
---|
118 | unsigned int lpid; // local proc/task id |
---|
119 | giet_proc_xyp( &x, &y, &lpid ); |
---|
120 | |
---|
121 | int file = 0; // file descriptor |
---|
122 | unsigned int nclusters = x_size * y_size; // number of clusters |
---|
123 | unsigned int cluster_id = (x * y_size) + y; // continuous cluster index |
---|
124 | unsigned int task_id = (cluster_id * nprocs) + lpid; // continuous task index |
---|
125 | unsigned int ntasks = nclusters * nprocs; // number of tasks |
---|
126 | unsigned int frame_size = FRAME_SIZE; // total size (bytes) |
---|
127 | unsigned int nblocks = frame_size / 512; // number of blocks/frame |
---|
128 | |
---|
129 | unsigned int lines_per_task = NL / ntasks; // lines per task |
---|
130 | unsigned int lines_per_cluster = NL / nclusters; // lines per cluster |
---|
131 | unsigned int pixels_per_task = NP / ntasks; // columns per task |
---|
132 | unsigned int pixels_per_cluster = NP / nclusters; // columns per cluster |
---|
133 | |
---|
134 | int first, last; |
---|
135 | |
---|
136 | date = giet_proctime(); |
---|
137 | START[cluster_id][lpid] = date; |
---|
138 | |
---|
139 | #if VERBOSE |
---|
140 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts at cycle %d\n", x,y,lpid, date ); |
---|
141 | #endif |
---|
142 | |
---|
143 | // parameters checking |
---|
144 | |
---|
145 | if ((nprocs != 1) && (nprocs != 2) && (nprocs != 4) && (nprocs != 8)) |
---|
146 | giet_exit( "[CONVOL ERROR] NB_PROCS_MAX must be 1, 2, 4 or 8\n"); |
---|
147 | |
---|
148 | if ((x_size!=1) && (x_size!=2) && (x_size!=4) && (x_size!=8) && (x_size!=16)) |
---|
149 | giet_exit( "[CONVOL ERROR] x_size must be 1, 2, 4, 8, 16\n"); |
---|
150 | |
---|
151 | if ((y_size!=1) && (y_size!=2) && (y_size!=4) && (y_size!=8) && (y_size!=16)) |
---|
152 | giet_exit( "[CONVOL ERROR] y_size must be 1, 2, 4, 8, 16\n"); |
---|
153 | |
---|
154 | if ( NL % nclusters != 0 ) |
---|
155 | giet_exit( "[CONVOL ERROR] CLUSTERS_MAX must be a divider of NL"); |
---|
156 | |
---|
157 | if ( NP % nclusters != 0 ) |
---|
158 | giet_exit( "[CONVOL ERROR] CLUSTERS_MAX must be a divider of NP"); |
---|
159 | |
---|
160 | |
---|
161 | /////////////////////////////////////////////////////////////////// |
---|
162 | // task[0][0][0] makes barrier initialisation |
---|
163 | /////////////////////////////////////////////////////////////////// |
---|
164 | |
---|
165 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
166 | { |
---|
167 | giet_shr_printf("\n[CONVOL] task[0,0,0] starts barrier init at cycle %d\n" |
---|
168 | "- CLUSTERS = %d\n" |
---|
169 | "- PROCS = %d\n" |
---|
170 | "- TASKS = %d\n" |
---|
171 | "- BLOCKS = %d\n", |
---|
172 | giet_proctime(), nclusters, nprocs, ntasks, nblocks ); |
---|
173 | #if USE_SQT_BARRIER |
---|
174 | sqt_barrier_init( &barrier, x_size , y_size , nprocs ); |
---|
175 | #else |
---|
176 | barrier_init( &barrier, ntasks ); |
---|
177 | #endif |
---|
178 | |
---|
179 | giet_shr_printf( "\n[CONVOL] task[0,0,0] completes barrier init at cycle %d\n", |
---|
180 | giet_proctime() ); |
---|
181 | |
---|
182 | barrier_init_ok = 1; |
---|
183 | } |
---|
184 | else |
---|
185 | { |
---|
186 | while ( barrier_init_ok == 0 ); |
---|
187 | } |
---|
188 | |
---|
189 | /////////////////////////////////////////////////////////////////// |
---|
190 | // All task[x][y][0] allocate the global buffers in cluster(x,y) |
---|
191 | // These buffers mut be sector-aligned. |
---|
192 | /////////////////////////////////////////////////////////////////// |
---|
193 | if ( lpid == 0 ) |
---|
194 | { |
---|
195 | |
---|
196 | #if VERBOSE |
---|
197 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] enters malloc at cycle %d\n", |
---|
198 | x,y,lpid, date ); |
---|
199 | #endif |
---|
200 | |
---|
201 | GA[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters) , x , y ); |
---|
202 | GB[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)*2 , x , y ); |
---|
203 | GC[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)*2 , x , y ); |
---|
204 | GD[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)*2 , x , y ); |
---|
205 | GZ[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)/2 , x , y ); |
---|
206 | |
---|
207 | #if VERBOSE |
---|
208 | giet_shr_printf( "\n[CONVOL] Shared Buffer Virtual Addresses in cluster(%d,%d)\n" |
---|
209 | "### GA = %x\n" |
---|
210 | "### GB = %x\n" |
---|
211 | "### GC = %x\n" |
---|
212 | "### GD = %x\n" |
---|
213 | "### GZ = %x\n", |
---|
214 | x, y, |
---|
215 | GA[cluster_id], |
---|
216 | GB[cluster_id], |
---|
217 | GC[cluster_id], |
---|
218 | GD[cluster_id], |
---|
219 | GZ[cluster_id] ); |
---|
220 | #endif |
---|
221 | } |
---|
222 | |
---|
223 | /////////////////////////////// |
---|
224 | #if USE_SQT_BARRIER |
---|
225 | sqt_barrier_wait( &barrier ); |
---|
226 | #else |
---|
227 | barrier_wait( &barrier ); |
---|
228 | #endif |
---|
229 | |
---|
230 | /////////////////////////////////////////////////////////////////// |
---|
231 | // All tasks initialise in their private stack a copy of the |
---|
232 | // arrays of pointers on the shared, distributed buffers. |
---|
233 | /////////////////////////////////////////////////////////////////// |
---|
234 | |
---|
235 | unsigned short * A[CLUSTERS_MAX]; |
---|
236 | int * B[CLUSTERS_MAX]; |
---|
237 | int * C[CLUSTERS_MAX]; |
---|
238 | int * D[CLUSTERS_MAX]; |
---|
239 | unsigned char * Z[CLUSTERS_MAX]; |
---|
240 | |
---|
241 | for (c = 0; c < nclusters; c++) |
---|
242 | { |
---|
243 | A[c] = GA[c]; |
---|
244 | B[c] = GB[c]; |
---|
245 | C[c] = GC[c]; |
---|
246 | D[c] = GD[c]; |
---|
247 | Z[c] = GZ[c]; |
---|
248 | } |
---|
249 | |
---|
250 | /////////////////////////////////////////////////////////////////////////// |
---|
251 | // task[0,0,0] open the file containing image, and load it from disk |
---|
252 | // to all A[c] buffers (nblocks / nclusters loaded in each cluster). |
---|
253 | // Other tasks are waiting on the init_ok condition. |
---|
254 | ////////////////////////////////////////////////////////////////////////// |
---|
255 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
256 | { |
---|
257 | // open file |
---|
258 | file = giet_fat_open("misc/philips_image.raw", 0 ); |
---|
259 | if ( file < 0 ) giet_exit( "[CONVOL ERROR] task[0,0,0] cannot open" |
---|
260 | " file misc/philips_image.raw" ); |
---|
261 | |
---|
262 | giet_shr_printf( "\n[CONVOL] task[0,0,0] open file misc/philips_image.raw" |
---|
263 | " at cycle %d\n", giet_proctime() ); |
---|
264 | |
---|
265 | for ( c = 0 ; c < nclusters ; c++ ) |
---|
266 | { |
---|
267 | giet_shr_printf( "\n[CONVOL] task[0,0,0] starts load " |
---|
268 | "for cluster %d at cycle %d\n", c, giet_proctime() ); |
---|
269 | |
---|
270 | giet_fat_read( file, |
---|
271 | A[c], |
---|
272 | nblocks/nclusters, |
---|
273 | (nblocks/nclusters)*c ); |
---|
274 | |
---|
275 | giet_shr_printf( "\n[CONVOL] task[0,0,0] completes load " |
---|
276 | "for cluster %d at cycle %d\n", c, giet_proctime() ); |
---|
277 | } |
---|
278 | load_image_ok = 1; |
---|
279 | } |
---|
280 | else |
---|
281 | { |
---|
282 | while ( load_image_ok == 0 ); |
---|
283 | } |
---|
284 | |
---|
285 | ///////////////////////////////////////////////////////////////////////////// |
---|
286 | // Optionnal parallel display of the initial image stored in A[c] buffers. |
---|
287 | // Eah task displays (NL/ntasks) lines. (one byte per pixel). |
---|
288 | ///////////////////////////////////////////////////////////////////////////// |
---|
289 | |
---|
290 | if ( INITIAL_DISPLAY_ENABLE ) |
---|
291 | { |
---|
292 | |
---|
293 | #if VERBOSE |
---|
294 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts initial display" |
---|
295 | " at cycle %d\n", |
---|
296 | x, y, lpid, giet_proctime() ); |
---|
297 | #endif |
---|
298 | |
---|
299 | unsigned int line; |
---|
300 | unsigned int offset = lines_per_task * lpid; |
---|
301 | |
---|
302 | for ( l = 0 ; l < lines_per_task ; l++ ) |
---|
303 | { |
---|
304 | line = offset + l; |
---|
305 | |
---|
306 | for ( p = 0 ; p < NP ; p++ ) |
---|
307 | { |
---|
308 | TZ(cluster_id, line, p) = (unsigned char)(TA(cluster_id, line, p) >> 8); |
---|
309 | } |
---|
310 | |
---|
311 | giet_fbf_sync_write( NP*(l + (task_id * lines_per_task) ), |
---|
312 | &TZ(cluster_id, line, 0), |
---|
313 | NP); |
---|
314 | } |
---|
315 | |
---|
316 | #if VERBOSE |
---|
317 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes initial display" |
---|
318 | " at cycle %d\n", |
---|
319 | x, y, lpid, giet_proctime() ); |
---|
320 | #endif |
---|
321 | |
---|
322 | //////////////////////////// |
---|
323 | #if USE_SQT_BARRIER |
---|
324 | sqt_barrier_wait( &barrier ); |
---|
325 | #else |
---|
326 | barrier_wait( &barrier ); |
---|
327 | #endif |
---|
328 | |
---|
329 | } |
---|
330 | |
---|
331 | //////////////////////////////////////////////////////// |
---|
332 | // parallel horizontal filter : |
---|
333 | // B <= transpose(FH(A)) |
---|
334 | // D <= A - FH(A) |
---|
335 | // Each task computes (NL/ntasks) lines |
---|
336 | // The image must be extended : |
---|
337 | // if (z<0) TA(cluster_id,l,z) == TA(cluster_id,l,0) |
---|
338 | // if (z>NP-1) TA(cluster_id,l,z) == TA(cluster_id,l,NP-1) |
---|
339 | //////////////////////////////////////////////////////// |
---|
340 | |
---|
341 | date = giet_proctime(); |
---|
342 | H_BEG[cluster_id][lpid] = date; |
---|
343 | |
---|
344 | #if VERBOSE |
---|
345 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts horizontal filter" |
---|
346 | " at cycle %d\n", |
---|
347 | x, y, lpid, date ); |
---|
348 | #else |
---|
349 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
350 | giet_shr_printf( "\n[CONVOL] task[0,0,0] starts horizontal filter" |
---|
351 | " at cycle %d\n", date ); |
---|
352 | #endif |
---|
353 | |
---|
354 | // l = absolute line index / p = absolute pixel index |
---|
355 | // first & last define which lines are handled by a given task |
---|
356 | |
---|
357 | first = task_id * lines_per_task; |
---|
358 | last = first + lines_per_task; |
---|
359 | |
---|
360 | for (l = first; l < last; l++) |
---|
361 | { |
---|
362 | // src_c and src_l are the cluster index and the line index for A & D |
---|
363 | int src_c = l / lines_per_cluster; |
---|
364 | int src_l = l % lines_per_cluster; |
---|
365 | |
---|
366 | // We use the specific values of the horizontal ep-filter for optimisation: |
---|
367 | // sum(p) = sum(p-1) + TA[p+hrange] - TA[p-hrange-1] |
---|
368 | // To minimize the number of tests, the loop on pixels is split in three domains |
---|
369 | |
---|
370 | int sum_p = (hrange + 2) * TA(src_c, src_l, 0); |
---|
371 | for (z = 1; z < hrange; z++) |
---|
372 | { |
---|
373 | sum_p = sum_p + TA(src_c, src_l, z); |
---|
374 | } |
---|
375 | |
---|
376 | // first domain : from 0 to hrange |
---|
377 | for (p = 0; p < hrange + 1; p++) |
---|
378 | { |
---|
379 | // dst_c and dst_p are the cluster index and the pixel index for B |
---|
380 | int dst_c = p / pixels_per_cluster; |
---|
381 | int dst_p = p % pixels_per_cluster; |
---|
382 | sum_p = sum_p + (int) TA(src_c, src_l, p + hrange) - (int) TA(src_c, src_l, 0); |
---|
383 | TB(dst_c, dst_p, l) = sum_p / hnorm; |
---|
384 | TD(src_c, src_l, p) = (int) TA(src_c, src_l, p) - sum_p / hnorm; |
---|
385 | } |
---|
386 | // second domain : from (hrange+1) to (NP-hrange-1) |
---|
387 | for (p = hrange + 1; p < NP - hrange; p++) |
---|
388 | { |
---|
389 | // dst_c and dst_p are the cluster index and the pixel index for B |
---|
390 | int dst_c = p / pixels_per_cluster; |
---|
391 | int dst_p = p % pixels_per_cluster; |
---|
392 | sum_p = sum_p + (int) TA(src_c, src_l, p + hrange) |
---|
393 | - (int) TA(src_c, src_l, p - hrange - 1); |
---|
394 | TB(dst_c, dst_p, l) = sum_p / hnorm; |
---|
395 | TD(src_c, src_l, p) = (int) TA(src_c, src_l, p) - sum_p / hnorm; |
---|
396 | } |
---|
397 | // third domain : from (NP-hrange) to (NP-1) |
---|
398 | for (p = NP - hrange; p < NP; p++) |
---|
399 | { |
---|
400 | // dst_c and dst_p are the cluster index and the pixel index for B |
---|
401 | int dst_c = p / pixels_per_cluster; |
---|
402 | int dst_p = p % pixels_per_cluster; |
---|
403 | sum_p = sum_p + (int) TA(src_c, src_l, NP - 1) |
---|
404 | - (int) TA(src_c, src_l, p - hrange - 1); |
---|
405 | TB(dst_c, dst_p, l) = sum_p / hnorm; |
---|
406 | TD(src_c, src_l, p) = (int) TA(src_c, src_l, p) - sum_p / hnorm; |
---|
407 | } |
---|
408 | |
---|
409 | #if SUPER_VERBOSE |
---|
410 | giet_shr_printf(" - line %d computed at cycle %d\n", l, giet_proctime() ); |
---|
411 | #endif |
---|
412 | |
---|
413 | } |
---|
414 | |
---|
415 | date = giet_proctime(); |
---|
416 | H_END[cluster_id][lpid] = date; |
---|
417 | |
---|
418 | #if VERBOSE |
---|
419 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes horizontal filter" |
---|
420 | " at cycle %d\n", |
---|
421 | x, y, lpid, date ); |
---|
422 | #else |
---|
423 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
424 | giet_shr_printf( "\n[CONVOL] task[0,0,0] completes horizontal filter" |
---|
425 | " at cycle %d\n", date ); |
---|
426 | #endif |
---|
427 | |
---|
428 | ///////////////////////////// |
---|
429 | #if USE_SQT_BARRIER |
---|
430 | sqt_barrier_wait( &barrier ); |
---|
431 | #else |
---|
432 | barrier_wait( &barrier ); |
---|
433 | #endif |
---|
434 | |
---|
435 | |
---|
436 | /////////////////////////////////////////////////////////////// |
---|
437 | // parallel vertical filter : |
---|
438 | // C <= transpose(FV(B)) |
---|
439 | // Each task computes (NP/ntasks) columns |
---|
440 | // The image must be extended : |
---|
441 | // if (l<0) TB(cluster_id,p,l) == TB(cluster_id,p,0) |
---|
442 | // if (l>NL-1) TB(cluster_id,p,l) == TB(cluster_id,p,NL-1) |
---|
443 | /////////////////////////////////////////////////////////////// |
---|
444 | |
---|
445 | date = giet_proctime(); |
---|
446 | V_BEG[cluster_id][lpid] = date; |
---|
447 | |
---|
448 | #if VERBOSE |
---|
449 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts vertical filter" |
---|
450 | " at cycle %d\n", |
---|
451 | x, y, lpid, date ); |
---|
452 | #else |
---|
453 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
454 | giet_shr_printf( "\n[CONVOL] task[0,0,0] starts vertical filter" |
---|
455 | " at cycle %d\n", date ); |
---|
456 | #endif |
---|
457 | |
---|
458 | // l = absolute line index / p = absolute pixel index |
---|
459 | // first & last define which pixels are handled by a given task |
---|
460 | |
---|
461 | first = task_id * pixels_per_task; |
---|
462 | last = first + pixels_per_task; |
---|
463 | |
---|
464 | for (p = first; p < last; p++) |
---|
465 | { |
---|
466 | // src_c and src_p are the cluster index and the pixel index for B |
---|
467 | int src_c = p / pixels_per_cluster; |
---|
468 | int src_p = p % pixels_per_cluster; |
---|
469 | |
---|
470 | int sum_l; |
---|
471 | |
---|
472 | // We use the specific values of the vertical ep-filter |
---|
473 | // To minimize the number of tests, the NL lines are split in three domains |
---|
474 | |
---|
475 | // first domain : explicit computation for the first 18 values |
---|
476 | for (l = 0; l < 18; l++) |
---|
477 | { |
---|
478 | // dst_c and dst_l are the cluster index and the line index for C |
---|
479 | int dst_c = l / lines_per_cluster; |
---|
480 | int dst_l = l % lines_per_cluster; |
---|
481 | |
---|
482 | for (z = 0, sum_l = 0; z < 35; z++) |
---|
483 | { |
---|
484 | sum_l = sum_l + vf[z] * TB(src_c, src_p, max(l - 17 + z,0) ); |
---|
485 | } |
---|
486 | TC(dst_c, dst_l, p) = sum_l / vnorm; |
---|
487 | } |
---|
488 | // second domain |
---|
489 | for (l = 18; l < NL - 17; l++) |
---|
490 | { |
---|
491 | // dst_c and dst_l are the cluster index and the line index for C |
---|
492 | int dst_c = l / lines_per_cluster; |
---|
493 | int dst_l = l % lines_per_cluster; |
---|
494 | |
---|
495 | sum_l = sum_l + TB(src_c, src_p, l + 4) |
---|
496 | + TB(src_c, src_p, l + 8) |
---|
497 | + TB(src_c, src_p, l + 11) |
---|
498 | + TB(src_c, src_p, l + 15) |
---|
499 | + TB(src_c, src_p, l + 17) |
---|
500 | - TB(src_c, src_p, l - 5) |
---|
501 | - TB(src_c, src_p, l - 9) |
---|
502 | - TB(src_c, src_p, l - 12) |
---|
503 | - TB(src_c, src_p, l - 16) |
---|
504 | - TB(src_c, src_p, l - 18); |
---|
505 | |
---|
506 | TC(dst_c, dst_l, p) = sum_l / vnorm; |
---|
507 | } |
---|
508 | // third domain |
---|
509 | for (l = NL - 17; l < NL; l++) |
---|
510 | { |
---|
511 | // dst_c and dst_l are the cluster index and the line index for C |
---|
512 | int dst_c = l / lines_per_cluster; |
---|
513 | int dst_l = l % lines_per_cluster; |
---|
514 | |
---|
515 | sum_l = sum_l + TB(src_c, src_p, min(l + 4, NL - 1)) |
---|
516 | + TB(src_c, src_p, min(l + 8, NL - 1)) |
---|
517 | + TB(src_c, src_p, min(l + 11, NL - 1)) |
---|
518 | + TB(src_c, src_p, min(l + 15, NL - 1)) |
---|
519 | + TB(src_c, src_p, min(l + 17, NL - 1)) |
---|
520 | - TB(src_c, src_p, l - 5) |
---|
521 | - TB(src_c, src_p, l - 9) |
---|
522 | - TB(src_c, src_p, l - 12) |
---|
523 | - TB(src_c, src_p, l - 16) |
---|
524 | - TB(src_c, src_p, l - 18); |
---|
525 | |
---|
526 | TC(dst_c, dst_l, p) = sum_l / vnorm; |
---|
527 | } |
---|
528 | |
---|
529 | #if SUPER_VERBOSE |
---|
530 | giet_shr_printf(" - column %d computed at cycle %d\n", p, giet_proctime()); |
---|
531 | #endif |
---|
532 | |
---|
533 | } |
---|
534 | |
---|
535 | date = giet_proctime(); |
---|
536 | V_END[cluster_id][lpid] = date; |
---|
537 | |
---|
538 | #if VERBOSE |
---|
539 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes vertical filter" |
---|
540 | " at cycle %d\n", |
---|
541 | x, y, lpid, date ); |
---|
542 | #else |
---|
543 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
544 | giet_shr_printf( "\n[CONVOL] task[0,0,0] completes vertical filter" |
---|
545 | " at cycle %d\n", date ); |
---|
546 | #endif |
---|
547 | |
---|
548 | //////////////////////////// |
---|
549 | #if USE_SQT_BARRIER |
---|
550 | sqt_barrier_wait( &barrier ); |
---|
551 | #else |
---|
552 | barrier_wait( &barrier ); |
---|
553 | #endif |
---|
554 | |
---|
555 | //////////////////////////////////////////////////////////////// |
---|
556 | // Optional parallel display of the final image Z <= D + C |
---|
557 | // Eah task displays (NL/ntasks) lines. (one byte per pixel). |
---|
558 | //////////////////////////////////////////////////////////////// |
---|
559 | |
---|
560 | if ( FINAL_DISPLAY_ENABLE ) |
---|
561 | { |
---|
562 | date = giet_proctime(); |
---|
563 | D_BEG[cluster_id][lpid] = date; |
---|
564 | |
---|
565 | #if VERBOSE |
---|
566 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] starts final display" |
---|
567 | " at cycle %d\n", |
---|
568 | x, y, lpid, date); |
---|
569 | #else |
---|
570 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
571 | giet_shr_printf( "\n[CONVOL] task[0,0,0] starts final display" |
---|
572 | " at cycle %d\n", date ); |
---|
573 | #endif |
---|
574 | |
---|
575 | unsigned int line; |
---|
576 | unsigned int offset = lines_per_task * lpid; |
---|
577 | |
---|
578 | for ( l = 0 ; l < lines_per_task ; l++ ) |
---|
579 | { |
---|
580 | line = offset + l; |
---|
581 | |
---|
582 | for ( p = 0 ; p < NP ; p++ ) |
---|
583 | { |
---|
584 | TZ(cluster_id, line, p) = |
---|
585 | (unsigned char)( (TD(cluster_id, line, p) + |
---|
586 | TC(cluster_id, line, p) ) >> 8 ); |
---|
587 | } |
---|
588 | |
---|
589 | giet_fbf_sync_write( NP*(l + (task_id * lines_per_task) ), |
---|
590 | &TZ(cluster_id, line, 0), |
---|
591 | NP); |
---|
592 | } |
---|
593 | |
---|
594 | date = giet_proctime(); |
---|
595 | D_END[cluster_id][lpid] = date; |
---|
596 | |
---|
597 | #if VERBOSE |
---|
598 | giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] completes final display" |
---|
599 | " at cycle %d\n", |
---|
600 | x, y, lpid, date); |
---|
601 | #else |
---|
602 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
603 | giet_shr_printf( "\n[CONVOL] task[0,0,0] completes final display" |
---|
604 | " at cycle %d\n", date ); |
---|
605 | #endif |
---|
606 | |
---|
607 | ////////////////////////////// |
---|
608 | #if USE_SQT_BARRIER |
---|
609 | sqt_barrier_wait( &barrier ); |
---|
610 | #else |
---|
611 | barrier_wait( &barrier ); |
---|
612 | #endif |
---|
613 | |
---|
614 | } |
---|
615 | |
---|
616 | ///////////////////////////////////////////////////////// |
---|
617 | // Task[0,0,0] makes the instrumentation |
---|
618 | ///////////////////////////////////////////////////////// |
---|
619 | |
---|
620 | if ( (x==0) && (y==0) && (lpid==0) ) |
---|
621 | { |
---|
622 | date = giet_proctime(); |
---|
623 | giet_shr_printf("\n[CONVOL] task[0,0,0] starts instrumentation" |
---|
624 | " at cycle %d\n\n", date ); |
---|
625 | |
---|
626 | int cc, pp; |
---|
627 | |
---|
628 | unsigned int min_start = 0xFFFFFFFF; |
---|
629 | unsigned int max_start = 0; |
---|
630 | |
---|
631 | unsigned int min_h_beg = 0xFFFFFFFF; |
---|
632 | unsigned int max_h_beg = 0; |
---|
633 | |
---|
634 | unsigned int min_h_end = 0xFFFFFFFF; |
---|
635 | unsigned int max_h_end = 0; |
---|
636 | |
---|
637 | unsigned int min_v_beg = 0xFFFFFFFF; |
---|
638 | unsigned int max_v_beg = 0; |
---|
639 | |
---|
640 | unsigned int min_v_end = 0xFFFFFFFF; |
---|
641 | unsigned int max_v_end = 0; |
---|
642 | |
---|
643 | unsigned int min_d_beg = 0xFFFFFFFF; |
---|
644 | unsigned int max_d_beg = 0; |
---|
645 | |
---|
646 | unsigned int min_d_end = 0xFFFFFFFF; |
---|
647 | unsigned int max_d_end = 0; |
---|
648 | |
---|
649 | for (cc = 0; cc < nclusters; cc++) |
---|
650 | { |
---|
651 | for (pp = 0; pp < nprocs; pp++ ) |
---|
652 | { |
---|
653 | if (START[cc][pp] < min_start) min_start = START[cc][pp]; |
---|
654 | if (START[cc][pp] > max_start) max_start = START[cc][pp]; |
---|
655 | |
---|
656 | if (H_BEG[cc][pp] < min_h_beg) min_h_beg = H_BEG[cc][pp]; |
---|
657 | if (H_BEG[cc][pp] > max_h_beg) max_h_beg = H_BEG[cc][pp]; |
---|
658 | |
---|
659 | if (H_END[cc][pp] < min_h_end) min_h_end = H_END[cc][pp]; |
---|
660 | if (H_END[cc][pp] > max_h_end) max_h_end = H_END[cc][pp]; |
---|
661 | |
---|
662 | if (V_BEG[cc][pp] < min_v_beg) min_v_beg = V_BEG[cc][pp]; |
---|
663 | if (V_BEG[cc][pp] > max_v_beg) max_v_beg = V_BEG[cc][pp]; |
---|
664 | |
---|
665 | if (V_END[cc][pp] < min_v_end) min_v_end = V_END[cc][pp]; |
---|
666 | if (V_END[cc][pp] > max_v_end) max_v_end = V_END[cc][pp]; |
---|
667 | |
---|
668 | if (D_BEG[cc][pp] < min_d_beg) min_d_beg = D_BEG[cc][pp]; |
---|
669 | if (D_BEG[cc][pp] > max_d_beg) max_d_beg = D_BEG[cc][pp]; |
---|
670 | |
---|
671 | if (D_END[cc][pp] < min_d_end) min_d_end = D_END[cc][pp]; |
---|
672 | if (D_END[cc][pp] > max_d_end) max_d_end = D_END[cc][pp]; |
---|
673 | } |
---|
674 | } |
---|
675 | |
---|
676 | giet_shr_printf(" - START : min = %d / max = %d / med = %d / delta = %d\n", |
---|
677 | min_start, max_start, (min_start+max_start)/2, max_start-min_start); |
---|
678 | |
---|
679 | giet_shr_printf(" - H_BEG : min = %d / max = %d / med = %d / delta = %d\n", |
---|
680 | min_h_beg, max_h_beg, (min_h_beg+max_h_beg)/2, max_h_beg-min_h_beg); |
---|
681 | |
---|
682 | giet_shr_printf(" - H_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
683 | min_h_end, max_h_end, (min_h_end+max_h_end)/2, max_h_end-min_h_end); |
---|
684 | |
---|
685 | giet_shr_printf(" - V_BEG : min = %d / max = %d / med = %d / delta = %d\n", |
---|
686 | min_v_beg, max_v_beg, (min_v_beg+max_v_beg)/2, max_v_beg-min_v_beg); |
---|
687 | |
---|
688 | giet_shr_printf(" - V_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
689 | min_v_end, max_v_end, (min_v_end+max_v_end)/2, max_v_end-min_v_end); |
---|
690 | |
---|
691 | giet_shr_printf(" - D_BEG : min = %d / max = %d / med = %d / delta = %d\n", |
---|
692 | min_d_beg, max_d_beg, (min_d_beg+max_d_beg)/2, max_d_beg-min_d_beg); |
---|
693 | |
---|
694 | giet_shr_printf(" - D_END : min = %d / max = %d / med = %d / delta = %d\n", |
---|
695 | min_d_end, max_d_end, (min_d_end+max_d_end)/2, max_d_end-min_d_end); |
---|
696 | |
---|
697 | giet_shr_printf( "\n General Scenario (Kcycles for each step)\n" ); |
---|
698 | giet_shr_printf( " - BOOT OS = %d\n", (min_start )/1000 ); |
---|
699 | giet_shr_printf( " - LOAD IMAGE = %d\n", (min_h_beg - min_start)/1000 ); |
---|
700 | giet_shr_printf( " - H_FILTER = %d\n", (max_h_end - min_h_beg)/1000 ); |
---|
701 | giet_shr_printf( " - BARRIER HORI/VERT = %d\n", (min_v_beg - max_h_end)/1000 ); |
---|
702 | giet_shr_printf( " - V_FILTER = %d\n", (max_v_end - min_v_beg)/1000 ); |
---|
703 | giet_shr_printf( " - BARRIER VERT/DISP = %d\n", (min_d_beg - max_v_end)/1000 ); |
---|
704 | giet_shr_printf( " - DISPLAY = %d\n", (max_d_end - min_d_beg)/1000 ); |
---|
705 | |
---|
706 | instrumentation_ok = 1; |
---|
707 | } |
---|
708 | else |
---|
709 | { |
---|
710 | while ( instrumentation_ok == 0 ); |
---|
711 | } |
---|
712 | |
---|
713 | giet_exit( "completed"); |
---|
714 | |
---|
715 | } // end main() |
---|
716 | |
---|
717 | // Local Variables: |
---|
718 | // tab-width: 3 |
---|
719 | // c-basic-offset: 3 |
---|
720 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
721 | // indent-tabs-mode: nil |
---|
722 | // End: |
---|
723 | |
---|
724 | // vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3 |
---|
725 | |
---|
726 | |
---|