source: soft/giet_vm/applications/convol/main.c @ 589

Last change on this file since 589 was 589, checked in by alain, 9 years ago

Modify all applications to support two new rules:
1) introduce a local Makefile for each application.
2) change "application.elf" name to "application/appli.elf" name in the application.py" file.
Introduce the shell application.

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