Ignore:
Timestamp:
Jul 27, 2015, 8:40:45 PM (9 years ago)
Author:
alain
Message:

Introduce support for the "shared" argument in the giet_tty_alloc() system call,
and replace the giet_shr_printf() system call by giet_tty_printf().

File:
1 edited

Legend:

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

    r515 r669  
    55//            Alain Greiner <alain.greiner@lip6.fr> february 2015
    66//
    7 // This application is an emulation of the Game of Life automaton.
     7// This multi-threaded application is an emulation of the Game of Life automaton.
    88// The world size is defined by the HEIGHT and WIDTH parameters.
    99// There is one task per processor.
    1010// Each task compute HEIGHT/nbprocs lines.
    11 // Task running on processor P(0,0,0) initialises the barrier, and
    12 // the chained buffer DMA controler.
     11// Task running on processor P(0,0,0) initialises the barrier, the TTY terminal,
     12// and the chained buffer DMA controler.
    1313//
    1414// The number of processors must be a power of 2 not larger than HEIGHT.
     
    1919#include "user_barrier.h"
    2020#include "mapping_info.h"
     21#include "hard_config.h"
    2122
    2223#define WIDTH           128
     
    2425#define NB_ITERATION    1000000000
    2526
    26 #define PRINTF(...) ({ if ( proc_id==0) { giet_shr_printf(__VA_ARGS__); } })
     27#define PRINTF(...) ({ if ( proc_id==0) { giet_tty_printf(__VA_ARGS__); } })
    2728
    2829typedef unsigned char uint8_t;
     
    3132
    3233uint8_t DISPLAY[2][HEIGHT][WIDTH] __attribute__((aligned(64)));
     34
     35unsigned int status0[16];
     36unsigned int status1[16];
    3337
    3438giet_sqt_barrier_t barrier;
     
    121125////////////////////////////////////////
    122126__attribute__((constructor)) void main()
     127////////////////////////////////////////
    123128{
    124129   // get processor identifier
     
    131136   unsigned int x_size;
    132137   unsigned int y_size;
    133    unsigned int n_local_procs;
    134    giet_procs_number( &x_size, &y_size, &n_local_procs );
     138   unsigned int nprocs;
     139   giet_procs_number( &x_size, &y_size, &nprocs );
    135140
    136141   // compute continuous processor index & number of procs
    137    unsigned int proc_id = (((x * y_size) + y) * n_local_procs) + p; 
    138    unsigned int n_global_procs = x_size * y_size * n_local_procs;
     142   unsigned int proc_id = (((x * y_size) + y) * nprocs) + p; 
     143   unsigned int n_global_procs = x_size * y_size * nprocs;
    139144
    140145   unsigned int i;
    141 
    142    if ( n_global_procs > HEIGHT )
    143    {
    144        PRINTF("[GAMEOFLIFE ERROR] Number or processors too large :"
    145               " nb_procs = %d / image heigth = %d\n", n_global_procs, HEIGHT );
    146        giet_exit("error");
    147    }
    148146
    149147   unsigned int nb_line       = HEIGHT / n_global_procs;
    150148   unsigned int base_line     = nb_line * proc_id;
    151149   
    152    PRINTF("\n*** Starting barrier and CMA initialisation at cycle %d ***\n"
    153           " nprocs = %d / nlines = %d\n",
    154           giet_proctime() , n_global_procs, HEIGHT );
    155 
    156    //////////// barrier & CMA initialization ( P(0,0,0) )
    157 
     150   // parameters checking
     151   giet_assert( (n_global_procs <= HEIGHT),
     152                " Number or processors larger than world height" );
     153
     154   giet_assert( ((WIDTH == FBUF_X_SIZE) && (HEIGHT == FBUF_Y_SIZE)),
     155                "Frame Buffer size does not fit the world size" );
     156   
     157   giet_assert( ((x_size == 1) || (x_size == 2) || (x_size == 4) ||
     158                 (x_size == 8) || (x_size == 16)),
     159                "x_size must be a power of 2 no larger than 16" );
     160
     161   giet_assert( ((y_size == 1) || (y_size == 2) || (y_size == 4) ||
     162                 (y_size == 8) || (y_size == 16)),
     163                "y_size must be a power of 2 no larger than 16" );
     164
     165   giet_assert( ((nprocs == 1) || (nprocs == 2) || (nprocs == 4)),
     166                "nprocs must be a power of 2 no larger than 4" );
     167
     168   // P[0,0,0] makes initialisation
    158169   if ( proc_id == 0 )
    159170   {
    160       // initialises CMA component
     171      // get a private TTY for P[0,0,0]
     172      giet_tty_alloc( 0 );
     173
     174      // get a Chained Buffer DMA channel
    161175      giet_fbf_cma_alloc();
    162       giet_fbf_cma_start( &DISPLAY[0][0][0] ,
    163                           &DISPLAY[1][0][0] ,
    164                           HEIGHT * WIDTH );
     176
     177      // initializes the source and destination buffers
     178      giet_fbf_cma_init_buf( &DISPLAY[0][0][0] ,
     179                             &DISPLAY[1][0][0] ,
     180                             status0 ,
     181                             status1 );
     182
     183      // activates CMA channel
     184      giet_fbf_cma_start( HEIGHT * WIDTH );
     185
     186      // initializes distributed heap
     187      unsigned int cx;
     188      unsigned int cy;
     189      for ( cx = 0 ; cx < x_size ; cx++ )
     190      {
     191         for ( cx = 0 ; cx < x_size ; cx++ )
     192         {
     193            heap_init( cx , cy );
     194         }
     195      }
    165196
    166197      // initialises barrier
    167       sqt_barrier_init( &barrier , x_size , y_size , n_local_procs );
     198      sqt_barrier_init( &barrier , x_size , y_size , nprocs );
     199
     200      PRINTF("\n[GAMEOFLIFE] P[0,0,0] completes initialisation at cycle %d\n"
     201             " nprocs = %d / nlines = %d\n",
     202             giet_proctime() , n_global_procs, HEIGHT );
    168203
    169204      // activates all other processors
     
    175210   }
    176211
    177    PRINTF("\n*** Starting world initialisation at cycle %d ***\n",
    178           giet_proctime() );
    179 
    180212   ///////////// world  initialization ( All processors )
    181213
    182    // initialises WORLD[0]
     214   // All processors initialize WORLD[0]
    183215   init_world( 0 , base_line , nb_line );
    184216
     
    192224   if ( proc_id == 0 ) giet_fbf_cma_display ( 0 );
    193225
    194    PRINTF("\n*** Starting evolution at cycle %d ***\n", giet_proctime() );
     226   PRINTF("\n[GAMEOFLIFE] starts evolution at cycle %d\n", giet_proctime() );
    195227   
    196228   //////////// evolution : 2 steps per iteration
Note: See TracChangeset for help on using the changeset viewer.