Ignore:
Timestamp:
Feb 8, 2015, 9:20:45 PM (10 years ago)
Author:
alain
Message:

1) Introduce distributed barriers in the multi-threads applications
(classif) transpose, convol, sort, gameoflife)

2) Introducing support for architectures containing empty clusters
in the mapping of these multi-threaded applications.

3) Removing the "command line arguments" in the sort application
(replaced by the giet_procs_number() system call.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/gameoflife/main.c

    r444 r502  
    1 /*
    2  * This application is an emulation of the game of life automaton
    3  * It must be deployed from processor 0 and use contiguous processor
    4  * (example 0,1,2,3)
    5  */
    6 
     1//////////////////////////////////////////////////////////////////////////////////
     2// File : main.c  (for gameoflife)
     3// Date : November 2013
     4// Author :  Alexandre Joannou <alexandre.joannou@lip6.fr>
     5//
     6// This application is an emulation of the game of life automaton.
     7// The world size is defined by the HEIGHT and WIDTH parameters.
     8// There is one task per processor, and each task compute HEIGHT/nbprocs lines.
     9// The number of processors must be a power of 2 not larger than HEIGHT.
     10//////////////////////////////////////////////////////////////////////////////////
    711
    812#include "stdio.h"
    913#include "limits.h"
    10 #include "barrier.h"
    11 #include "hard_config.h"
     14#include "user_barrier.h"
    1215#include "mapping_info.h"
    1316
    1417#define WIDTH           128
    1518#define HEIGHT          128
    16 #define NB_CLUSTER_MAX  256
    1719#define NB_ITERATION    1000000000
    1820
    19 #define PRINTF(...) ({ if ( proc_id==0) { giet_tty_printf(__VA_ARGS__); } })
    20 
    21 giet_barrier_t barriers[2];
    22 
    23 unsigned int init_ok = 1;
    24 
    25 #define NEW 0
    26 #define OLD 1
     21#define PRINTF(...) ({ if ( proc_id==0) { giet_shr_printf(__VA_ARGS__); } })
     22
     23giet_sqt_barrier_t barrier;
     24
     25unsigned int init_ok = 0;
     26
     27#define OLD 0
     28#define NEW 1
     29#define DSP 2
    2730
    2831typedef unsigned char uint8_t;
    2932typedef unsigned int size_t;
    3033
    31 uint8_t world[2][HEIGHT][WIDTH];
    32 uint8_t world_yuv[HEIGHT][WIDTH];
    33 
    34 /* Generate binary values for world between base_line and base_line + nb_line */
     34uint8_t world[3][HEIGHT][WIDTH];
     35
     36/////////////////////////////////////////////////
    3537void init_world(size_t base_line, size_t nb_line)
    3638{
    3739   size_t x,y;
    38    for (y = base_line ; y < base_line + nb_line; y++){
    39       for(x = 0; x < WIDTH ; x++) {
    40          // TODO OPTIMIZE RANDOM INIT
     40   for (y = base_line ; y < base_line + nb_line; y++)
     41   {
     42      for(x = 0; x < WIDTH ; x++)
     43      {
    4144         world[OLD][y][x] = giet_rand() % 2; 
    4245      }
     
    4447}
    4548
     49/////////////////////////////////////////////////
    4650uint8_t number_of_alive_neigh(size_t x, size_t y)
    4751{
     
    6064}
    6165
    62 /* Compute cell x,y */
     66/////////////////////////////////////////////////
    6367uint8_t compute_cell(size_t x, size_t y)
    6468{
    6569   uint8_t nb_neighbours_alive = number_of_alive_neigh(x,y);
    66    if (world[OLD][y][x] == 1) {
    67       if (nb_neighbours_alive == 2 ||
    68           nb_neighbours_alive == 3)
    69       {
    70          return 1;   
    71       }
    72    }
    73    else {
    74       if (nb_neighbours_alive == 3) {
    75          return 1;
    76       }
    77       else {
    78          return world[OLD][y][x];
    79       }
     70   if (world[OLD][y][x] == 1)
     71   {
     72      if (nb_neighbours_alive == 2 || nb_neighbours_alive == 3)  return 1;
     73   }
     74   else
     75   {
     76      if (nb_neighbours_alive == 3) return 1;
     77      else                          return world[OLD][y][x];
    8078   }
    8179   return 0;
     
    9997{
    10098   size_t x,y;
    101    for (y = base_line; y < base_line + nb_line; y++){
    102       for(x = 0; x < WIDTH ; x++) {
    103          //world_yuv[y][x] = world[NEW][y][x]*100; 
    104          world[NEW][y][x] = world[NEW][y][x]*255; 
     99   for (y = base_line; y < base_line + nb_line; y++)
     100   {
     101      for(x = 0; x < WIDTH ; x++)
     102      {
     103         world[DSP][y][x] = world[OLD][y][x]*255; 
    105104      }
    106105   }
    107106
    108107   giet_fbf_sync_write( base_line * WIDTH ,
    109                        &world[NEW][base_line][0],
    110                        nb_line * WIDTH);
     108                        &world[DSP][base_line][0],
     109                        nb_line * WIDTH );
    111110}
    112111
     
    133132   giet_proc_xyp( &x, &y, &p );
    134133
     134   // get processors number
     135   unsigned int x_size;
     136   unsigned int y_size;
     137   unsigned int n_local_procs;
     138   giet_procs_number( &x_size, &y_size, &n_local_procs );
     139
    135140   // compute continuous processor index
    136    unsigned int proc_id = (((x * Y_SIZE) + y) * NB_PROCS_MAX) + p; 
    137 
    138    unsigned int nlocal_procs  = NB_PROCS_MAX;               // processors per cluster
    139    unsigned int nclusters     = X_SIZE*Y_SIZE;              // number of clusters
    140    unsigned int nglobal_procs = nclusters * nlocal_procs;   // number of processors
     141   unsigned int proc_id = (((x * y_size) + y) * n_local_procs) + p; 
     142
     143   unsigned int n_clusters     = x_size * y_size;            // number of clusters
     144   unsigned int n_global_procs = n_clusters * n_local_procs; // number of processors
    141145   size_t i;
    142146
    143    size_t       nb_line       = HEIGHT / nglobal_procs;
     147   if ( n_global_procs > HEIGHT )
     148   {
     149       PRINTF("[GAMEOFLIFE ERROR] Number or processors too large :"
     150              " nb_procs = %d / image heigth = %d\n", n_global_procs, HEIGHT );
     151       giet_exit("error");
     152   }
     153
     154   size_t       nb_line       = HEIGHT / n_global_procs;
    144155   size_t       base_line     = nb_line * proc_id;
    145156   
    146    PRINTF("*** Starting init at cycle %d ***\n", giet_proctime());
    147 
    148    //  barriers initialization
     157   PRINTF("\n*** Starting barrier initialisation at cycle %d ***\n"
     158          " nprocs = %d / nlines = %d\n",
     159          giet_proctime() , n_global_procs, HEIGHT );
     160
     161   // barrier initialization
    149162   if ( proc_id == 0 )
    150163   {
    151       barrier_init(&barriers[0], nglobal_procs);
    152       barrier_init(&barriers[1], nglobal_procs);
    153 
    154       init_ok = 0;
     164      sqt_barrier_init( &barrier , x_size , y_size , n_local_procs );
     165      init_ok = 1;
    155166   }
    156167   else
    157168   {
    158       while ( init_ok == 1 );
    159    }
    160 
    161    init_world(base_line, nb_line);
    162 
    163    PRINTF("*** Completing init at cycle %d ***\n", giet_proctime());
    164    barrier_wait(&barriers[0]);
     169      while ( init_ok == 0 ) asm volatile("nop");
     170   }
     171
     172   PRINTF("\n*** Starting world initialisation at cycle %d ***\n",
     173          giet_proctime() );
     174
     175   //  parallel world  initialization
     176   init_world( base_line , nb_line );
     177
     178PRINTF("coucou 0\n");
     179
     180   display_world( base_line , nb_line );
     181
     182PRINTF("coucou 1\n");
     183
     184   sqt_barrier_wait( &barrier );
     185
     186   PRINTF("\n*** Starting life at cycle %d ***\n",
     187          giet_proctime() );
    165188   
    166189   for (i = 0; i < NB_ITERATION; i++)
    167190   {
    168       compute_new_gen(base_line, nb_line);
    169       grow_old_world(base_line, nb_line);
    170       display_world(base_line, nb_line);
    171       barrier_wait(&barriers[1]);
    172       barrier_init(&barriers[1], nglobal_procs);
    173    }
    174 
    175    PRINTF("*** End of main at cycle %d ***\n", giet_proctime());
     191      compute_new_gen( base_line, nb_line );
     192      grow_old_world( base_line, nb_line );
     193      display_world( base_line, nb_line );
     194
     195      sqt_barrier_wait( &barrier );
     196
     197      PRINTF(" - iteration %d completed\n", i );
     198   }
     199
     200   PRINTF("\n*** End of main at cycle %d ***\n", giet_proctime());
    176201
    177202   giet_exit("Completed");
Note: See TracChangeset for help on using the changeset viewer.