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