Changeset 741 for soft/giet_vm/applications
- Timestamp:
- Dec 10, 2015, 12:16:18 PM (9 years ago)
- Location:
- soft/giet_vm/applications/mjpeg
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/mjpeg/Makefile
r723 r741 9 9 10 10 OBJS = mjpeg.o \ 11 tg.o \12 11 demux.o \ 13 12 vld.o \ … … 31 30 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 32 31 33 tg.o: tg.c34 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $<35 36 32 demux.o: demux.c 37 33 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< -
soft/giet_vm/applications/mjpeg/demux.c
r736 r741 90 90 91 91 // initialise BUFIO for MWMR channel <in> 92 mwmr_channel_t* mwmr_in = tg_2_demux[index];92 mwmr_channel_t* mwmr_in = main_2_demux[index]; 93 93 mwmr_bufio_t bufio_in; 94 94 uint8_t in_buffer[64]; -
soft/giet_vm/applications/mjpeg/mjpeg.c
r740 r741 10 10 // communications between threads uses MWMR channels,. 11 11 // It uses the chained buffer DMA component to display the images on the graphic display. 12 // It contains 6 types of threads (plus the "main" thread, that makes initialisation) 12 // It contains 5 types of threads, plus the "main" thread, that makes initialisation, 13 // dispatch the byte stream to the various pipelines, and makes instrumentation. 13 14 // and 7 types of MWMR communication channels: 14 // - the TGthread is only mapped in cluster[0,0], but all other threads15 // - the main thread is only mapped in cluster[0,0], but all other threads 15 16 // (DEMUX, VLD, IQZZ, IDCT, LIBU) are replicated in all clusters. 16 17 // - all MWMR channels are replicated in all clusters. … … 41 42 42 43 // arrays of pointers on MWMR channels 43 mwmr_channel_t* tg_2_demux[256];// one per cluster44 mwmr_channel_t* main_2_demux[256]; // one per cluster 44 45 mwmr_channel_t* demux_2_vld_data[256]; // one per cluster 45 46 mwmr_channel_t* demux_2_vld_huff[256]; // one per cluster … … 50 51 51 52 // thread trdid ( for pthread_create() and pthread_join() ) 52 pthread_t trdid_tg;53 53 pthread_t trdid_demux[256]; // one per cluster 54 54 pthread_t trdid_vld[256]; // one per cluster … … 74 74 //////////////////////////////////////////////// 75 75 76 extern void tg( );77 76 extern void demux( uint32_t index ); 78 77 extern void vld( uint32_t index ); … … 122 121 uint32_t image_width; 123 122 uint32_t image_height; 123 uint32_t fd; // file descriptor 124 124 125 125 if ( INTERACTIVE_MODE ) … … 165 165 166 166 // open file containing the MJPEG bit stream 167 intfd = giet_fat_open( file_pathname , 0 );167 fd = giet_fat_open( file_pathname , 0 ); 168 168 169 169 giet_pthread_assert( (fd >= 0), … … 190 190 191 191 // allocate MWMR channels in cluster[x][y] 192 tg_2_demux[index]= remote_malloc( sizeof( mwmr_channel_t ) , x , y );193 buffer = remote_malloc( 4 * TG_2_DEMUX_DEPTH , x , y );194 mwmr_init( tg_2_demux[index] , buffer , 1 , TG_2_DEMUX_DEPTH );192 main_2_demux[index] = remote_malloc( sizeof( mwmr_channel_t ) , x , y ); 193 buffer = remote_malloc( 4 * MAIN_2_DEMUX_DEPTH , x , y ); 194 mwmr_init( main_2_demux[index] , buffer , 1 , MAIN_2_DEMUX_DEPTH ); 195 195 196 196 demux_2_vld_data[index] = remote_malloc( sizeof( mwmr_channel_t ) , x , y ); … … 228 228 giet_fbf_cma_start(); 229 229 230 mwmr_channel_t* p tr;230 mwmr_channel_t* pc; 231 231 232 232 for ( n = 0 ; n < x_size*y_size ; n++ ) 233 233 { 234 p tr = tg_2_demux[n];235 PRINTF(" - tg_2_demux[%d] = %x / &lock = %x / &buf = %x / size = %d\n",236 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )237 238 p tr= demux_2_vld_data[n];234 pc = main_2_demux[n]; 235 PRINTF(" - main_2_demux[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 236 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 237 238 pc = demux_2_vld_data[n]; 239 239 PRINTF(" - demux_2_vld[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 240 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )241 242 p tr= vld_2_iqzz[n];240 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 241 242 pc = vld_2_iqzz[n]; 243 243 PRINTF(" - vld_2_iqzz[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 244 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )245 246 p tr= iqzz_2_idct[n];244 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 245 246 pc = iqzz_2_idct[n]; 247 247 PRINTF(" - iqzz_2_idct[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 248 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )249 250 p tr= idct_2_libu[n];248 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 249 250 pc = idct_2_libu[n]; 251 251 PRINTF(" - idct_2_libu[%d] = %x / &lock = %x / &buf = %x / size = %d\n", 252 n, p tr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )252 n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 ) 253 253 } 254 254 255 255 // launch all threads : precise mapping is defined in the mjpeg.py file 256 256 uint32_t index; 257 258 if ( giet_pthread_create( &trdid_tg, NULL, &tg , NULL ) )259 giet_pthread_exit( "error launching thread tg\n");260 257 261 258 for ( x = 0 ; x < x_size ; x++ ) … … 321 318 } 322 319 320 ///////////////////////////////////////////////////////////////////////////////////// 321 // dispatch the byte stream to the demux threads, one compressed image per cluster. 322 // It transfer the stream from the file identified by the fd argument to a 1024 323 // bytes local buffer. It analyses the stream to detect the End_of_Image markers. 324 // All the bytes corresponding to a single image from the first byte, to the EOI 325 // marker included, are written in the main_2_demux[index] channel, in increasing 326 // order of the cluster index. 327 ///////////////////////////////////////////////////////////////////////////////////// 328 329 // allocate input buffer : 1024 bytes 330 uint8_t bufin[1024]; 331 332 // allocate output bufio to access output MWMR channels : 64 bytes == 16 words 333 mwmr_bufio_t bufio; 334 uint8_t bufout[64]; 335 mwmr_bufio_init( &bufio , bufout , 64 , 0 , main_2_demux[0] ); 336 337 uint32_t image; // image index 338 uint32_t cluster; // cluster index / modulo x_size*y_size 339 uint32_t ptr; // byte pointer in input buffer 340 uint32_t eoi_found; // boolean : End-of-Image found 341 uint32_t ff_found; // boolean : 0xFF value found 342 uint32_t bytes_count; // mumber of bytes in compressed image 343 344 // initialise image and cluster index, and bufin pointer 345 image = 0; 346 cluster = 0; 347 ptr = 0; 348 349 while( image < MAX_IMAGES ) // one compressed image per iteration 350 { 351 // initialise image specific variables 352 eoi_found = 0; 353 ff_found = 0; 354 bytes_count = 0; 355 356 // re-initialise the destination buffer for each image 357 bufio.mwmr = main_2_demux[cluster]; 358 359 // scan bit stream until EOI found 360 // transfer one byte per iteration from input buffer to output bufio 361 while ( eoi_found == 0 ) 362 { 363 // - tranfer 1024 bytes from file to input buffer when input buffer empty. 364 // - return to first byte in input file when EOF found, 365 // to emulate an infinite stream of images. 366 if ( ptr == 0 ) 367 { 368 uint32_t r = giet_fat_read( fd , bufin , 1024 ); 369 if ( r < 1024 ) 370 { 371 giet_fat_lseek( fd , 0 , SEEK_SET ); 372 giet_fat_read( fd , bufin + r , 1024 - r ); 373 } 374 } 375 376 // transfer one byte from input buffer to output bufio 377 mwmr_bufio_write_byte( &bufio , bufin[ptr] ); 378 379 // analyse this byte to find EOI marker OxFFD8 380 // flush the output buffer when EOI found 381 if ( ff_found ) // possible End of Image 382 { 383 ff_found = 0; 384 if ( bufin[ptr] == 0xD9 ) // End of Image found 385 { 386 // exit current image 387 eoi_found = 1; 388 389 // flush output bufio 390 mwmr_bufio_flush( &bufio ); 391 } 392 } 393 else // test if first byte of a marker 394 { 395 if ( bufin[ptr] == 0xFF ) ff_found = 1; 396 } 397 398 // increment input buffer pointer modulo 1024 399 ptr++; 400 if ( ptr == 1024 ) ptr = 0; 401 402 // increment bytes_count for current image 403 bytes_count++; 404 405 } // end while (eoi) 406 407 #if DEBUG_MAIN 408 PRINTF("\nMAIN send image %d to cluster %d at cycle %d : %d bytes\n", 409 image , cluster , giet_proctime() , bytes_count ) 410 #endif 411 // increment image index 412 image++; 413 414 // increment cluster index modulo (x_size*y_size) 415 cluster++; 416 if (cluster == x_size * y_size) cluster = 0; 417 418 } // end while on images 419 420 ///////////////////////////////////////////////////////////////////////////////////// 323 421 // wait all threads completion 324 325 if ( giet_pthread_join( trdid_tg , NULL ) ) 326 { PRINTF("\n[MJPEG ERROR] calling giet_pthread_join() for tg\n" ) } 422 ///////////////////////////////////////////////////////////////////////////////////// 327 423 328 424 for ( x = 0 ; x < x_size ; x++ ) … … 359 455 } 360 456 361 // instrumentation 362 363 uint32_t image; 457 ///////////////////////////////////////////////////////////////////////////////////// 458 // makes instrumentation 459 ///////////////////////////////////////////////////////////////////////////////////// 460 364 461 PRINTF("\n[MJPEG] Instumentation Results\n" ) 365 462 for ( image = 0 ; image < MAX_IMAGES ; image++ ) -
soft/giet_vm/applications/mjpeg/mjpeg.h
r736 r741 30 30 //////////////////////////////////////////////////////////////////////////////////////// 31 31 32 #define TG_2_DEMUX_DEPTH102432 #define MAIN_2_DEMUX_DEPTH 1024 33 33 #define DEMUX_2_VLD_DATA_DEPTH 1024 34 34 #define DEMUX_2_VLD_HUFF_DEPTH 1024 … … 45 45 //////////////////////////////////////////////////////////////////////////////////////// 46 46 47 #define DEBUG_CLUSTER_INDEX 0xFFFFFFFF // use 0xFFFFFFFF forall clusters47 #define DEBUG_CLUSTER_INDEX 0xFFFFFFFF // use 0xFFFFFFFF to trace all clusters 48 48 49 #define DEBUG_ TG149 #define DEBUG_MAIN 1 50 50 #define DEBUG_DEMUX 1 51 51 #define DEBUG_VLD 1 … … 58 58 //////////////////////////////////////////////////////////////////////////////////////// 59 59 60 extern uint32_t fd; // file descriptor for the file containing MJPEG stream 61 62 extern mwmr_channel_t* tg_2_demux[256]; // one per cluster 60 extern mwmr_channel_t* main_2_demux[256]; // one per cluster 63 61 extern mwmr_channel_t* demux_2_vld_data[256]; // one per cluster 64 62 extern mwmr_channel_t* demux_2_vld_huff[256]; // one per cluster … … 68 66 extern mwmr_channel_t* idct_2_libu[256]; // one per cluster 69 67 70 extern pthread_t trdid_tg;71 68 extern pthread_t trdid_demux[256]; // one per cluster 72 69 extern pthread_t trdid_vld[256]; // one per cluster -
soft/giet_vm/applications/mjpeg/mjpeg.py
r736 r741 12 12 # 13 13 # The mapping of threads on processors is the following: 14 # - the "main" thread, on P[0,0,0] launches all others threads and exit. 15 # - the "tg" thread is only running on P[0,0,0]. 14 # - the "main" thread is running on P[0,0,0]. 16 15 # - the "demux", "iqzz", "idct", "vld", and "libu" threads, implementing 17 16 # a block-level pipe-line, are replicated in all clusters. … … 83 82 84 83 # stacks vsegs: local (one stack per thread => 5 stacks per cluster) 85 # ... plus main_stack and tg_stackin cluster[0][0]84 # ... plus main_stack in cluster[0][0] 86 85 base = stack_base 87 86 mapping.addVseg( vspace, 'mjpeg_main_stack', … … 92 91 base += stack_size 93 92 94 mapping.addVseg( vspace, 'mjpeg_tg_stack',95 base , stack_size, 'C_WU', vtype = 'BUFFER',96 x = 0 , y = 0 , pseg = 'RAM',97 local = True )98 99 base += stack_size100 101 93 for x in xrange (x_size): 102 94 for y in xrange (y_size): … … 139 131 140 132 # threads mapping: demux, vld, iqzz, idct, libu replicated in all clusters 141 # main & tg aremapped in cluster[0,0]133 # main mapped in cluster[0,0] 142 134 mapping.addThread( vspace, 'main', True, 0, 0, 0, 143 135 'mjpeg_main_stack', … … 145 137 0 ) # index in start_vector 146 138 147 if ( nprocs == 1 ): 148 p_tg = 0 149 p_demux = 0 150 p_vld = 0 151 p_iqzz = 0 152 p_idct = 0 153 p_libu = 0 154 elif ( nprocs == 2 ): 155 p_tg = 0 156 p_demux = 1 157 p_vld = 1 158 p_iqzz = 1 159 p_idct = 1 160 p_libu = 1 161 elif ( nprocs == 3 ): 162 p_tg = 0 163 p_demux = 1 164 p_vld = 2 165 p_iqzz = 1 166 p_idct = 1 167 p_libu = 1 168 elif ( nprocs == 4 ): 169 p_tg = 0 170 p_demux = 1 171 p_vld = 3 172 p_iqzz = 2 173 p_idct = 3 174 p_libu = 2 139 if ( x==0 and y==0 ): # tasks mapping in cluster[0,0] 140 if ( nprocs == 1 ): 141 p_demux = 0 142 p_vld = 0 143 p_iqzz = 0 144 p_idct = 0 145 p_libu = 0 146 elif ( nprocs == 2 ): 147 p_demux = 1 148 p_vld = 1 149 p_iqzz = 1 150 p_idct = 1 151 p_libu = 1 152 elif ( nprocs == 3 ): 153 p_demux = 1 154 p_vld = 2 155 p_iqzz = 1 156 p_idct = 1 157 p_libu = 1 158 elif ( nprocs == 4 ): 159 p_demux = 1 160 p_vld = 2 161 p_iqzz = 1 162 p_idct = 3 163 p_libu = 1 164 else: # tasks mapping in other clusters 165 if ( nprocs == 1 ): 166 p_demux = 0 167 p_vld = 0 168 p_iqzz = 0 169 p_idct = 0 170 p_libu = 0 171 elif ( nprocs == 2 ): 172 p_demux = 0 173 p_vld = 1 174 p_iqzz = 0 175 p_idct = 0 176 p_libu = 0 177 elif ( nprocs == 3 ): 178 p_demux = 0 179 p_vld = 1 180 p_iqzz = 0 181 p_idct = 2 182 p_libu = 1 183 elif ( nprocs == 4 ): 184 p_demux = 0 185 p_vld = 1 186 p_iqzz = 2 187 p_idct = 3 188 p_libu = 2 189 175 190 176 mapping.addThread( vspace, 'tg', False, 0, 0, p_tg,177 'mjpeg_tg_stack',178 'mjpeg_heap_0_0',179 1 ) # index in start_vector180 181 191 for x in xrange (x_size): 182 192 for y in xrange (y_size): … … 186 196 'mjpeg_demux_stack_%d_%d' % (x,y), 187 197 'mjpeg_heap_%d_%d' % (x,y), 188 2) # start_index198 1 ) # start_index 189 199 190 200 mapping.addThread( vspace, 'vld_%d_%d' % (x,y), False , x, y, p_vld, 191 201 'mjpeg_vld_stack_%d_%d' % (x,y), 192 202 'mjpeg_heap_%d_%d' % (x,y), 193 3) # start_index203 2 ) # start_index 194 204 195 205 mapping.addThread( vspace, 'iqzz_%d_%d' % (x,y), False , x, y, p_iqzz, 196 206 'mjpeg_iqzz_stack_%d_%d' % (x,y), 197 207 'mjpeg_heap_%d_%d' % (x,y), 198 4) # start_index208 3 ) # start_index 199 209 200 210 mapping.addThread( vspace, 'idct_%d_%d' % (x,y), False , x, y, p_idct, 201 211 'mjpeg_idct_stack_%d_%d' % (x,y), 202 212 'mjpeg_heap_%d_%d' % (x,y), 203 5) # start_index213 4 ) # start_index 204 214 205 215 mapping.addThread( vspace, 'libu_%d_%d' % (x,y), False , x, y, p_libu, 206 216 'mjpeg_libu_stack_%d_%d' % (x,y), 207 217 'mjpeg_heap_%d_%d' % (x,y), 208 6) # start_index218 5 ) # start_index 209 219 210 220 # extend mapping name
Note: See TracChangeset
for help on using the changeset viewer.