Changeset 712 for soft/giet_vm/applications/transpose/transpose.c
- Timestamp:
- Oct 7, 2015, 11:56:33 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/transpose/transpose.c
r708 r712 7 7 // It can run on a multi-processors, multi-clusters architecture, with one thread 8 8 // per processor, and uses the POSIX threads API. 9 // It does not use the CMA to display the result image. 9 10 // 10 11 // The main() function can be launched on any processor P[x,y,l]. … … 28 29 29 30 #include "stdio.h" 31 #include "stdlib.h" 30 32 #include "user_barrier.h" 31 33 #include "malloc.h" … … 36 38 #define PROCS_MAX 4 // max number of procs per cluster 37 39 #define CLUSTER_MAX (X_MAX * Y_MAX) // max number of clusters 38 #define IMAGE_SIZE 256 // image size : nlines = npixels39 #define INPUT_FILE_PATH "/misc/lena_256.raw" // pathname on virtual disk40 #define OUTPUT_FILE_PATH "/home/lena_transposed.raw" // pathname on virtual disk40 #define IMAGE_SIZE 256 // default image size 41 #define INPUT_FILE_PATH "/misc/lena_256.raw" // default input file pathname 42 #define OUTPUT_FILE_PATH "/home/lena_transposed.raw" // default output file pathname 41 43 42 44 // macro to use a shared TTY … … 65 67 66 68 // checksum variables 67 unsigned check_line_before[ IMAGE_SIZE];68 unsigned check_line_after[ IMAGE_SIZE];69 unsigned check_line_before[1024]; 70 unsigned check_line_after[1024]; 69 71 70 72 // lock protecting shared TTY … … 73 75 // synchronisation barrier (all threads) 74 76 giet_sqt_barrier_t barrier; 77 78 // input & output files pathname and size 79 char input_file_name[256]; 80 char output_file_name[256]; 81 unsigned int image_size; 75 82 76 83 //////////////////////////////////////////// … … 97 104 unsigned int nclusters = x_size * y_size; // number of clusters 98 105 unsigned int nthreads = x_size * y_size * nprocs; // number of threads 99 unsigned int npixels = IMAGE_SIZE * IMAGE_SIZE; // pixels per image106 unsigned int npixels = image_size * image_size; // pixels per image 100 107 int fd_in = 0; // initial file descriptor 101 108 int fd_out = 0; // output file descriptor … … 122 129 123 130 // open input file 124 fd_in = giet_fat_open( INPUT_FILE_PATH, O_RDONLY ); // read_only131 fd_in = giet_fat_open( input_file_name , O_RDONLY ); // read_only 125 132 if ( fd_in < 0 ) 126 133 { 127 134 printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot open file %s\n", 128 x_id , y_id , p_id , INPUT_FILE_PATH);135 x_id , y_id , p_id , input_file_name ); 129 136 giet_pthread_exit(" open() failure"); 130 137 } … … 132 139 { 133 140 printf("\n[TRANSPOSE] Proc [0,0,0] open file %s / fd = %d\n", 134 INPUT_FILE_PATH, fd_in );141 input_file_name , fd_in ); 135 142 } 136 143 137 144 // open output file 138 fd_out = giet_fat_open( OUTPUT_FILE_PATH, O_CREATE ); // create if required145 fd_out = giet_fat_open( output_file_name , O_CREATE ); // create if required 139 146 if ( fd_out < 0 ) 140 147 { 141 148 printf("\n[TRANSPOSE ERROR] Proc [%d,%d,%d] cannot open file %s\n", 142 x_id , y_id , p_id , OUTPUT_FILE_PATH);149 x_id , y_id , p_id , output_file_name ); 143 150 giet_pthread_exit(" open() failure"); 144 151 } … … 146 153 { 147 154 printf("\n[TRANSPOSE] Proc [0,0,0] open file %s / fd = %d\n", 148 OUTPUT_FILE_PATH, fd_out );155 output_file_name , fd_out ); 149 156 } 150 157 … … 184 191 185 192 // parallel transpose from buf_in to buf_out 186 // each thread makes the transposition for nlt lines (nlt = IMAGE_SIZE/nthreads)193 // each thread makes the transposition for nlt lines (nlt = image_size/nthreads) 187 194 // from line [thread_id*nlt] to line [(thread_id + 1)*nlt - 1] 188 195 // (p,l) are the absolute pixel coordinates in the source image … … 190 197 TRSP_START[x_id][y_id][p_id] = giet_proctime(); 191 198 192 unsigned int nlt = IMAGE_SIZE/ nthreads; // number of lines per thread193 unsigned int nlc = IMAGE_SIZE/ nclusters; // number of lines per cluster199 unsigned int nlt = image_size / nthreads; // number of lines per thread 200 unsigned int nlc = image_size / nclusters; // number of lines per cluster 194 201 195 202 unsigned int src_cluster; … … 208 215 209 216 // in each iteration we transfer one byte 210 for ( p = 0 ; p < IMAGE_SIZE; p++ )217 for ( p = 0 ; p < image_size ; p++ ) 211 218 { 212 219 // read one byte from local buf_in 213 220 src_cluster = l / nlc; 214 src_index = (l % nlc)* IMAGE_SIZE+ p;221 src_index = (l % nlc)*image_size + p; 215 222 byte = buf_in[src_cluster][src_index]; 216 223 … … 220 227 // write one byte to remote buf_out 221 228 dst_cluster = p / nlc; 222 dst_index = (p % nlc)* IMAGE_SIZE+ l;229 dst_index = (p % nlc)*image_size + l; 223 230 buf_out[dst_cluster][dst_index] = byte; 224 231 } … … 436 443 "[TRANSPOSE ERROR] y_size must be 1,2,4,8,16"); 437 444 438 giet_pthread_assert( (nprocs * x_size * y_size <= IMAGE_SIZE ), 439 "[TRANSPOSE ERROR] number of threads larger than number of lines"); 440 445 // compute number of threads 441 446 unsigned int nthreads = x_size * y_size * nprocs; 442 447 … … 445 450 lock_init( &tty_lock); 446 451 447 printf("\n[TRANSPOSE] start at cycle %d on %d cores\n", giet_proctime(), nthreads ); 452 // get FBF ownership and FBF size 453 unsigned int width; 454 unsigned int height; 455 giet_fbf_alloc(); 456 giet_fbf_size( &width , &height ); 457 458 // enter interactive part if required 459 printf("\n[TRANSPOSE] start at cycle %d on %d cores / FBF = %d * %d pixels\n", 460 giet_proctime(), nthreads , width , height ); 461 462 // input_file_name, output_file_name, and size acquisition 463 printf("\n[TRANSPOSE] enter path for input file / default is : %s\n> ", INPUT_FILE_PATH ); 464 giet_tty_gets( input_file_name , 256 ); 465 printf("\n"); 466 467 if ( strcmp( input_file_name , "" ) == 0 ) strcpy( input_file_name , INPUT_FILE_PATH ); 468 469 printf("\n[TRANSPOSE] enter path for output file / default is : %s\n> ", OUTPUT_FILE_PATH ); 470 giet_tty_gets( output_file_name , 256 ); 471 printf("\n"); 472 473 if ( strcmp( output_file_name , "" ) == 0 ) strcpy( output_file_name , OUTPUT_FILE_PATH ); 474 475 printf("\n[TRANSPOSE] enter image size / default is : %d\n> ", IMAGE_SIZE ); 476 giet_tty_getw( &image_size ); 477 printf("\n"); 478 479 if ( image_size == 0 ) image_size = IMAGE_SIZE; 480 481 printf("\n[TRANSPOSE] input = %s / output = %s / size = %d\n", 482 input_file_name, output_file_name, image_size ); 483 484 giet_pthread_assert( (nprocs * x_size * y_size <= image_size ), 485 "[TRANSPOSE ERROR] number of threads larger than number of lines"); 448 486 449 487 // distributed heap initialisation
Note: See TracChangeset
for help on using the changeset viewer.