Changeset 676 for trunk/user/transpose
- Timestamp:
- Nov 20, 2020, 12:11:35 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/transpose/transpose.c
r659 r676 56 56 // local buf_in[cid] buffer, and write pixels to all remote // buf_out[cid] buffers. 57 57 // 58 // - The image must fit the frame buffer size, that must be power of 2.58 // - The image must have [nlines = npixels = IMAGE_SIZE], and cannot exceed the FBF size. 59 59 // - The number of clusters must be a power of 2 no larger than 256. 60 60 // - The number of cores per cluster must be a power of 2 no larger than 4. … … 80 80 81 81 #define IMAGE_TYPE 420 // pixel encoding type 82 83 //#define IMAGE_SIZE 128 // image size 84 //#define INPUT_FILE_PATH "/misc/images_128.raw" // input file pathname 85 //#define OUTPUT_FILE_PATH "/misc/transposed_128.raw" // output file pathname 86 87 //#define IMAGE_SIZE 256 // image size 88 //#define INPUT_FILE_PATH "/misc/lena_256.raw" // input file pathname 89 #//define OUTPUT_FILE_PATH "/misc/transposed_256.raw" // output file pathname 90 91 //#define IMAGE_SIZE 512 // image size 92 //#define INPUT_FILE_PATH "/misc/couple_512.raw" // input file pathname 93 //#define OUTPUT_FILE_PATH "/misc/transposed_512.raw" // output file pathname 94 95 #define IMAGE_SIZE 1024 // image size 96 #define INPUT_FILE_PATH "/misc/philips_1024.raw" // input file pathname 97 #define OUTPUT_FILE_PATH "/misc/transposed_1024.raw" // output file pathname 98 99 #define SAVE_RESULT_FILE 0 // save result image on disk 82 #define IMAGE_SIZE 256 // default image size 83 #define INPUT_IMAGE_PATH "/misc/lena_256.raw" // default input image pathname 84 #define OUTPUT_IMAGE_PATH "/misc/lena_trsp_256.raw" // default output image pathname 85 86 #define SAVE_RESULT_FILE 1 // save result image on disk 100 87 #define USE_DQT_BARRIER 0 // quad-tree barrier if non zero 101 88 … … 108 95 #define VERBOSE_EXEC 1 // exec function print comments 109 96 97 #define INTERACTIVE_MODE 1 110 98 111 99 /////////////////////////////////////////////////////// … … 140 128 unsigned char * buf_out[CLUSTERS_MAX]; 141 129 142 // pointer and identifier for dynamically allocated FBF window 143 void * win_buf; 144 int wid; 130 // pointer and identifier for FBF windows 131 void * in_win_buf; 132 int in_wid; 133 void * out_win_buf; 134 int out_wid; 145 135 146 136 // synchronisation barrier (all working threads) … … 167 157 // array of thread attributes / indexed by [tid] 168 158 pthread_attr_t exec_attr[THREADS_MAX]; 159 160 // image features 161 unsigned int image_size; 162 char input_image_path[128]; 163 char output_image_path[128]; 169 164 170 165 //////////////////////////////////////////////////////////////// … … 234 229 unsigned int nthreads = nclusters * ncores; 235 230 236 if( nthreads > IMAGE_SIZE ) 237 { 238 printf("\n[transpose error] number of threads larger than number of lines\n"); 239 exit( 0 ); 231 // get input and output images path and size 232 if( INTERACTIVE_MODE ) 233 { 234 printf("\n - image size : "); 235 get_uint32( &image_size ); 236 237 printf("\n - input image path : "); 238 get_string( input_image_path , 128 ); 239 240 printf(" - output image path : "); 241 get_string( output_image_path , 128 ); 242 } 243 else 244 { 245 image_size = IMAGE_SIZE; 246 strcpy( input_image_path , INPUT_IMAGE_PATH ); 247 strcpy( input_image_path , OUTPUT_IMAGE_PATH ); 240 248 } 241 249 242 250 // get FBF size and type 243 unsignedint fbf_width;244 unsignedint fbf_height;245 unsignedint fbf_type;251 int fbf_width; 252 int fbf_height; 253 int fbf_type; 246 254 fbf_get_config( &fbf_width , &fbf_height , &fbf_type ); 247 255 248 if( (fbf_width < IMAGE_SIZE) || (fbf_height < IMAGE_SIZE) || (fbf_type != IMAGE_TYPE) ) 249 { 250 printf("\n[transpose error] image does not fit FBF size or type\n"); 256 // check image 257 if( nthreads > image_size ) 258 { 259 printf("\n[transpose error] nthreads (%d) larger than image size (%d)\n", 260 nthreads , image_size ); 261 exit( 0 ); 262 } 263 264 if( ((unsigned int)fbf_width < image_size) || 265 ((unsigned int)fbf_height < image_size) || 266 (fbf_type != IMAGE_TYPE) ) 267 { 268 printf("\n[transpose error] image not acceptable\n" 269 "FBF width = %d / npixels = %d\n" 270 "FBF height = %d / nlines = %d\n" 271 "FBF type = %d / expected = %d\n", 272 fbf_width, image_size, fbf_height, image_size, fbf_type, IMAGE_TYPE ); 251 273 exit( 0 ); 252 274 } 253 275 254 276 // define total number of pixels 255 int npixels = IMAGE_SIZE * IMAGE_SIZE;277 int npixels = image_size * image_size; 256 278 257 279 // define instrumentation file name … … 259 281 { 260 282 printf("\n[transpose] %d cluster(s) / %d core(s) / <%s> / PID %x / NO_PLACE\n", 261 nclusters, ncores, INPUT_FILE_PATH, getpid() );283 nclusters, ncores, input_image_path, getpid() ); 262 284 263 285 // build instrumentation file name 264 286 if( USE_DQT_BARRIER ) 265 287 snprintf( filename , 32 , "trsp_dqt_no_place_%d_%d_%d", 266 IMAGE_SIZE, x_size * y_size , ncores );288 image_size , x_size * y_size , ncores ); 267 289 else 268 290 snprintf( filename , 32 , "trsp_smp_no_place_%d_%d_%d", 269 IMAGE_SIZE, x_size * y_size , ncores );291 image_size , x_size * y_size , ncores ); 270 292 } 271 293 … … 273 295 { 274 296 printf("\n[transpose] %d cluster(s) / %d core(s) / <%s> / PID %x / EXPLICIT\n", 275 nclusters, ncores, INPUT_FILE_PATH, getpid() );297 nclusters, ncores, input_image_path, getpid() ); 276 298 277 299 // build instrumentation file name 278 300 if( USE_DQT_BARRIER ) 279 301 snprintf( filename , 32 , "trsp_dqt_explicit_%d_%d_%d", 280 IMAGE_SIZE, x_size * y_size , ncores );302 image_size , x_size * y_size , ncores ); 281 303 else 282 304 snprintf( filename , 32 , "trsp_smp_explicit_%d_%d_%d", 283 IMAGE_SIZE, x_size * y_size , ncores );305 image_size , x_size * y_size , ncores ); 284 306 } 285 307 … … 287 309 { 288 310 printf("\n[transpose] %d cluster(s) / %d core(s) / <%s> / PID %x / PARALLEL\n", 289 nclusters, ncores, INPUT_FILE_PATH, getpid() );311 nclusters, ncores, input_image_path, getpid() ); 290 312 291 313 // build instrumentation file name 292 314 if( USE_DQT_BARRIER ) 293 315 snprintf( filename , 32 , "trsp_dqt_parallel_%d_%d_%d", 294 IMAGE_SIZE, x_size * y_size , ncores );316 image_size , x_size * y_size , ncores ); 295 317 else 296 318 snprintf( filename , 32 , "trsp_smp_parallel_%d_%d_%d", 297 IMAGE_SIZE , x_size * y_size , ncores ); 298 } 299 300 // open a window in FBF 301 wid = fbf_create_window( 0, // l_zero 302 0, // p_zero 303 IMAGE_SIZE, // lines 304 IMAGE_SIZE, // pixels 305 &win_buf ); 306 if( wid < 0) 307 { 308 printf("\n[transpose error] cannot open FBF window\n"); 319 image_size , x_size * y_size , ncores ); 320 } 321 322 // create an FBF window for input image 323 in_wid = fbf_create_window( 0, // l_zero 324 0, // p_zero 325 image_size, // lines 326 image_size, // pixels 327 &in_win_buf ); // pointer on buffer in user space 328 if( in_wid < 0) 329 { 330 printf("\n[transpose error] cannot create window for %s\n", input_image_path ); 331 exit( 0 ); 332 } 333 334 // activate window 335 error = fbf_active_window( in_wid , 1 ); 336 337 if( error ) 338 { 339 printf("\n[transpose error] cannot activate window for %s\n", input_image_path ); 309 340 exit( 0 ); 310 341 } 311 342 312 343 #if VERBOSE_MAIN 313 printf("\n[transpose] main on core[%x,%d] created FBF window %d / buffer %x\n", 314 cxy_main, lid_main, wid , win_buf ); 344 printf("\n[transpose] main on core[%x,%d] created window for %s / wid %d / buf %x\n", 345 cxy_main, lid_main, input_image_path, in_wid , in_win_buf ); 346 #endif 347 348 // create an FBF window for output image 349 out_wid = fbf_create_window( image_size, // l_zero 350 image_size, // p_zero 351 image_size, // lines 352 image_size, // pixels 353 &out_win_buf ); // pointer on buffer in user space 354 if( out_wid < 0) 355 { 356 printf("\n[transpose error] cannot create window for %s\n", output_image_path ); 357 exit( 0 ); 358 } 359 360 // activate window 361 error = fbf_active_window( out_wid , 1 ); 362 363 if( error ) 364 { 365 printf("\n[transpose error] cannot activate window for %s\n", output_image_path ); 366 exit( 0 ); 367 } 368 369 #if VERBOSE_MAIN 370 printf("\n[transpose] main on core[%x,%d] created window for %s / wid %d / buf %x\n", 371 cxy_main, lid_main, output_image_path, out_wid , out_win_buf ); 315 372 #endif 316 373 … … 356 413 357 414 // open input file 358 int fd_in = open( INPUT_FILE_PATH, O_RDONLY , 0 );415 int fd_in = open( input_image_path , O_RDONLY , 0 ); 359 416 360 417 if ( fd_in < 0 ) 361 418 { 362 printf("\n[transpose error] main cannot open file %s\n", INPUT_FILE_PATH);419 printf("\n[transpose error] main cannot open file %s\n", input_image_path ); 363 420 exit( 0 ); 364 421 } 365 422 366 423 #if VERBOSE_MAIN 367 printf("\n[transpose] main open file <%s> / fd = %d\n", INPUT_FILE_PATH, fd_in );424 printf("\n[transpose] main open file <%s> / fd = %d\n", input_image_path , fd_in ); 368 425 #endif 369 426 370 427 // open output file 371 int fd_out = open( OUTPUT_FILE_PATH, O_CREAT , 0 );428 int fd_out = open( output_image_path , O_CREAT , 0 ); 372 429 373 430 if ( fd_out < 0 ) 374 431 { 375 printf("\n[transpose error] main cannot open file %s\n", OUTPUT_FILE_PATH);432 printf("\n[transpose error] main cannot open file %s\n", output_image_path ); 376 433 exit( 0 ); 377 434 } … … 385 442 386 443 #if VERBOSE_MAIN 387 printf("\n[transpose] main moved file <%s> to buf_in\n", INPUT_FILE_PATH);444 printf("\n[transpose] main moved file <%s> to buf_in\n", input_image_path ); 388 445 #endif 389 446 … … 621 678 #endif 622 679 623 // delete FBF window 624 if( fbf_delete_window( wid ) ) 680 // delete FBF windows 681 if( fbf_delete_window( in_wid ) ) 682 if( fbf_delete_window( out_wid ) ) 625 683 { 626 684 printf("\n[transpose error] main cannot delete FBF window\n"); 627 685 exit( 0 ); 628 686 } 687 688 #if VERBOSE_MAIN 689 printf("\n[transpose] main deleted FBF windows\n"); 690 #endif 629 691 630 692 // main thread suicide … … 634 696 635 697 } // end main() 698 699 700 701 636 702 637 703 … … 646 712 int error; 647 713 648 unsigned char * wbuf = win_buf;649 650 714 pthread_parallel_work_args_t * args = (pthread_parallel_work_args_t *)arguments; 651 715 … … 678 742 679 743 // compute total number of pixels per image 680 unsigned int npixels = IMAGE_SIZE * IMAGE_SIZE;744 unsigned int npixels = image_size * image_size; 681 745 682 746 // compute total number of threads and clusters … … 689 753 690 754 // compute first and last line per thread 691 unsigned int lines_per_cid = pixels_per_cid / IMAGE_SIZE;692 unsigned int lines_per_lid = pixels_per_lid / IMAGE_SIZE;755 unsigned int lines_per_cid = pixels_per_cid / image_size; 756 unsigned int lines_per_lid = pixels_per_lid / image_size; 693 757 694 758 unsigned int line_first = (cid * lines_per_cid) + (lid * lines_per_lid); … … 751 815 752 816 // all local threads copy part of buf_in[cid] to FBF window for display 753 memcpy( wbuf + (cid * pixels_per_cid) + (lid * pixels_per_lid),817 memcpy( in_win_buf + (cid * pixels_per_cid) + (lid * pixels_per_lid), 754 818 buf_in[cid] + (lid * pixels_per_lid), 755 819 pixels_per_lid ); … … 760 824 #endif 761 825 762 // retresh window763 error = fbf_refresh_window( wid , line_first , line_last );826 // all threads contribute to input window refresh 827 error = fbf_refresh_window( in_wid , line_first , line_last ); 764 828 765 829 if( error ) … … 785 849 // (l,p) are the absolute pixel coordinates in the dest image 786 850 787 unsigned int nlt = IMAGE_SIZE/ nthreads; // number of lines per thread788 unsigned int nlc = IMAGE_SIZE/ nclusters; // number of lines per cluster851 unsigned int nlt = image_size / nthreads; // number of lines per thread 852 unsigned int nlc = image_size / nclusters; // number of lines per cluster 789 853 790 854 unsigned int src_cid; … … 802 866 { 803 867 // loop on pixels in one line (one pixel per iteration) 804 for ( p = 0 ; p < IMAGE_SIZE; p++ )868 for ( p = 0 ; p < image_size ; p++ ) 805 869 { 806 870 // read one byte from local buf_in 807 871 src_cid = l / nlc; 808 src_index = (l % nlc) * IMAGE_SIZE+ p;872 src_index = (l % nlc) * image_size + p; 809 873 810 874 byte = buf_in[src_cid][src_index]; … … 812 876 // write one byte to remote buf_out 813 877 dst_cid = p / nlc; 814 dst_index = (p % nlc) * IMAGE_SIZE+ l;878 dst_index = (p % nlc) * image_size + l; 815 879 816 880 buf_out[dst_cid][dst_index] = byte; … … 834 898 835 899 // each local threads copy part of buf_out[cid] to FBF window for display 836 memcpy( wbuf + (cid * pixels_per_cid) + (lid * pixels_per_lid),900 memcpy( out_win_buf + (cid * pixels_per_cid) + (lid * pixels_per_lid), 837 901 buf_out[cid] + (lid * pixels_per_lid), 838 902 pixels_per_lid ); … … 843 907 #endif 844 908 845 // refresh window846 error = fbf_refresh_window( wid , line_first , line_last );909 // each thread contributes to output window refresh 910 error = fbf_refresh_window( out_wid , line_first , line_last ); 847 911 848 912 if( error )
Note: See TracChangeset
for help on using the changeset viewer.