Ignore:
Timestamp:
Oct 7, 2015, 11:56:33 AM (9 years ago)
Author:
alain
Message:

Introduce the giet_fbf_size() and giet_fbf_alloc() system calls.

File:
1 edited

Legend:

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

    r708 r712  
    66//////////////////////////////////////////////////////////////////////////////////
    77// This multi-threaded application is an emulation of the Game of Life automaton.
    8 // The world size is defined by the HEIGHT and WIDTH parameters.
     8// The world size is defined by the Frame Buffer width and height.
    99//
    1010// There is at most one thread per processor in the platform.
     
    1414// - if the number of processors is not larger than the number of lines,
    1515//   the number of threads is equal to the number of processors, and
    16 //   each thread process HEIGHT/nthreads (or HEIGHT/nthreads + 1) lines.
     16//   each thread process height/nthreads (or height/nthreads + 1) lines.
    1717//
    1818// Thread running on processor P(0,0,0) execute the main() function,
     
    3131#include "malloc.h"
    3232
    33 #define WIDTH           FBUF_X_SIZE
    34 #define HEIGHT          FBUF_Y_SIZE
    35 
    3633#define VERBOSE         1
    3734
     
    4643arguments_t   args[1024];     // at most 1024 threads
    4744
    48 uint8_t world[2][HEIGHT][WIDTH] __attribute__((aligned(64)));
    49 
    50 uint8_t display[2][HEIGHT][WIDTH] __attribute__((aligned(64)));
    51 
    52 unsigned int status0[16];
    53 unsigned int status1[16];
     45uint8_t world[2][256][256] __attribute__((aligned(64)));
     46
     47uint8_t display[2][256][256] __attribute__((aligned(64)));
     48
     49unsigned int status0[16] __attribute__((aligned(64)));
     50unsigned int status1[16] __attribute__((aligned(64)));
    5451
    5552giet_sqt_barrier_t barrier;
     53
     54unsigned int width;
     55unsigned int height;
    5656
    5757////////////////////////////////////
     
    6363   for (y = base_line ; y < base_line + nb_line ; y++)
    6464   {
    65       for(x = 0 ; x < WIDTH ; x++)
     65      for(x = 0 ; x < width ; x++)
    6666      {
    6767         world[phase][y][x] = (giet_rand() >> (x % 8)) & 0x1;
     
    7777   uint8_t nb = 0;
    7878
    79    nb += world[phase][(y - 1) % HEIGHT][(x - 1) % WIDTH];
    80    nb += world[phase][ y              ][(x - 1) % WIDTH];
    81    nb += world[phase][(y + 1) % HEIGHT][(x - 1) % WIDTH];
    82    nb += world[phase][(y - 1) % HEIGHT][ x             ];
    83    nb += world[phase][(y + 1) % HEIGHT][ x             ];
    84    nb += world[phase][(y - 1) % HEIGHT][(x + 1) % WIDTH];
    85    nb += world[phase][ y              ][(x + 1) % WIDTH];
    86    nb += world[phase][(y + 1) % HEIGHT][(x + 1) % WIDTH];
     79   nb += world[phase][(y - 1) % height][(x - 1) % width];
     80   nb += world[phase][ y              ][(x - 1) % width];
     81   nb += world[phase][(y + 1) % height][(x - 1) % width];
     82   nb += world[phase][(y - 1) % height][ x             ];
     83   nb += world[phase][(y + 1) % height][ x             ];
     84   nb += world[phase][(y - 1) % height][(x + 1) % width];
     85   nb += world[phase][ y              ][(x + 1) % width];
     86   nb += world[phase][(y + 1) % height][(x + 1) % width];
    8787
    8888   return nb;
     
    116116   for (y = base_line; y < base_line + nb_line; y++)
    117117   {
    118       for(x = 0; x < WIDTH ; x++)
     118      for(x = 0; x < width ; x++)
    119119      {
    120120         world[phase][y][x] = compute_cell( 1 - phase , x , y ); 
     
    131131   for (y = base_line; y < base_line + nb_line; y++)
    132132   {
    133       for(x = 0; x < WIDTH ; x++)
     133      for(x = 0; x < width ; x++)
    134134      {
    135135         display[phase][y][x] = world[phase][y][x]*255; 
     
    224224   giet_procs_number( &x_size, &y_size, &nprocs );
    225225
     226   // get a shared TTY
     227   giet_tty_alloc( 1 );
     228
    226229   giet_pthread_assert( (x_size <= 16) , "x_size no larger than 16" );
    227230   giet_pthread_assert( (y_size <= 16) , "y_size no larger than 16" );
    228    giet_pthread_assert( (nprocs <=  4) , "nprocs no larger than 16" );
     231   giet_pthread_assert( (nprocs <=  4) , "nprocs no larger than 4" );
     232
     233   // get FBF width and height
     234   giet_fbf_size( &width , &height );
     235
     236   giet_pthread_assert( (width  <= 256)   , "FBF width larger than 256" );
     237   giet_pthread_assert( (height <= 256)   , "FBF height larger than 256" );
     238   giet_pthread_assert( (width  && height) , "FBF not available" );
    229239
    230240   // compute number of threads and min number of lines per thread
     
    234244   unsigned int nlines;
    235245   unsigned int extra;
    236    if ( total_procs > HEIGHT )
    237    {
    238       nthreads = HEIGHT;
     246   if ( total_procs > height )
     247   {
     248      nthreads = height;
    239249      nlines   = 1;
    240250      extra    = 0;
     
    243253   {
    244254      nthreads = total_procs;
    245       nlines   = HEIGHT / total_procs;
    246       extra    = HEIGHT % total_procs; 
    247    }
    248 
    249    // get a shared TTY
    250    giet_tty_alloc( 1 );
     255      nlines   = height / total_procs;
     256      extra    = height % total_procs; 
     257   }
     258
     259   // get FBF ownership
     260   giet_fbf_alloc();
    251261
    252262   // get a Chained Buffer DMA channel
     
    260270
    261271   // activates CMA channel
    262    giet_fbf_cma_start( HEIGHT * WIDTH );
     272   giet_fbf_cma_start( height * width );
    263273
    264274   // initializes distributed heap
     
    278288   giet_tty_printf("\n[GAMEOFLIFE] P[%d,%d,%d] completes initialisation at cycle %d\n"
    279289                   " nprocs = %d / nlines = %d / nthreads = %d\n",
    280                    x, y, p, giet_proctime() , total_procs , HEIGHT , nthreads );
     290                   x, y, p, giet_proctime() , total_procs , height , nthreads );
    281291
    282292   // compute arguments (index, nlines) for all threads
Note: See TracChangeset for help on using the changeset viewer.