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