Ignore:
Timestamp:
Oct 7, 2015, 11:56:33 AM (9 years ago)
Author:
alain
Message:

Introduce the giet_fbf_size() and giet_fbf_alloc() system calls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/transpose/transpose.c

    r708 r712  
    77// It can run on a multi-processors, multi-clusters architecture, with one thread
    88// per processor, and uses the POSIX threads API.
     9// It does not use the CMA to display the result image.
    910//
    1011// The main() function can be launched on any processor P[x,y,l].
     
    2829
    2930#include "stdio.h"
     31#include "stdlib.h"
    3032#include "user_barrier.h"
    3133#include "malloc.h"
     
    3638#define PROCS_MAX             4                           // max number of procs per cluster
    3739#define CLUSTER_MAX           (X_MAX * Y_MAX)             // max number of clusters
    38 #define IMAGE_SIZE            256                         // image size : nlines = npixels
    39 #define INPUT_FILE_PATH       "/misc/lena_256.raw"        // pathname on virtual disk
    40 #define OUTPUT_FILE_PATH      "/home/lena_transposed.raw" // pathname on virtual disk
     40#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
    4143
    4244// macro to use a shared TTY
     
    6567
    6668// checksum variables
    67 unsigned check_line_before[IMAGE_SIZE];
    68 unsigned check_line_after[IMAGE_SIZE];
     69unsigned check_line_before[1024];
     70unsigned check_line_after[1024];
    6971
    7072// lock protecting shared TTY
     
    7375// synchronisation barrier (all threads)
    7476giet_sqt_barrier_t barrier;
     77
     78// input & output files pathname and size
     79char          input_file_name[256];
     80char          output_file_name[256];
     81unsigned int  image_size;
    7582
    7683////////////////////////////////////////////
     
    97104    unsigned int nclusters     = x_size * y_size;               // number of clusters
    98105    unsigned int nthreads      = x_size * y_size * nprocs;      // number of threads
    99     unsigned int npixels       = IMAGE_SIZE * IMAGE_SIZE;       // pixels per image
     106    unsigned int npixels       = image_size * image_size;       // pixels per image
    100107    int          fd_in         = 0;                             // initial file descriptor
    101108    int          fd_out        = 0;                             // output file descriptor
     
    122129
    123130        // open input file
    124         fd_in = giet_fat_open( INPUT_FILE_PATH , O_RDONLY );  // read_only
     131        fd_in = giet_fat_open( input_file_name , O_RDONLY );  // read_only
    125132        if ( fd_in < 0 )
    126133        {
    127134            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 );
    129136            giet_pthread_exit(" open() failure");
    130137        }
     
    132139        {
    133140            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 );
    135142        }
    136143
    137144        // open output file
    138         fd_out = giet_fat_open( OUTPUT_FILE_PATH , O_CREATE );   // create if required
     145        fd_out = giet_fat_open( output_file_name , O_CREATE );   // create if required
    139146        if ( fd_out < 0 )
    140147        {
    141148            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 );
    143150            giet_pthread_exit(" open() failure");
    144151        }
     
    146153        {
    147154            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 );
    149156        }
    150157
     
    184191
    185192    // 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)
    187194    // from line [thread_id*nlt] to line [(thread_id + 1)*nlt - 1]
    188195    // (p,l) are the absolute pixel coordinates in the source image
     
    190197    TRSP_START[x_id][y_id][p_id] = giet_proctime();
    191198
    192     unsigned int nlt   = IMAGE_SIZE / nthreads;    // number of lines per thread
    193     unsigned int nlc   = IMAGE_SIZE / nclusters;   // number of lines per cluster
     199    unsigned int nlt   = image_size / nthreads;    // number of lines per thread
     200    unsigned int nlc   = image_size / nclusters;   // number of lines per cluster
    194201
    195202    unsigned int src_cluster;
     
    208215     
    209216        // in each iteration we transfer one byte
    210         for ( p = 0 ; p < IMAGE_SIZE ; p++ )
     217        for ( p = 0 ; p < image_size ; p++ )
    211218        {
    212219            // read one byte from local buf_in
    213220            src_cluster = l / nlc;
    214             src_index   = (l % nlc)*IMAGE_SIZE + p;
     221            src_index   = (l % nlc)*image_size + p;
    215222            byte        = buf_in[src_cluster][src_index];
    216223
     
    220227            // write one byte to remote buf_out
    221228            dst_cluster = p / nlc;
    222             dst_index   = (p % nlc)*IMAGE_SIZE + l;
     229            dst_index   = (p % nlc)*image_size + l;
    223230            buf_out[dst_cluster][dst_index] = byte;
    224231        }
     
    436443                         "[TRANSPOSE ERROR] y_size must be 1,2,4,8,16");
    437444
    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
    441446    unsigned int nthreads = x_size * y_size * nprocs;
    442447
     
    445450    lock_init( &tty_lock);
    446451
    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");
    448486
    449487    // distributed heap initialisation
Note: See TracChangeset for help on using the changeset viewer.