Changeset 372 for soft/giet_vm


Ignore:
Timestamp:
Jul 31, 2014, 9:54:37 PM (10 years ago)
Author:
alain
Message:

Modify the convol application to use the remote_malloc library,
and to support both the simple barrier and the SBT barrier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/convol/main.c

    r362 r372  
    1111#include "stdlib.h"
    1212#include "barrier.h"
    13 
     13#include "remote_malloc.h"
     14
     15#define USE_SBT_BARRIER            1
    1416#define VERBOSE                    0
    1517#define SUPER_VERBOSE              0
     
    3436#define min(x,y) ((x) < (y) ? (x) : (y))
    3537
    36 // instrumentation counters indexed by (cluster_id, lpid]
     38// global instrumentation counters (cluster_id, lpid]
     39
    3740unsigned int START[NB_CLUSTERS][NB_PROCS_MAX];
    3841unsigned int H_BEG[NB_CLUSTERS][NB_PROCS_MAX];
     
    4346unsigned int D_END[NB_CLUSTERS][NB_PROCS_MAX];
    4447
    45 // synchronization barriers
    46 giet_barrier_t barrier_1;
    47 giet_barrier_t barrier_2;
    48 giet_barrier_t barrier_3;
    49 giet_barrier_t barrier_4;
    50 
    51 volatile unsigned int init_ok = 0;
    52 volatile unsigned int exit_ok = 0;
    53 
     48// global synchronization barrier
     49
     50#if USE_SBT_BARRIER
     51giet_sbt_barrier_t  barrier;
     52#else
     53giet_barrier_t      barrier;
     54#endif
     55
     56volatile unsigned int barrier_init_ok    = 0;
     57volatile unsigned int load_image_ok      = 0;
     58volatile unsigned int instrumentation_ok = 0;
     59
     60// global pointers on distributed buffers in all clusters
     61unsigned short * GA[NB_CLUSTERS];
     62int *            GB[NB_CLUSTERS];
     63int *            GC[NB_CLUSTERS];
     64int *            GD[NB_CLUSTERS];
     65unsigned char *  GZ[NB_CLUSTERS];
    5466
    5567///////////////////////////////////////////
     
    128140        giet_exit( "[CONVOL ERROR] NB_CLUSTERS must be a divider of NP");
    129141
     142   
    130143    ///////////////////////////////////////////////////////////////////
    131     // All tasks initialise in their private stack five
    132     // arrays of pointers on the shared, distributed buffers,
    133     // containing the image. These buffers are indexed by cluster_id,
    134     // as there one set of 5 buffers per cluster.
     144    // task[0][0][0] makes barrier initialisation
    135145    ///////////////////////////////////////////////////////////////////
    136 
    137     unsigned short * A[NB_CLUSTERS];
    138     int *            B[NB_CLUSTERS];
    139     int *            C[NB_CLUSTERS];
    140     int *            D[NB_CLUSTERS];
    141     unsigned char *  Z[NB_CLUSTERS];
    142 
    143     // get heap vaddr in cluster[0,0]
    144     unsigned int base;
    145     giet_vobj_get_vbase( "convol", "conv_heap_0_0", &base );
    146 
    147     // size allocated to each cluster depends on the number of clusters
    148     unsigned int size = 0x01000000 / nclusters;
    149 
    150     // initialise pointers on distributed buffers
    151     for (c = 0; c < nclusters; c++)
    152     {
    153         unsigned int cluster_offset = base + (size * c);
    154         A[c] = (unsigned short *) (cluster_offset);
    155         B[c] = (int *)            (cluster_offset + (frame_size * 1 / nclusters));
    156         C[c] = (int *)            (cluster_offset + (frame_size * 3 / nclusters));
    157         D[c] = (int *)            (cluster_offset + (frame_size * 5 / nclusters));
    158         Z[c] = (unsigned char *)  (cluster_offset + (frame_size * 7 / nclusters));
    159 
    160 #if VERBOSE
    161 if ( pid == 0 ) giet_shr_printf( "\n########################################\n"
    162                                  "### A[%d] = %x\n"
    163                                  "### B[%d] = %x\n"               
    164                                  "### C[%d] = %x\n"               
    165                                  "### D[%d] = %x\n"               
    166                                  "### Z[%d] = %x\n"               
    167                                  "########################################\n",
    168                                  c,A[c],c,B[c],c,C[c],c,D[c],c,Z[c] );
    169 #endif
    170     }
    171 
    172     ///////////////////////////////////////////////////////////////////////////
    173     // task[0,0,0] makes barrier initialisation,
    174     // open the file containing image, and load it from disk to A[c] buffers
    175     // (nblocks / nclusters loaded in each cluster).
    176     // Other tasks are waiting on the init_ok condition.
    177     //////////////////////////////////////////////////////////////////////////
     146   
    178147    if ( pid == 0 )
    179148    {
     
    187156                        giet_proctime(), nclusters, nprocs, ntasks,
    188157                        npixels, frame_size, nblocks );
    189 
    190         //  barriers initialization
    191         barrier_init( &barrier_1, ntasks );
    192         barrier_init( &barrier_2, ntasks );
    193         barrier_init( &barrier_3, ntasks );
    194         barrier_init( &barrier_4, ntasks );
    195 
    196         giet_shr_printf( "\n[CONVOL] task[0,0,0] completes barrier init at cycle %d\n",
    197                 giet_proctime() );
    198 
     158#if USE_SBT_BARRIER
     159        sbt_barrier_init( &barrier, ntasks );
     160#else
     161        barrier_init( &barrier, ntasks );
     162#endif
     163
     164        giet_shr_printf( "\n[CONVOL] task[0,0,0] completes barrier init at cycle %d\n",
     165                         giet_proctime() );
     166
     167        barrier_init_ok = 1;
     168    }
     169    else
     170    {
     171        while ( barrier_init_ok == 0 );
     172    }
     173
     174    ///////////////////////////////////////////////////////////////////
     175    // All task[x][y][0] allocate the global buffers in cluster(x,y)
     176    // These buffers mut be sector-aligned.
     177    ///////////////////////////////////////////////////////////////////
     178    if ( lpid == 0 )
     179    {
     180
     181#if VERBOSE
     182giet_shr_printf( "\n[CONVOL] task[%d,%d,%d] enters malloc at cycle %d\n", x,y,lpid, date );
     183#endif
     184
     185        GA[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)   , 9 , x , y );
     186        GB[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)*2 , 9 , x , y );
     187        GC[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)*2 , 9 , x , y );
     188        GD[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)*2 , 9 , x , y );
     189        GZ[cluster_id] = remote_malloc( (FRAME_SIZE/nclusters)/2 , 9 , x , y );
     190       
     191#if VERBOSE
     192giet_shr_printf( "\n[CONVOL]  Shared Buffer Virtual Addresses in cluster(%d,%d)\n"
     193                 "### GA = %x\n"
     194                 "### GB = %x\n"               
     195                 "### GC = %x\n"               
     196                 "### GD = %x\n"               
     197                 "### GZ = %x\n",
     198                 x, y,
     199                 GA[cluster_id],
     200                 GB[cluster_id],
     201                 GC[cluster_id],
     202                 GD[cluster_id],
     203                 GZ[cluster_id] );
     204#endif
     205    }
     206
     207#if USE_SBT_BARRIER
     208        sbt_barrier_wait( &barrier );
     209#else
     210        barrier_wait( &barrier );
     211#endif
     212
     213
     214    ///////////////////////////////////////////////////////////////////
     215    // All tasks initialise in their private stack a copy of the
     216    // arrays of pointers on the shared, distributed buffers.
     217    ///////////////////////////////////////////////////////////////////
     218
     219    unsigned short * A[NB_CLUSTERS];
     220    int *            B[NB_CLUSTERS];
     221    int *            C[NB_CLUSTERS];
     222    int *            D[NB_CLUSTERS];
     223    unsigned char *  Z[NB_CLUSTERS];
     224
     225    for (c = 0; c < nclusters; c++)
     226    {
     227        A[c] = GA[c];
     228        B[c] = GB[c];
     229        C[c] = GC[c];
     230        D[c] = GD[c];
     231        Z[c] = GZ[c];
     232    }
     233
     234    ///////////////////////////////////////////////////////////////////////////
     235    // task[0,0,0] open the file containing image, and load it from disk
     236    // to all A[c] buffers (nblocks / nclusters loaded in each cluster).
     237    // Other tasks are waiting on the init_ok condition.
     238    //////////////////////////////////////////////////////////////////////////
     239    if ( pid == 0 )
     240    {
    199241        // open file
    200242        file = giet_fat_open("misc/philips_image.raw", 0 );
     
    218260                             "for cluster %d at cycle %d\n", c, giet_proctime() );
    219261        }
    220         init_ok = 1;
     262        load_image_ok = 1;
    221263    }
    222264    else
    223265    {
    224         while ( init_ok == 0 );
     266        while ( load_image_ok == 0 );
    225267    }
    226268
     
    262304#endif
    263305
    264         ///////////////////////////
    265         barrier_wait( &barrier_1 );
     306#if USE_SBT_BARRIER
     307        sbt_barrier_wait( &barrier );
     308#else
     309        barrier_wait( &barrier );
     310#endif
    266311
    267312    }
     
    362407#endif
    363408
    364     ///////////////////////////
    365     barrier_wait( &barrier_2 );
     409#if USE_SBT_BARRIER
     410        sbt_barrier_wait( &barrier );
     411#else
     412        barrier_wait( &barrier );
     413#endif
     414
    366415
    367416    ///////////////////////////////////////////////////////////////
     
    475524#endif
    476525
    477     ///////////////////////////
    478     barrier_wait( &barrier_3 );
     526#if USE_SBT_BARRIER
     527        sbt_barrier_wait( &barrier );
     528#else
     529        barrier_wait( &barrier );
     530#endif
    479531
    480532    ////////////////////////////////////////////////////////////////
     
    528580#endif
    529581     
    530         ///////////////////////////
    531         barrier_wait( &barrier_4 );
     582#if USE_SBT_BARRIER
     583        sbt_barrier_wait( &barrier );
     584#else
     585        barrier_wait( &barrier );
     586#endif
     587
    532588    }
    533589
     
    622678        giet_shr_printf( " - DISPLAY           = %d\n", (max_d_end - min_d_beg)/1000 );
    623679
    624         exit_ok = 1;
     680        instrumentation_ok = 1;
    625681    }
    626682    else
    627683    {
    628         while ( exit_ok == 0 );
     684        while ( instrumentation_ok == 0 );
    629685    }
    630686
Note: See TracChangeset for help on using the changeset viewer.