Changeset 669 for soft/giet_vm/applications/gameoflife/main.c
- Timestamp:
- Jul 27, 2015, 8:40:45 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/gameoflife/main.c
r515 r669 5 5 // Alain Greiner <alain.greiner@lip6.fr> february 2015 6 6 // 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. 8 8 // The world size is defined by the HEIGHT and WIDTH parameters. 9 9 // There is one task per processor. 10 10 // Each task compute HEIGHT/nbprocs lines. 11 // Task running on processor P(0,0,0) initialises the barrier, and12 // 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. 13 13 // 14 14 // The number of processors must be a power of 2 not larger than HEIGHT. … … 19 19 #include "user_barrier.h" 20 20 #include "mapping_info.h" 21 #include "hard_config.h" 21 22 22 23 #define WIDTH 128 … … 24 25 #define NB_ITERATION 1000000000 25 26 26 #define PRINTF(...) ({ if ( proc_id==0) { giet_ shr_printf(__VA_ARGS__); } })27 #define PRINTF(...) ({ if ( proc_id==0) { giet_tty_printf(__VA_ARGS__); } }) 27 28 28 29 typedef unsigned char uint8_t; … … 31 32 32 33 uint8_t DISPLAY[2][HEIGHT][WIDTH] __attribute__((aligned(64))); 34 35 unsigned int status0[16]; 36 unsigned int status1[16]; 33 37 34 38 giet_sqt_barrier_t barrier; … … 121 125 //////////////////////////////////////// 122 126 __attribute__((constructor)) void main() 127 //////////////////////////////////////// 123 128 { 124 129 // get processor identifier … … 131 136 unsigned int x_size; 132 137 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 ); 135 140 136 141 // 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; 139 144 140 145 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 }148 146 149 147 unsigned int nb_line = HEIGHT / n_global_procs; 150 148 unsigned int base_line = nb_line * proc_id; 151 149 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 158 169 if ( proc_id == 0 ) 159 170 { 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 161 175 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 } 165 196 166 197 // 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 ); 168 203 169 204 // activates all other processors … … 175 210 } 176 211 177 PRINTF("\n*** Starting world initialisation at cycle %d ***\n",178 giet_proctime() );179 180 212 ///////////// world initialization ( All processors ) 181 213 182 // initialisesWORLD[0]214 // All processors initialize WORLD[0] 183 215 init_world( 0 , base_line , nb_line ); 184 216 … … 192 224 if ( proc_id == 0 ) giet_fbf_cma_display ( 0 ); 193 225 194 PRINTF("\n *** Starting evolution at cycle %d ***\n", giet_proctime() );226 PRINTF("\n[GAMEOFLIFE] starts evolution at cycle %d\n", giet_proctime() ); 195 227 196 228 //////////// evolution : 2 steps per iteration
Note: See TracChangeset
for help on using the changeset viewer.