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