Ignore:
Timestamp:
Feb 8, 2015, 9:20:45 PM (9 years ago)
Author:
alain
Message:

1) Introduce distributed barriers in the multi-threads applications
(classif) transpose, convol, sort, gameoflife)

2) Introducing support for architectures containing empty clusters
in the mapping of these multi-threaded applications.

3) Removing the "command line arguments" in the sort application
(replaced by the giet_procs_number() system call.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/sort/main.c

    r432 r502  
    99//      barrier routines to apply a sort algorithm in several stages.
    1010//
    11 //      Considerations :
    12 //
    13 //          - It supports up to 256 processors and the number of processors
    14 //            must be a power of 2.
    15 //
    16 //          - If there is only one TTY available, this application uses a spin
    17 //            lock to avoid several threads writting at the same time.
    18 //
    19 //          - This application must be executed on a cache coherent
    20 //            architecture. Otherwise some modifications must be applied
    21 //
    22 //          - The processors executing this application must have a contiguous
    23 //            processor id and the first processor must have id 0.
     11//      Constraints :
     12//
     13//      - It supports up to 1024 processors and the number of processors
     14//        must be a power of 2.
     15//
     16//      _ The array of values to be sorted (ARRAY_LENGTH) must be power of 2
     17//        larger than the number of processors.
     18//
     19//      - This application must be executed on a cache coherent architecture.
    2420//
    2521///////////////////////////////////////////////////////////////////////////////
     
    2824#include "mapping_info.h"
    2925#include "hard_config.h"
    30 #include "barrier.h"
    31 
    32 #define ARRAY_LENGTH    512
    33 #define IPT             (ARRAY_LENGTH / *nb_thread) // ITEMS PER THREAD
     26#include "user_barrier.h"
     27
     28#define ARRAY_LENGTH    4096
     29#define IPT             (ARRAY_LENGTH / threads) // ITEMS PER THREAD
    3430
    3531////////////////////////////////////////////////////////////////////////////////
    36 // Processors other than 0 display algorithm state
    37 // The processor 0 always displays some information so this does not affect him
     32// Processors other than 0 display algorithm state if VERBOSE non zero
    3833
    3934#define VERBOSE         1
    4035
    4136////////////////////////////////////////////////////////////////////////////////
    42 // Define printf according to verbosity option and number of available
    43 // TTY
     37// Define printf according to verbosity option and number of available TTY
    4438
    4539#if (VERBOSE == 1)
     
    5044
    5145#define task0_printf(...) if(thread_id == 0) giet_shr_printf(__VA_ARGS__)
    52 
    53 #define exit    giet_exit
    54 #define procid  giet_procid
    55 #define rand    giet_rand
    5646
    5747int array0[ARRAY_LENGTH];
     
    7363        int init_pos_result);
    7464
    75 ///////////////////////////////////////////////////
    76 // This application support at most 256 processors
    77 // Number of barriers = log2(nb_thread)
    78 
    79 giet_barrier_t barrier[8];
     65///////////////////////////////////////////////////////
     66// This application supports at most 1024 processors
     67// Number of barriers = log2(threads)
     68
     69giet_barrier_t barrier[10];
    8070
    8171//////////////////////////////////////////
     
    8373{
    8474    int thread_id = giet_thread_id();
    85     unsigned int* nb_thread;
    8675    int * src_array = NULL;
    8776    int * dst_array = NULL;
     
    9180    unsigned int time_end;   
    9281
    93     giet_vobj_get_vbase( "sort" ,
    94                          "sort_args",
    95                          (unsigned int*)&nb_thread );
    96    
    97     task0_printf("\n[ Thread 0 ] Starting sort application with %u threads "
    98                  "at cycle %u\n", *nb_thread, time_start);
     82    // compute number of threads (one thread per proc)
     83    unsigned int x_size;
     84    unsigned int y_size;
     85    unsigned int nprocs;
     86    unsigned int threads;
     87    giet_procs_number( &x_size , &y_size , &nprocs );
     88    threads = x_size * y_size * nprocs;
     89
     90    if ( (threads != 1)   && (threads != 2)   && (threads != 4)   &&
     91         (threads != 8)   && (threads != 16 ) && (threads != 32)  &&
     92         (threads != 64)  && (threads != 128) && (threads != 256) &&
     93         (threads != 512) && (threads != 1024) )
     94    {
     95        task0_printf("[SORT ERROR] Number of processors must be power of 2\n"
     96                     "  x_size = %d / y_size = %d / nprocs = %d\n",
     97                     x_size , y_size , nprocs );
     98        giet_exit("error");
     99    }
     100
     101    task0_printf("\n[ Thread 0 ] Starting sort application with %d threads "
     102                 "at cycle %d\n", threads, time_start);
    99103
    100104    ///////////////////////////
     
    103107    if (thread_id == 0)
    104108    {
    105         for (i = 0; i < __builtin_ctz(*nb_thread); i++)
    106         {
    107             barrier_init(&barrier[i], *nb_thread >> i);
     109        for (i = 0; i < __builtin_ctz( threads ); i++)
     110        {
     111            barrier_init(&barrier[i], threads >> i);
    108112        }
    109113
     
    120124    for (i = IPT * thread_id; i < IPT * (thread_id + 1); i++)
    121125    {
    122         array0[i] = rand();
     126        array0[i] = giet_rand();
    123127    }
    124128
     
    132136    printf("[ Thread %d ] Finishing Stage 0\n\r", thread_id);
    133137
    134     for (i = 0; i < __builtin_ctz(*nb_thread); i++)
     138    for (i = 0; i < __builtin_ctz( threads ); i++)
    135139    {
    136140        barrier_wait(&barrier[i]);
     
    139143        {
    140144            printf("[ Thread %d ] Quit\n\r", thread_id );
    141             exit("Completed");
     145            giet_exit("Completed");
    142146        }
    143147
     
    173177    if(thread_id != 0)
    174178    {
    175         exit("error: only thread 0 should get here");
     179        giet_exit("error: only thread 0 should get here");
    176180    }
    177181
     
    196200    if (success)
    197201    {
    198         exit("!!! Success !!!");
     202        giet_exit("!!! Success !!!");
    199203    }
    200204    else
     
    206210            printf("array[%d] = %d\n", i, dst_array[i]);
    207211        }
    208         exit("!!!  Failure !!!");
    209     }
    210 
    211     exit("Completed");
     212        giet_exit("!!!  Failure !!!");
     213    }
     214
     215    giet_exit("Completed");
    212216}
    213217
Note: See TracChangeset for help on using the changeset viewer.