Changeset 676 for trunk/user/transpose


Ignore:
Timestamp:
Nov 20, 2020, 12:11:35 AM (4 years ago)
Author:
alain
Message:

Introduce chat application to test the named pipes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/transpose/transpose.c

    r659 r676  
    5656// local buf_in[cid] buffer, and write pixels to all remote // buf_out[cid] buffers.
    5757//
    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.
    5959// - The number of clusters  must be a power of 2 no larger than 256.
    6060// - The number of cores per cluster must be a power of 2 no larger than 4.
     
    8080
    8181#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
    10087#define USE_DQT_BARRIER       0                            // quad-tree barrier if non zero
    10188
     
    10895#define VERBOSE_EXEC          1                            // exec function print comments
    10996
     97#define INTERACTIVE_MODE      1
    11098
    11199///////////////////////////////////////////////////////
     
    140128unsigned char *  buf_out[CLUSTERS_MAX];
    141129
    142 // pointer and identifier for dynamically allocated FBF window
    143 void   *  win_buf;
    144 int       wid;
     130// pointer and identifier for FBF windows
     131void   *  in_win_buf;
     132int       in_wid;
     133void   *  out_win_buf;
     134int       out_wid;
    145135
    146136// synchronisation barrier (all working threads)
     
    167157// array of thread attributes / indexed by [tid]
    168158pthread_attr_t                exec_attr[THREADS_MAX];
     159
     160// image features
     161unsigned int   image_size;
     162char           input_image_path[128];
     163char           output_image_path[128];
    169164
    170165////////////////////////////////////////////////////////////////
     
    234229    unsigned int nthreads  = nclusters * ncores;
    235230
    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 );
    240248    }
    241249
    242250    // get FBF size and type
    243     unsigned int   fbf_width;
    244     unsigned int   fbf_height;
    245     unsigned int   fbf_type;
     251    int   fbf_width;
     252    int   fbf_height;
     253    int   fbf_type;
    246254    fbf_get_config( &fbf_width , &fbf_height , &fbf_type );
    247255
    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 );
    251273        exit( 0 );
    252274    }
    253275
    254276    // define total number of pixels
    255     int npixels = IMAGE_SIZE * IMAGE_SIZE;
     277    int npixels = image_size * image_size;
    256278
    257279    // define instrumentation file name
     
    259281    {
    260282        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() );
    262284
    263285        // build instrumentation file name
    264286        if( USE_DQT_BARRIER )
    265287        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 );
    267289        else
    268290        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 );
    270292    }
    271293
     
    273295    {
    274296        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() );
    276298
    277299        // build instrumentation file name
    278300        if( USE_DQT_BARRIER )
    279301        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 );
    281303        else
    282304        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 );
    284306    }
    285307
     
    287309    {
    288310        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() );
    290312
    291313        // build instrumentation file name
    292314        if( USE_DQT_BARRIER )
    293315        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 );
    295317        else
    296318        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 );
    309340        exit( 0 );
    310341    }
    311342
    312343#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 );
     344printf("\n[transpose] main on core[%x,%d] created window for %s / wid %d / buf %x\n",
     345cxy_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
     370printf("\n[transpose] main on core[%x,%d] created window for %s / wid %d / buf %x\n",
     371cxy_main, lid_main, output_image_path, out_wid , out_win_buf );
    315372#endif
    316373
     
    356413
    357414    // 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 );
    359416
    360417    if ( fd_in < 0 )
    361418    {
    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 );
    363420        exit( 0 );
    364421    }
    365422
    366423#if  VERBOSE_MAIN
    367 printf("\n[transpose] main open file <%s> / fd = %d\n", INPUT_FILE_PATH , fd_in );
     424printf("\n[transpose] main open file <%s> / fd = %d\n", input_image_path , fd_in );
    368425#endif
    369426
    370427    // 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 );
    372429
    373430    if ( fd_out < 0 )
    374431    {
    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 );
    376433        exit( 0 );
    377434    }
     
    385442
    386443#if  VERBOSE_MAIN
    387 printf("\n[transpose] main moved file <%s> to buf_in\n", INPUT_FILE_PATH );
     444printf("\n[transpose] main moved file <%s> to buf_in\n", input_image_path );
    388445#endif
    389446
     
    621678#endif
    622679
    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 ) )
    625683    {
    626684        printf("\n[transpose error] main cannot delete FBF window\n");
    627685        exit( 0 );
    628686    }
     687
     688#if VERBOSE_MAIN
     689printf("\n[transpose] main deleted FBF windows\n");
     690#endif
    629691
    630692    // main thread suicide
     
    634696
    635697} // end main()
     698
     699
     700
     701
    636702
    637703
     
    646712    int                  error;
    647713
    648     unsigned char      * wbuf = win_buf;
    649  
    650714    pthread_parallel_work_args_t * args = (pthread_parallel_work_args_t *)arguments;
    651715
     
    678742
    679743    // compute total number of pixels per image
    680     unsigned int npixels = IMAGE_SIZE * IMAGE_SIZE;     
     744    unsigned int npixels = image_size * image_size;     
    681745
    682746    // compute total number of threads and clusters
     
    689753
    690754    // 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;
    693757
    694758    unsigned int line_first = (cid * lines_per_cid) + (lid * lines_per_lid);
     
    751815
    752816    // 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),
    754818            buf_in[cid] + (lid * pixels_per_lid),
    755819            pixels_per_lid );
     
    760824#endif
    761825
    762     // retresh window
    763     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 );
    764828
    765829    if( error )
     
    785849    // (l,p) are the absolute pixel coordinates in the dest image
    786850
    787     unsigned int nlt   = IMAGE_SIZE / nthreads;    // number of lines per thread
    788     unsigned int nlc   = IMAGE_SIZE / nclusters;   // number of lines per cluster
     851    unsigned int nlt   = image_size / nthreads;    // number of lines per thread
     852    unsigned int nlc   = image_size / nclusters;   // number of lines per cluster
    789853
    790854    unsigned int src_cid;
     
    802866    {
    803867        // 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++ )
    805869        {
    806870            // read one byte from local buf_in
    807871            src_cid   = l / nlc;
    808             src_index = (l % nlc) * IMAGE_SIZE + p;
     872            src_index = (l % nlc) * image_size + p;
    809873
    810874            byte = buf_in[src_cid][src_index];
     
    812876            // write one byte to remote buf_out
    813877            dst_cid   = p / nlc;
    814             dst_index = (p % nlc) * IMAGE_SIZE + l;
     878            dst_index = (p % nlc) * image_size + l;
    815879
    816880            buf_out[dst_cid][dst_index] = byte;
     
    834898
    835899    // 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),
    837901            buf_out[cid] + (lid * pixels_per_lid),
    838902            pixels_per_lid );
     
    843907#endif
    844908
    845     // refresh window
    846     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 );
    847911
    848912    if( error )
Note: See TracChangeset for help on using the changeset viewer.