Changeset 712 for soft/giet_vm/applications/gameoflife/gameoflife.c
- Timestamp:
- Oct 7, 2015, 11:56:33 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/gameoflife/gameoflife.c
r708 r712 6 6 ////////////////////////////////////////////////////////////////////////////////// 7 7 // 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. 9 9 // 10 10 // There is at most one thread per processor in the platform. … … 14 14 // - if the number of processors is not larger than the number of lines, 15 15 // 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. 17 17 // 18 18 // Thread running on processor P(0,0,0) execute the main() function, … … 31 31 #include "malloc.h" 32 32 33 #define WIDTH FBUF_X_SIZE34 #define HEIGHT FBUF_Y_SIZE35 36 33 #define VERBOSE 1 37 34 … … 46 43 arguments_t args[1024]; // at most 1024 threads 47 44 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] ;45 uint8_t world[2][256][256] __attribute__((aligned(64))); 46 47 uint8_t display[2][256][256] __attribute__((aligned(64))); 48 49 unsigned int status0[16] __attribute__((aligned(64))); 50 unsigned int status1[16] __attribute__((aligned(64))); 54 51 55 52 giet_sqt_barrier_t barrier; 53 54 unsigned int width; 55 unsigned int height; 56 56 57 57 //////////////////////////////////// … … 63 63 for (y = base_line ; y < base_line + nb_line ; y++) 64 64 { 65 for(x = 0 ; x < WIDTH; x++)65 for(x = 0 ; x < width ; x++) 66 66 { 67 67 world[phase][y][x] = (giet_rand() >> (x % 8)) & 0x1; … … 77 77 uint8_t nb = 0; 78 78 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]; 87 87 88 88 return nb; … … 116 116 for (y = base_line; y < base_line + nb_line; y++) 117 117 { 118 for(x = 0; x < WIDTH; x++)118 for(x = 0; x < width ; x++) 119 119 { 120 120 world[phase][y][x] = compute_cell( 1 - phase , x , y ); … … 131 131 for (y = base_line; y < base_line + nb_line; y++) 132 132 { 133 for(x = 0; x < WIDTH; x++)133 for(x = 0; x < width ; x++) 134 134 { 135 135 display[phase][y][x] = world[phase][y][x]*255; … … 224 224 giet_procs_number( &x_size, &y_size, &nprocs ); 225 225 226 // get a shared TTY 227 giet_tty_alloc( 1 ); 228 226 229 giet_pthread_assert( (x_size <= 16) , "x_size no larger than 16" ); 227 230 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" ); 229 239 230 240 // compute number of threads and min number of lines per thread … … 234 244 unsigned int nlines; 235 245 unsigned int extra; 236 if ( total_procs > HEIGHT)237 { 238 nthreads = HEIGHT;246 if ( total_procs > height ) 247 { 248 nthreads = height; 239 249 nlines = 1; 240 250 extra = 0; … … 243 253 { 244 254 nthreads = total_procs; 245 nlines = HEIGHT/ total_procs;246 extra = HEIGHT% total_procs;247 } 248 249 // get a shared TTY250 giet_ tty_alloc( 1);255 nlines = height / total_procs; 256 extra = height % total_procs; 257 } 258 259 // get FBF ownership 260 giet_fbf_alloc(); 251 261 252 262 // get a Chained Buffer DMA channel … … 260 270 261 271 // activates CMA channel 262 giet_fbf_cma_start( HEIGHT * WIDTH);272 giet_fbf_cma_start( height * width ); 263 273 264 274 // initializes distributed heap … … 278 288 giet_tty_printf("\n[GAMEOFLIFE] P[%d,%d,%d] completes initialisation at cycle %d\n" 279 289 " 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 ); 281 291 282 292 // compute arguments (index, nlines) for all threads
Note: See TracChangeset
for help on using the changeset viewer.