Changeset 708


Ignore:
Timestamp:
Oct 1, 2015, 4:09:25 PM (9 years ago)
Author:
alain
Message:

Adapt the following application to the POSIX threads API

  • convol
  • classif
  • raycast
  • coproc
  • display
  • gameoflife
  • transpose
  • shell
Location:
soft/giet_vm/applications
Files:
5 added
6 deleted
20 edited
3 moved

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/classif/Makefile

    r589 r708  
    22APP_NAME = classif
    33
    4 OBJS= main.o
     4OBJS= classif.o
    55
    66LIBS= -L../../build/libs -luser
  • soft/giet_vm/applications/classif/classif.py

    r610 r708  
    1010#  This file describes the mapping of the multi-threaded "classif"
    1111#  application on a multi-clusters, multi-processors architecture.
    12 #  The mapping of tasks on processors is the following:
    13 #    - one "load" task per cluster containing processors,
    14 #    - one "store" task per cluster containing processors,
    15 #    - (nprocs-2) "analyse" task per cluster containing processors.
     12#  The mapping of threads on processors is the following:
     13#    - the "main" on cluster[0][0] 
     14#    - one "load" thread per cluster containing processors,
     15#    - one "store" thread per cluster containing processors,
     16#    - (nprocs-2) "analyse" thread per cluster containing processors.
    1617#  The mapping of virtual segments is the following:
    1718#    - There is one shared data vseg in cluster[0][0]
     
    3940    y_width   = mapping.y_width
    4041
    41     assert (nprocs >= 3)
     42    assert (nprocs >= 3) and (nprocs <= 8)
    4243
    4344    # define vsegs base & size
    44     code_base  = 0x10000000
    45     code_size  = 0x00010000     # 64 Kbytes (replicated in each cluster)
     45    code_base  = 0x10000000     
     46    code_size  = 0x00010000     # 64 Kbytes (per cluster)
    4647   
    4748    data_base  = 0x20000000
    48     data_size  = 0x00010000     # 64 Kbytes
     49    data_size  = 0x00010000     # 64 Kbytes (non replicated)
    4950
    5051    heap_base  = 0x30000000
    51     heap_size  = 0x00040000     # 256 Kbytes (per cluster)     
     52    heap_size  = 0x00200000     # 2M bytes (per cluster)     
    5253
    5354    stack_base = 0x40000000
    54     stack_size = 0x00200000     # 2 Mbytes (per cluster)
     55    stack_size = 0x00010000     # 64 Kbytes (per thread)
    5556
    5657    # create vspace
    57     vspace = mapping.addVspace( name = 'classif', startname = 'classif_data' )
     58    vspace = mapping.addVspace( name = 'classif', startname = 'classif_data', active = False )
    5859   
    5960    # data vseg : shared / cluster[0][0]
     
    7374                mapping.addVseg( vspace, 'classif_heap_%d_%d' %(x,y), base , size,
    7475                                 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM',
    75                                  local = False )
     76                                 local = False, big = True )
    7677
    77     # code vsegs : local (one copy in each cluster)
     78    # code vsegs : local (one copy per cluster)
    7879    for x in xrange (x_size):
    7980        for y in xrange (y_size):
     
    8889
    8990    # stacks vsegs: local (one stack per processor => nprocs stacks per cluster)
     91    # ... plus main_stack in cluster[0][0]
     92    mapping.addVseg( vspace, 'main_stack',
     93                     stack_base, stack_size, 'C_WU', vtype = 'BUFFER',
     94                     x = 0 , y = 0 , pseg = 'RAM',
     95                     local = True )
     96
    9097    for x in xrange (x_size):
    9198        for y in xrange (y_size):
     
    94101                for p in xrange( nprocs ):
    95102                    proc_id = (((x * y_size) + y) * nprocs) + p
    96                     size    = (stack_size / nprocs) & 0xFFFFF000
    97                     base    = stack_base + (proc_id * size)
     103                    base    = stack_base + (proc_id * stack_size) + stack_size
    98104
    99105                    mapping.addVseg( vspace, 'classif_stack_%d_%d_%d' % (x,y,p),
    100                                      base, size, 'C_WU', vtype = 'BUFFER',
     106                                     base, stack_size, 'C_WU', vtype = 'BUFFER',
    101107                                     x = x , y = y , pseg = 'RAM',
    102                                      local = True, big = True )
     108                                     local = True )
    103109
    104     # distributed tasks / one task per processor
     110    # distributed threads / one thread per processor
     111    # ... plus main on P[0][0][0]
     112    mapping.addThread( vspace, 'main', True, 0, 0, 1,
     113                       'main_stack',
     114                       'classif_heap_0_0',
     115                       0 )                      # index in start_vector
     116
    105117    for x in xrange (x_size):
    106118        for y in xrange (y_size):
     
    108120            if ( mapping.clusters[cluster_id].procs ):
    109121                for p in xrange( nprocs ):
    110                     trdid = (((x * y_size) + y) * nprocs) + p
    111                     if  ( p== 0 ):                              # task load
    112                         task_index = 2
    113                         task_name  = 'load_%d_%d_%d' %(x,y,p)           
    114                     elif  ( p== 1 ):                            # task store
    115                         task_index = 1
    116                         task_name  = 'store_%d_%d_%d' %(x,y,p)           
    117                     else :                                      # task analyse
    118                         task_index = 0
    119                         task_name  = 'analyse_%d_%d_%d' % (x,y,p)
     122                    if  ( p== 0 ):                              # thread load
     123                        start_index = 3
     124                        thread_name = 'load_%d_%d_%d' %(x,y,p)           
     125                    elif  ( p== 1 ):                            # thread store
     126                        start_index = 2
     127                        thread_name = 'store_%d_%d_%d' %(x,y,p)           
     128                    else :                                      # thread analyse
     129                        start_index = 1
     130                        thread_name = 'analyse_%d_%d_%d' % (x,y,p)
    120131
    121                     mapping.addTask( vspace, task_name, trdid, x, y, p,
    122                                      'classif_stack_%d_%d_%d' % (x,y,p),
    123                                      'classif_heap_%d_%d' % (x,y),
    124                                      task_index )
     132                    mapping.addThread( vspace, thread_name, False , x, y, p,
     133                                       'classif_stack_%d_%d_%d' % (x,y,p),
     134                                       'classif_heap_%d_%d' % (x,y),
     135                                       start_index )   # index in start_vector
    125136
    126137    # extend mapping name
  • soft/giet_vm/applications/convol/Makefile

    r589 r708  
     1
     2CC = mipsel-unknown-elf-gcc
     3AS = mipsel-unknown-elf-as
     4LD = mipsel-unknown-elf-ld
     5DU = mipsel-unknown-elf-objdump
     6AR = mipsel-unknown-elf-ar
    17
    28APP_NAME = convol
    39
    4 OBJS= main.o
     10OBJS= convol.o
    511
    612LIBS= -L../../build/libs -luser
    713
    8 INCLUDES = -I../../giet_libs -I. -I../..
     14INCLUDES = -I../../giet_libs -I. -I../.. -I../../giet_xml
    915
    1016LIB_DEPS = ../../build/libs/libuser.a
  • soft/giet_vm/applications/convol/convol.py

    r669 r708  
    1111#  application on a multi-clusters, multi-processors architecture.
    1212#  This include both the mapping of virtual segments on the clusters,
    13 #  and the mapping of tasks on processors.
    14 #  There is one task per processor.
     13#  and the mapping of threads on processors.
     14#  There is one thread per processor.
    1515#  The mapping of virtual segments is the following:
    1616#    - There is one shared data vseg in cluster[0][0]
     
    8585                                     local = True, big = True )
    8686           
    87     # heap vsegs : distributed but non local (any heap can be accessed by any task)
     87    # heap vsegs : distributed but non local (any heap can be accessed by any thread)
    8888    for x in xrange (x_size):
    8989        for y in xrange (y_size):
     
    9797                                 local = False, big = True )
    9898
    99     # distributed tasks : one task per processor
     99    # distributed threads : one thread per processor
    100100    for x in xrange (x_size):
    101101        for y in xrange (y_size):
     
    103103            if ( mapping.clusters[cluster_id].procs ):
    104104                for p in xrange( nprocs ):
    105                     trdid = (((x * y_size) + y) * nprocs) + p
     105                    if (x == 0) and (y == 0) and (p == 0) :   # main thread
     106                        startid = 1
     107                        is_main = True
     108                    else :                                    # trsp thread
     109                        startid = 0
     110                        is_main = False
    106111
    107                     mapping.addTask( vspace, 'conv_%d_%d_%d' % (x,y,p),
    108                                      trdid, x, y, p,
    109                                      'conv_stack_%d_%d_%d' % (x,y,p),
    110                                      'conv_heap_%d_%d' % (x,y), 0 )
     112                    mapping.addThread( vspace,
     113                                       'conv_%d_%d_%d' % (x,y,p),
     114                                       is_main,
     115                                       x, y, p,
     116                                       'conv_stack_%d_%d_%d' % (x,y,p),
     117                                       'conv_heap_%d_%d' % (x,y),
     118                                       startid )
    111119
    112120    # extend mapping name
  • soft/giet_vm/applications/coproc/Makefile

    r589 r708  
     1
     2CC = mipsel-unknown-elf-gcc
     3AS = mipsel-unknown-elf-as
     4LD = mipsel-unknown-elf-ld
     5DU = mipsel-unknown-elf-objdump
     6AR = mipsel-unknown-elf-ar
    17
    28APP_NAME = coproc
    39
    4 OBJS= main.o
     10OBJS= coproc.o
    511
    612LIBS= -L../../build/libs -luser
  • soft/giet_vm/applications/coproc/coproc.c

    r707 r708  
    11///////////////////////////////////////////////////////////////////////////////////////
    2 //  file   : main.c  (for coproc application)
     2//  file   : coproc.c
    33//  date   : avril 2015
    44//  author : Alain Greiner
    55///////////////////////////////////////////////////////////////////////////////////////
    66//  This file describes the single thread "coproc" application.
    7 //  It uses the embedded GCD (Greater Common Divider) coprocessor to make
    8 //  the GCD computation between two vectors of 32 bits integers.
     7//  It uses the GCD (Greater Common Divider) hardware coprocessor
     8//  to make the GCD computation between two vectors of 32 bits integers.
    99//  The vectors size is defined by the VECTOR_SIZE parameter.
    1010///////////////////////////////////////////////////////////////////////////////////////
     
    1818#define  DMA_MODE    MODE_DMA_IRQ
    1919
    20 #define VERBOSE      1
     20#define  VERBOSE     1
    2121
    2222// Memory buffers for coprocessor
     
    5959    unsigned int nb_config      = (coproc_info>>16) & 0xFF;
    6060    unsigned int nb_status      = (coproc_info>>24) & 0xFF;
    61     giet_assert( ((nb_to_coproc   == 2) &&
    62                   (nb_from_coproc == 1) &&
    63                   (nb_config      == 1) &&
    64                   (nb_status      == 0) ) ,
    65                   "wrong GCD coprocessor interface" );
     61    giet_pthread_assert( ((nb_to_coproc   == 2) &&
     62                         (nb_from_coproc == 1) &&
     63                         (nb_config      == 1) &&
     64                         (nb_status      == 0) ) ,
     65                         "wrong GCD coprocessor interface" );
    6666
    67 if ( VERBOSE )
     67#if  VERBOSE
    6868giet_tty_printf("\n*** get GCD coprocessor at cycle %d\n", giet_proctime() );
     69#endif
    6970
    7071    //////////////////////// initializes channel for OPA
     
    8990    giet_coproc_channel_init( 2 , &res_desc );
    9091   
    91 if ( VERBOSE )
     92#if  VERBOSE
    9293giet_tty_printf("\n*** channels initialized at cycle %d\n", giet_proctime() );
     94#endif
    9395
    9496    /////////////////////// starts communication channels
    9597    giet_coproc_run( 0 );
    9698
    97 if ( VERBOSE )
     99#if  VERBOSE
    98100giet_tty_printf("\n*** start GCD coprocessor at cycle %d\n", giet_proctime() );
     101#endif
    99102
    100103    /////////////////////// wait coprocessor completion
     
    104107    }
    105108
    106 if ( VERBOSE )
     109#if  VERBOSE
    107110giet_tty_printf("\n*** GCD computation completed at cycle %d\n", giet_proctime() );
     111#endif
    108112
    109113    // display result
     
    117121    giet_coproc_release( 0 );
    118122
    119     giet_exit("completed");
     123    giet_pthread_exit("completed");
    120124
    121125} // end main
  • soft/giet_vm/applications/coproc/coproc.py

    r610 r708  
    3333    x = 0
    3434    y = 0
    35     p = 0
     35    p = 1
    3636
    3737    assert( (x < x_size) and (y < y_size) )
     
    5050
    5151    # create vspace
    52     vspace = mapping.addVspace( name = 'coproc', startname = 'coproc_data' )
     52    vspace = mapping.addVspace( name = 'coproc', startname = 'coproc_data', active = False )
    5353   
    5454    # data vseg in cluster[x,y]
     
    6969                     local = False, big = True )
    7070
    71     # one task on processor[x,y,0]
    72     mapping.addTask( vspace, 'coproc', 0 , x , y , 0 ,
    73                      'coproc_stack' , '' , 0 )
     71    # one thread on processor[x,y,p]
     72    mapping.addThread( vspace,
     73                       'coproc',
     74                       True,                    # is_main
     75                       x, y, p,
     76                       'coproc_stack',
     77                       '',                      # no heap
     78                       0 )                      # start_id
    7479
    7580    # extend mapping name
  • soft/giet_vm/applications/display/Makefile

    r589 r708  
     1
     2CC = mipsel-unknown-elf-gcc
     3AS = mipsel-unknown-elf-as
     4LD = mipsel-unknown-elf-ld
     5DU = mipsel-unknown-elf-objdump
     6AR = mipsel-unknown-elf-ar
    17
    28APP_NAME = display
    39
    4 OBJS= main.o
     10OBJS= display.o
    511
    612LIBS= -L../../build/libs -luser
  • soft/giet_vm/applications/display/display.py

    r644 r708  
    1818    x_width   = mapping.x_width
    1919    y_width   = mapping.y_width
     20
     21    # define thread placement
     22    x = 0
     23    y = 0
     24    p = 2
    2025
    2126    # define vsegs base & size
     
    5863
    5964    # task
    60     mapping.addTask( vspace, 'disp', 0, 0, 0, 1, 'disp_stack', 'disp_heap', 0 )
     65    mapping.addThread( vspace, 'display',
     66                       True,               # is_main
     67                       x, y, p,
     68                       'disp_stack',
     69                       'disp_heap',
     70                       0 )                 # startid
    6171
    6272    # extend mapping name
  • soft/giet_vm/applications/gameoflife/Makefile

    r589 r708  
     1
     2CC = mipsel-unknown-elf-gcc
     3AS = mipsel-unknown-elf-as
     4LD = mipsel-unknown-elf-ld
     5DU = mipsel-unknown-elf-objdump
     6AR = mipsel-unknown-elf-ar
    17
    28APP_NAME = gameoflife
    39
    4 OBJS= main.o
     10OBJS= gameoflife.o
    511
    612LIBS= -L../../build/libs -luser
  • soft/giet_vm/applications/gameoflife/gameoflife.c

    r707 r708  
    44// Authors :  Alexandre Joannou <alexandre.joannou@lip6.fr> november 2013
    55//            Alain Greiner <alain.greiner@lip6.fr> february 2015
    6 //
     6//////////////////////////////////////////////////////////////////////////////////
    77// This multi-threaded application is an emulation of the Game of Life automaton.
    88// The world size is defined by the HEIGHT and WIDTH parameters.
    9 // There is one task per processor.
    10 // Each task compute HEIGHT/nbprocs lines.
    11 // Task running on processor P(0,0,0) initialises the barrier, the TTY terminal,
    12 // and the chained buffer DMA controler.
    139//
    14 // The number of processors must be a power of 2 not larger than HEIGHT.
     10// There is at most one thread per processor in the platform.
     11// - If the number of processors is larger than the number of lines,
     12//   the number of threads is equal to the number of lines, and
     13//   each thread process one single line.
     14// - if the number of processors is not larger than the number of lines,
     15//   the number of threads is equal to the number of processors, and
     16//   each thread process HEIGHT/nthreads (or HEIGHT/nthreads + 1) lines.
     17//
     18// Thread running on processor P(0,0,0) execute the main() function,
     19// that initialises the barrier, the TTY terminal, the CMA controler,
     20// and launch the other threads, before calling the execute function.
     21// Other threads are just running the execute() function.
     22//
     23// The total number of processors cannot be larger than 1024 = 16 * 16 * 4
    1524//////////////////////////////////////////////////////////////////////////////////
    1625
     
    2029#include "mapping_info.h"
    2130#include "hard_config.h"
    22 
    23 #define WIDTH           128
    24 #define HEIGHT          128
    25 #define NB_ITERATION    1000000000
    26 
    27 #define PRINTF(...) ({ if ( proc_id==0) { giet_tty_printf(__VA_ARGS__); } })
     31#include "malloc.h"
     32
     33#define WIDTH           FBUF_X_SIZE
     34#define HEIGHT          FBUF_Y_SIZE
     35
     36#define VERBOSE         1
    2837
    2938typedef unsigned char uint8_t;
    3039
    31 uint8_t WORLD[2][HEIGHT][WIDTH] __attribute__((aligned(64)));
    32 
    33 uint8_t DISPLAY[2][HEIGHT][WIDTH] __attribute__((aligned(64)));
     40typedef struct
     41{
     42    unsigned int    index;    // index of first line to be processed
     43    unsigned int    lines;    // number of lines to be processed
     44}   arguments_t;
     45
     46arguments_t   args[1024];     // at most 1024 threads
     47
     48uint8_t world[2][HEIGHT][WIDTH] __attribute__((aligned(64)));
     49
     50uint8_t display[2][HEIGHT][WIDTH] __attribute__((aligned(64)));
    3451
    3552unsigned int status0[16];
     
    3754
    3855giet_sqt_barrier_t barrier;
    39 
    40 volatile unsigned int init_ok;
    4156
    4257////////////////////////////////////
     
    5065      for(x = 0 ; x < WIDTH ; x++)
    5166      {
    52          WORLD[phase][y][x] = (giet_rand() >> (x % 8)) & 0x1;
     67         world[phase][y][x] = (giet_rand() >> (x % 8)) & 0x1;
    5368      }
    5469   }
     
    6277   uint8_t nb = 0;
    6378
    64    nb += WORLD[phase][(y - 1) % HEIGHT][(x - 1) % WIDTH];
    65    nb += WORLD[phase][ y              ][(x - 1) % WIDTH];
    66    nb += WORLD[phase][(y + 1) % HEIGHT][(x - 1) % WIDTH];
    67    nb += WORLD[phase][(y - 1) % HEIGHT][ x             ];
    68    nb += WORLD[phase][(y + 1) % HEIGHT][ x             ];
    69    nb += WORLD[phase][(y - 1) % HEIGHT][(x + 1) % WIDTH];
    70    nb += WORLD[phase][ y              ][(x + 1) % WIDTH];
    71    nb += WORLD[phase][(y + 1) % HEIGHT][(x + 1) % WIDTH];
     79   nb += world[phase][(y - 1) % HEIGHT][(x - 1) % WIDTH];
     80   nb += world[phase][ y              ][(x - 1) % WIDTH];
     81   nb += world[phase][(y + 1) % HEIGHT][(x - 1) % WIDTH];
     82   nb += world[phase][(y - 1) % HEIGHT][ x             ];
     83   nb += world[phase][(y + 1) % HEIGHT][ x             ];
     84   nb += world[phase][(y - 1) % HEIGHT][(x + 1) % WIDTH];
     85   nb += world[phase][ y              ][(x + 1) % WIDTH];
     86   nb += world[phase][(y + 1) % HEIGHT][(x + 1) % WIDTH];
    7287
    7388   return nb;
     
    8196   uint8_t nb_neighbours_alive = number_of_alive_neighbour( phase, x , y );
    8297
    83    if (WORLD[phase][y][x] == 1)
     98   if (world[phase][y][x] == 1)
    8499   {
    85100      if (nb_neighbours_alive == 2 || nb_neighbours_alive == 3)  return 1;
     
    88103   {
    89104      if (nb_neighbours_alive == 3) return 1;
    90       else                          return WORLD[phase][y][x];
     105      else                          return world[phase][y][x];
    91106   }
    92107   return 0;
     
    103118      for(x = 0; x < WIDTH ; x++)
    104119      {
    105          WORLD[phase][y][x] = compute_cell( 1 - phase , x , y ); 
     120         world[phase][y][x] = compute_cell( 1 - phase , x , y ); 
    106121      }
    107122   }
     
    118133      for(x = 0; x < WIDTH ; x++)
    119134      {
    120          DISPLAY[phase][y][x] = WORLD[phase][y][x]*255; 
    121       }
    122    }
    123 }
     135         display[phase][y][x] = world[phase][y][x]*255; 
     136      }
     137   }
     138}
     139
     140
     141
     142///////////////////////////////////////////////////////////////
     143__attribute__((constructor)) void execute( arguments_t* pargs )
     144///////////////////////////////////////////////////////////////
     145{
     146   unsigned int nb_lines      = pargs->lines;
     147   unsigned int base_line     = pargs->index;
     148
     149   ///////////// parallel world  initialization
     150
     151   // All processors initialize world[0]
     152   init_world( 0 , base_line , nb_lines );
     153
     154   // copy world[0] to display[0]
     155   copy_world( 0 , base_line , nb_lines );
     156
     157   // synchronise with other procs
     158   sqt_barrier_wait( &barrier );
     159
     160   // main() makes display[0]
     161   if ( base_line == 0 ) giet_fbf_cma_display ( 0 );
     162
     163   //////////// evolution : 2 steps per iteration
     164
     165   unsigned int i = 0;
     166   while( 1 )
     167   {
     168      // compute world[1] from world[0]
     169      compute_new_gen( 1 , base_line , nb_lines );
     170
     171      // copy world[1] to display[1]
     172      copy_world( 1 , base_line , nb_lines );
     173
     174      // synchronise with other procs
     175      sqt_barrier_wait( &barrier );
     176
     177      // main makes display[1]
     178      if ( base_line == 0 ) giet_fbf_cma_display ( 1 );
     179   
     180#if VERBOSE
     181      if ( base_line == 0 ) giet_tty_printf(" - step %d\n", 2*i );
     182#endif
     183   
     184      // compute world[0] from world[1]
     185      compute_new_gen( 0 , base_line , nb_lines );
     186
     187      // copy world[0] to display[0]
     188      copy_world( 0 , base_line , nb_lines );
     189
     190      // synchronise with other procs
     191      sqt_barrier_wait( &barrier );
     192
     193      // main makes display[0]
     194      if ( base_line == 0 ) giet_fbf_cma_display ( 0 );
     195
     196#if VERBOSE
     197      if ( base_line == 0 ) giet_tty_printf(" - step %d\n", 2*i + 1 );
     198#endif
     199
     200      i++;
     201
     202   } // end evolution loop
     203
     204   giet_pthread_exit("Completed");
     205
     206} // end main()
     207
     208
    124209
    125210////////////////////////////////////////
     
    133218   giet_proc_xyp( &x, &y, &p );
    134219
    135    // get processors number
     220   // get platform parameters
    136221   unsigned int x_size;
    137222   unsigned int y_size;
     
    139224   giet_procs_number( &x_size, &y_size, &nprocs );
    140225
    141    // compute continuous processor index & number of procs
    142    unsigned int proc_id = (((x * y_size) + y) * nprocs) + p; 
    143    unsigned int n_global_procs = x_size * y_size * nprocs;
    144 
    145    unsigned int i;
    146 
    147    unsigned int nb_line       = HEIGHT / n_global_procs;
    148    unsigned int base_line     = nb_line * proc_id;
    149    
    150    // parameters checking
    151    giet_assert( (n_global_procs <= HEIGHT),
    152                 " Number or processors larger than world height" );
    153 
    154    giet_assert( ((WIDTH == FBUF_X_SIZE) && (HEIGHT == FBUF_Y_SIZE)),
    155                 "Frame Buffer size does not fit the world size" );
    156    
    157    giet_assert( ((x_size == 1) || (x_size == 2) || (x_size == 4) ||
    158                  (x_size == 8) || (x_size == 16)),
    159                 "x_size must be a power of 2 no larger than 16" );
    160 
    161    giet_assert( ((y_size == 1) || (y_size == 2) || (y_size == 4) ||
    162                  (y_size == 8) || (y_size == 16)),
    163                 "y_size must be a power of 2 no larger than 16" );
    164 
    165    giet_assert( ((nprocs == 1) || (nprocs == 2) || (nprocs == 4)),
    166                 "nprocs must be a power of 2 no larger than 4" );
    167 
    168    // P[0,0,0] makes initialisation
    169    if ( proc_id == 0 )
    170    {
    171       // get a private TTY for P[0,0,0]
    172       giet_tty_alloc( 0 );
    173 
    174       // get a Chained Buffer DMA channel
    175       giet_fbf_cma_alloc();
    176 
    177       // initializes the source and destination buffers
    178       giet_fbf_cma_init_buf( &DISPLAY[0][0][0] ,
    179                              &DISPLAY[1][0][0] ,
    180                              status0 ,
    181                              status1 );
    182 
    183       // activates CMA channel
    184       giet_fbf_cma_start( HEIGHT * WIDTH );
    185 
    186       // initializes distributed heap
    187       unsigned int cx;
    188       unsigned int cy;
    189       for ( cx = 0 ; cx < x_size ; cx++ )
    190       {
    191          for ( cx = 0 ; cx < x_size ; cx++ )
    192          {
    193             heap_init( cx , cy );
    194          }
    195       }
    196 
    197       // initialises barrier
    198       sqt_barrier_init( &barrier , x_size , y_size , nprocs );
    199 
    200       PRINTF("\n[GAMEOFLIFE] P[0,0,0] completes initialisation at cycle %d\n"
    201              " nprocs = %d / nlines = %d\n",
    202              giet_proctime() , n_global_procs, HEIGHT );
    203 
    204       // activates all other processors
    205       init_ok = 1;
     226   giet_pthread_assert( (x_size <= 16) , "x_size no larger than 16" );
     227   giet_pthread_assert( (y_size <= 16) , "y_size no larger than 16" );
     228   giet_pthread_assert( (nprocs <=  4) , "nprocs no larger than 16" );
     229
     230   // compute number of threads and min number of lines per thread
     231   // extra is the number of threads that must process one extra line
     232   unsigned int total_procs = x_size * y_size * nprocs;
     233   unsigned int nthreads;
     234   unsigned int nlines;
     235   unsigned int extra;
     236   if ( total_procs > HEIGHT )
     237   {
     238      nthreads = HEIGHT;
     239      nlines   = 1;
     240      extra    = 0;
    206241   }
    207242   else
    208243   {
    209       while ( init_ok == 0 ) asm volatile("nop\n nop\n nop");
    210    }
    211 
    212    ///////////// world  initialization ( All processors )
    213 
    214    // All processors initialize WORLD[0]
    215    init_world( 0 , base_line , nb_line );
    216 
    217    // copy WORLD[0] to DISPLAY[0]
    218    copy_world( 0 , base_line , nb_line );
    219 
    220    // synchronise with other procs
    221    sqt_barrier_wait( &barrier );
    222 
    223    // P(0,0,0) displays DISPLAY[0]
    224    if ( proc_id == 0 ) giet_fbf_cma_display ( 0 );
    225 
    226    PRINTF("\n[GAMEOFLIFE] starts evolution at cycle %d\n", giet_proctime() );
    227    
    228    //////////// evolution : 2 steps per iteration
    229 
    230    for (i = 0 ; i < NB_ITERATION ; i++)
    231    {
    232       // compute WORLD[1] from WORLD[0]
    233       compute_new_gen( 1 , base_line , nb_line );
    234 
    235       // copy WORLD[1] to DISPLAY[1]
    236       copy_world( 1 , base_line , nb_line );
    237 
    238       // synchronise with other procs
    239       sqt_barrier_wait( &barrier );
    240 
    241       // P(0,0,0) displays DISPLAY[1]
    242       if ( proc_id == 0 ) giet_fbf_cma_display ( 1 );
    243    
    244       PRINTF(" - step %d\n", 2*i );
    245    
    246       // compute WORLD[0] from WORLD[1]
    247       compute_new_gen( 0 , base_line , nb_line );
    248 
    249       // copy WORLD[0] to DISPLAY[0]
    250       copy_world( 0 , base_line , nb_line );
    251 
    252       // synchronise with other procs
    253       sqt_barrier_wait( &barrier );
    254 
    255       // P(0,0,0) displays DISPLAY[0]
    256       if ( proc_id == 0 ) giet_fbf_cma_display ( 0 );
    257 
    258       PRINTF(" - step %d\n", 2*i + 1 );
    259    } // end main loop
    260 
    261    PRINTF("\n*** End of main at cycle %d ***\n", giet_proctime());
    262 
    263    giet_exit("Completed");
     244      nthreads = total_procs;
     245      nlines   = HEIGHT / total_procs;
     246      extra    = HEIGHT % total_procs; 
     247   }
     248
     249   // get a shared TTY
     250   giet_tty_alloc( 1 );
     251
     252   // get a Chained Buffer DMA channel
     253   giet_fbf_cma_alloc();
     254
     255   // initializes the source and destination buffers
     256   giet_fbf_cma_init_buf( &display[0][0][0] ,
     257                          &display[1][0][0] ,
     258                          status0 ,
     259                          status1 );
     260
     261   // activates CMA channel
     262   giet_fbf_cma_start( HEIGHT * WIDTH );
     263
     264   // initializes distributed heap
     265   unsigned int cx;
     266   unsigned int cy;
     267   for ( cx = 0 ; cx < x_size ; cx++ )
     268   {
     269      for ( cy = 0 ; cy < y_size ; cy++ )
     270      {
     271         heap_init( cx , cy );
     272      }
     273   }
     274
     275   // initialises barrier
     276   sqt_barrier_init( &barrier , x_size , y_size , nprocs );
     277
     278   giet_tty_printf("\n[GAMEOFLIFE] P[%d,%d,%d] completes initialisation at cycle %d\n"
     279                   " nprocs = %d / nlines = %d / nthreads = %d\n",
     280                   x, y, p, giet_proctime() , total_procs , HEIGHT , nthreads );
     281
     282   // compute arguments (index, nlines) for all threads
     283   unsigned int n;                   // thread index
     284   unsigned int index;               // first line index
     285   for ( n = 0 , index = 0 ; n < nthreads ; n++ )
     286   {
     287      if ( extra )
     288      {
     289         args[n].index = index;
     290         args[n].lines = nlines + 1;
     291         index         = index + nlines + 1;
     292      }
     293      else
     294      {
     295         args[n].index = index;
     296         args[n].lines = nlines;
     297         index         = index + nlines;
     298      }
     299#if VERBOSE     
     300giet_tty_printf("[GAMEOFLIFE] Thread %d : first = %d / nlines = %d\n",
     301                n , args[n].index , args[n].lines );
     302#endif
     303   }
     304
     305   // launch all other threads
     306   pthread_t  trdid;                 // unused because no pthread_join()
     307   for ( n = 1 ; n < nthreads ; n++ )
     308   {
     309      if ( giet_pthread_create( &trdid,
     310                                NULL,                  // no attribute
     311                                &execute,
     312                                &args[n] ) )
     313      {
     314          giet_tty_printf("\n[TRANSPOSE ERROR] creating thread %x\n", n );
     315          giet_pthread_exit( NULL );
     316      }
     317   }
     318
     319   // run execute function
     320   execute( &args[0] );
     321
     322   giet_pthread_exit( "completed" );
     323   
    264324} // end main()
     325
     326
    265327
    266328// Local Variables:
  • soft/giet_vm/applications/gameoflife/gameoflife.py

    r669 r708  
    1010#  This file describes the mapping of the multi-threaded "gameoflife"
    1111#  application on a multi-clusters, multi-processors architecture.
    12 #  This include both the mapping of virtual segments on the clusters,
    13 #  and the mapping of tasks on processors.
    14 #  There is one task per processor.
     12#  There is one thread per processor.
    1513#  The mapping of virtual segments is the following:
    1614#    - There is one shared data vseg in cluster[0][0]
     
    102100            if ( mapping.clusters[cluster_id].procs ):
    103101                for p in xrange( nprocs ):
    104                     trdid = (((x * y_size) + y) * nprocs) + p
     102                    if (x == 0) and (y == 0) and (p == 0) :   # main thread
     103                        startid = 1
     104                        is_main = True
     105                    else :                                    # other threads
     106                        startid = 0
     107                        is_main = False
    105108
    106                     mapping.addTask( vspace, 'gol_%d_%d_%d' % (x,y,p),
    107                                      trdid, x, y, p,
    108                                      'gol_stack_%d_%d_%d' % (x,y,p),
    109                                      'gol_heap_%d_%d' %(x,y) , 0 ) 
     109                    mapping.addThread( vspace,
     110                                       'gol_%d_%d_%d' % (x,y,p),
     111                                       is_main,
     112                                       x, y, p,
     113                                       'gol_stack_%d_%d_%d' % (x,y,p),
     114                                       'gol_heap_%d_%d' % (x,y),
     115                                       startid )
    110116
    111117    # extend mapping name
  • soft/giet_vm/applications/raycast/Makefile

    r673 r708  
     1
     2CC = mipsel-unknown-elf-gcc
     3AS = mipsel-unknown-elf-as
     4LD = mipsel-unknown-elf-ld
     5DU = mipsel-unknown-elf-objdump
     6AR = mipsel-unknown-elf-ar
    17
    28APP_NAME = raycast
    39
    4 OBJS = ctrl.o disp.o game.o main.o
     10OBJS = disp.o game.o raycast.o
    511
    612LIBS = -L../../build/libs -luser -lmath
  • soft/giet_vm/applications/raycast/disp.c

    r692 r708  
    66#include <math.h>
    77#include <hard_config.h>
    8 #include <user_sqt_lock.h>
     8#include <user_lock.h>
    99
    1010#define FIELD_OF_VIEW   (70.f * M_PI / 180.f)   // Camera field of view
     
    1313#define FLOOR_COLOR     (0x33)                  // dark gray
    1414
    15 // Globals
    16 
    17 static unsigned char*           buf[2];         // framebuffer
    18 static void *                   sts[2];         // for fbf_cma
    19 static unsigned int             cur_buf;        // current framebuffer
    20 static volatile unsigned int    slice_x;        // slice index (shared)
    21 static sqt_lock_t               slice_x_lock;   // slice index lock
    22 static volatile unsigned int    slice_cnt;      // slice count (shared)
    23 
    24 // Textures indexed by block number
    25 static unsigned char *g_tex[] =
    26 {
    27     NULL, // 0
    28     NULL, // rock
    29     NULL, // door
    30     NULL, // handle
    31     NULL, // wood
    32 };
    33 
     15
     16////////////////////////////
     17// Extern variables
     18////////////////////////////
     19
     20extern unsigned char*  g_tex[5];
     21extern unsigned char*  buf[2];
     22extern void*           sts[2];
     23extern unsigned int    cur_buf;
     24extern unsigned int    slice_x;
     25extern unsigned int    slice_count;
     26extern sqt_lock_t      slice_get_lock;
     27extern sqt_lock_t      slice_done_lock;
     28extern Game            game;
     29
     30//////////////////////
    3431// Local functions
    35 
     32////////////////////////
     33
     34/////////////////////////////////////////////////////////////////////////
    3635static void dispDrawColumnTex(int x, int y0, int y1, unsigned char *line)
    3736{
     
    4746}
    4847
     48///////////////////////////////////////////////////////////////////////////
    4949static void dispDrawColumnSolid(int x, int y0, int y1, unsigned char color)
    5050{
     
    5757}
    5858
    59 static void dispDrawSlice(Game *game, int x, int height, int type, int tx)
     59////////////////////////////////////////////////////////////////
     60static void dispDrawSlice( int x, int height, int type, int tx )
    6061{
    6162    // Ceiling
     
    9091}
    9192
    92 static float dispRaycast(Game *game, int *type, float *tx, float angle)
    93 {
    94     float x = game->player.x;
    95     float y = game->player.y;
     93///////////////////////////////////////////////////////////////////////
     94static float dispRaycast( int *type, float *tx, float angle )
     95{
     96    float x = game.player.x;
     97    float y = game.player.y;
    9698
    9799    // Camera is inside a block.
     
    162164}
    163165
     166////////////////////////////////////////////////////////////////
    164167static void dispTranspose(unsigned char *buf, unsigned int size)
    165168{
     
    179182}
    180183
    181 static unsigned char *dispLoadTexture(char *path)
     184////////////////////////
     185// Exported functions
     186////////////////////////
     187
     188//////////////////////////////////////////
     189unsigned char* dispLoadTexture(char *path)
    182190{
    183191    int fd;
     
    186194    tex = malloc(TEX_SIZE * TEX_SIZE);
    187195    fd = giet_fat_open(path, O_RDONLY);
    188     if (fd < 0) {
     196    if (fd < 0)
     197    {
    189198        free(tex);
    190199        return NULL;
     
    196205    dispTranspose(tex, TEX_SIZE);
    197206
    198     giet_tty_printf("[RAYCAST] loaded tex %s\n", path);
    199 
    200207    return tex;
    201208}
    202209
    203 // Exported functions
    204 
    205 void dispInit()
    206 {
    207     unsigned int w, h, p;
    208 
    209     // Initialize lock
    210     giet_procs_number(&w, &h, &p);
    211     sqt_lock_init(&slice_x_lock, w, h, p);
    212 
    213     // Allocate framebuffer
    214     buf[0] = malloc(FBUF_X_SIZE * FBUF_Y_SIZE);
    215     buf[1] = malloc(FBUF_X_SIZE * FBUF_Y_SIZE);
    216     sts[0] = malloc(64);
    217     sts[1] = malloc(64);
    218 
    219     // Initialize framebuffer
    220     giet_fbf_cma_alloc();
    221     giet_fbf_cma_init_buf(buf[0], buf[1], sts[0], sts[1]);
    222     giet_fbf_cma_start(FBUF_X_SIZE * FBUF_Y_SIZE);
    223 
    224     // Load textures
    225     g_tex[1] = dispLoadTexture("misc/rock_32.raw");
    226     g_tex[2] = dispLoadTexture("misc/door_32.raw");
    227     g_tex[3] = dispLoadTexture("misc/handle_32.raw");
    228     g_tex[4] = dispLoadTexture("misc/wood_32.raw");
    229 
    230     cur_buf = 0;
    231     slice_cnt = 0;
    232     slice_x = FBUF_X_SIZE;
    233 }
    234 
    235 int dispRenderSlice(Game *game)
    236 {
    237     unsigned int x;
     210///////////////////////////////////////////////////
     211unsigned int dispRenderSlice( unsigned int* slice )
     212{
     213    // return 0 when there is no more slice to do
     214
    238215    int type;
    239216    float angle, dist, tx;
    240 
    241     sqt_lock_acquire(&slice_x_lock);
    242 
    243     if (slice_x == FBUF_X_SIZE) {
    244         // No more work to do for this frame
    245         sqt_lock_release(&slice_x_lock);
     217    unsigned int x;
     218
     219    // get a slice index
     220    sqt_lock_acquire( &slice_get_lock );
     221
     222    if (slice_x >= FBUF_X_SIZE)      // No more work to do for this frame
     223    {
     224        sqt_lock_release( &slice_get_lock );
    246225        return 0;
    247226    }
    248     else {
    249         // Keep slice coordinate
    250         x = slice_x++;
    251     }
    252 
    253     sqt_lock_release(&slice_x_lock);
    254 
    255     angle = game->player.dir - FIELD_OF_VIEW / 2.f +
     227    else                             // Keep slice coordinate
     228    {
     229        x       = slice_x;
     230        slice_x = x + 1;
     231        sqt_lock_release( &slice_get_lock );
     232        *slice  = x;
     233    }
     234
     235    // Cast a ray to get wall distance
     236    angle = game.player.dir - FIELD_OF_VIEW / 2.f +
    256237            x * FIELD_OF_VIEW / FBUF_X_SIZE;
    257238
    258     // Cast a ray to get wall distance
    259     dist = dispRaycast(game, &type, &tx, angle);
    260 
    261     // Perspective correction
    262     dist *= cos(game->player.dir - angle);
     239    dist = dispRaycast(&type, &tx, angle);
     240
     241    dist *= cos(game.player.dir - angle);
    263242
    264243    // Draw ceiling, wall and floor
    265     dispDrawSlice(game, x, FBUF_Y_SIZE / dist, type, tx * TEX_SIZE);
     244    dispDrawSlice(x, FBUF_Y_SIZE / dist, type, tx * TEX_SIZE);
    266245
    267246    // Signal this slice is done
    268     atomic_increment((unsigned int*)&slice_cnt, 1);
     247
     248    sqt_lock_acquire( &slice_done_lock );
     249    slice_count++;
     250    sqt_lock_release( &slice_done_lock );
    269251
    270252    return 1;
    271 }
    272 
    273 void dispRender(Game *game)
    274 {
    275     int start = giet_proctime();
    276 
    277     // Start rendering
    278     slice_cnt = 0;
    279     slice_x = 0;
    280 
    281     // Render slices
    282     while (dispRenderSlice(game));
    283 
    284     // Wait for completion
    285     while (slice_cnt != FBUF_X_SIZE);
    286 
    287     // Flip framebuffer
    288     giet_fbf_cma_display(cur_buf);
    289     cur_buf = !cur_buf;
    290     giet_tty_printf("[RAYCAST] flip (took %d cycles)\n", giet_proctime() - start);
    291 }
    292 
     253}  // end dispRenderSlice()
     254
     255
  • soft/giet_vm/applications/raycast/disp.h

    r683 r708  
    44#include "game.h"
    55
    6 void dispInit();
    7 int dispRenderSlice(Game *game);
    8 void dispRender(Game *game);
     6unsigned char* dispLoadTexture( char* path );
     7unsigned int   dispRenderSlice( unsigned int* slice );
    98
    109#endif // __DISP_H
  • soft/giet_vm/applications/raycast/game.c

    r683 r708  
    33#include "ctrl.h"
    44#include <math.h>
    5 
    6 // Globals
     5#include <stdio.h>
     6
     7//////////////////////////////
     8// Game Maps
     9//////////////////////////////
    710
    811static Map map[] =
     
    7073};
    7174
    72 static Game game =
    73 {
    74     .mapId = 0
    75 };
    76 
    77 static bool g_exit;
    78 
     75////////////////////////////
     76// extern variables
     77////////////////////////////
     78
     79extern Game         game;
     80
     81//////////////////////
    7982// Local functions
    80 
     83//////////////////////
     84
     85////////////////////////////////////
    8186static void gameOnBlockHit(int type)
    8287{
    83     g_exit = true;
    84 }
    85 
     88    giet_tty_printf("\n[RAYCAST] Fatal collision, killed...\n");
     89    game.exit = 1;
     90}
     91
     92///////////////////////////////////////////////
    8693static void gameCollision(float opx, float opy)
    8794{
    88     static bool collided_x = false;
    89     static bool collided_y = false;
    90 
    91     float px = game.player.x;
    92     float py = game.player.y;
    93     int fpx = floor(px);
    94     int fpy = floor(py);
    95     bool colliding_x = false;
    96     bool colliding_y = false;
    97     int collide_type_x = 0;
    98     int collide_type_y = 0;
    99     int type;
     95    static unsigned int collided_x = 0;
     96    static unsigned int collided_y = 0;
     97
     98    float               px = game.player.x;
     99    float               py = game.player.y;
     100    int                 fpx = floor(px);
     101    int                 fpy = floor(py);
     102    unsigned int        colliding_x = 0;
     103    unsigned int        colliding_y = 0;
     104    int                 collide_type_x = 0;
     105    int                 collide_type_y = 0;
     106    int                 type;
    100107
    101108    // Check for x axis collisions
    102     if      ((type = gameLocate(floor(px + COLLIDE_GAP), fpy))) {
    103         colliding_x = true, collide_type_x = type;
     109    if      ((type = gameLocate(floor(px + COLLIDE_GAP), fpy)))
     110    {
     111        colliding_x = 1, collide_type_x = type;
    104112        game.player.x = fpx - COLLIDE_GAP + 1;
    105113    }
    106     else if ((type = gameLocate(floor(px - COLLIDE_GAP), fpy))) {
    107         colliding_x = true, collide_type_x = type;
     114    else if ((type = gameLocate(floor(px - COLLIDE_GAP), fpy)))
     115    {
     116        colliding_x = 1, collide_type_x = type;
    108117        game.player.x = fpx + COLLIDE_GAP;
    109118    }
    110119
    111120    // Check for y axis collisions
    112     if      ((type = gameLocate(fpx, floor(py + COLLIDE_GAP)))) {
    113         colliding_y = true, collide_type_y = type;
     121    if      ((type = gameLocate(fpx, floor(py + COLLIDE_GAP))))
     122    {
     123        colliding_y = 1, collide_type_y = type;
    114124        game.player.y = fpy - COLLIDE_GAP + 1;
    115125    }
    116     else if ((type = gameLocate(fpx, floor(py - COLLIDE_GAP)))) {
    117         colliding_y = true, collide_type_y = type;
     126    else if ((type = gameLocate(fpx, floor(py - COLLIDE_GAP))))
     127    {
     128        colliding_y = 1, collide_type_y = type;
    118129        game.player.y = fpy + COLLIDE_GAP;
    119130    }
    120131
    121132    // Check if we're inside a wall
    122     if ((type = gameLocate(fpx, fpy))) {
    123         colliding_x = true, collide_type_x = type;
    124         colliding_y = true, collide_type_y = type;
    125         game.player.x = opx, game.player.y = opy;
     133    if ((type = gameLocate(fpx, fpy)))
     134    {
     135        colliding_x   = 1   , collide_type_x = type;
     136        colliding_y   = 1   , collide_type_y = type;
     137        game.player.x = opx , game.player.y = opy;
    126138    }
    127139
     
    136148}
    137149
    138 static void gameLogic()
    139 {
    140     float opx = game.player.x;
    141     float opy = game.player.y;
    142 
    143     ctrlLogic(&game);
    144     gameCollision(opx, opy);
    145 }
    146 
    147 static void gameInitMap()
    148 {
    149     game.map = &map[game.mapId];
    150     game.player.x = game.map->startX;
    151     game.player.y = game.map->startY;
     150/////////////////////////
     151// Exported functions
     152/////////////////////////
     153
     154///////////////
     155void gameInit()
     156{
     157    game.mapId      = 0;
     158    game.map        = &map[0];
     159    game.player.x   = game.map->startX;
     160    game.player.y   = game.map->startY;
    152161    game.player.dir = game.map->startDir;
    153     game.timeLeft = TIME_TOTAL;
    154 }
    155 
    156 // Exported functions
    157 
     162    game.timeLeft   = TIME_TOTAL;
     163    game.exit       = 0;
     164}
     165
     166//////////////////
     167void gameControl()
     168{
     169    // Only six commands are accepted:
     170    // - key Q         : quit game
     171    // - key UP        : forward move
     172    // - key DOWN      : backward move
     173    // - key RIGHT     : right move
     174    // - key LEFT      : left move
     175    // - any other key : continue
     176    // several moves can be made before continue
     177
     178    char c;
     179    unsigned int state = 0;
     180    unsigned int done  = 0;
     181
     182    // display prompt
     183    giet_tty_printf("\n[RAYCAST] > " );
     184
     185    // get one command
     186    while ( done == 0 )
     187    {
     188        // get one character       
     189        giet_tty_getc( &c );
     190
     191        if (state == 0) // first character
     192        {
     193            if      (c == 0x1B)         // ESCAPE : possible player move 
     194            {
     195                state = 1;
     196            }
     197            else if (c == 0x71)         // quit game
     198            {
     199                game.exit = 1;
     200                done = 1;
     201                giet_tty_printf("QUIT\n");
     202            }
     203            else                        // continue
     204            {
     205                done = 1;
     206                giet_tty_printf("\n");
     207            }
     208        }
     209        else if (state == 1) // previous character was ESCAPE
     210        {
     211            if      (c == 0x5B)        // BRAKET : possible player move
     212            {
     213                state = 2;
     214            }
     215            else                       // continue
     216            {
     217                done = 1;
     218                giet_tty_printf("\n");
     219            }
     220        }
     221        else  // previous characters were ESCAPE,BRACKET
     222        {
     223            if      (c == 0x41)        // UP arrow <=> forward move
     224            {
     225                game.player.x += PLAYER_MOVE * cos(game.player.dir);
     226                game.player.y += PLAYER_MOVE * sin(game.player.dir);
     227                giet_tty_printf("GO ");
     228                state = 0;
     229            }
     230            else if (c == 0x42)        // DOWN arrow <=> backward move
     231            {
     232                game.player.x -= PLAYER_MOVE * cos(game.player.dir);
     233                game.player.y -= PLAYER_MOVE * sin(game.player.dir);
     234                giet_tty_printf("BACK ");
     235                state = 0;
     236            }
     237            else if (c == 0x43)        // RIGHT arrow <=> turn right     
     238            {
     239                game.player.dir += PLAYER_ROT;
     240                giet_tty_printf("RIGHT ");
     241                state = 0;
     242            }
     243            else if (c == 0x44)        // LEFT arrow <=> turn left     
     244            {
     245                game.player.dir -= PLAYER_ROT;
     246                giet_tty_printf("LEFT ");
     247                state = 0;
     248            }
     249            else                       // continue
     250            {
     251                done = 1;
     252                giet_tty_printf("\n");
     253            }
     254        }
     255    }  // end while
     256   
     257    // check new position
     258    int hit = gameLocate( game.player.x , game.player.y );
     259    if ( hit )  gameOnBlockHit( hit );
     260}
     261
     262////////////////////////////
    158263int gameLocate(int x, int y)
    159264{
    160265    if ((x < 0 || x >= game.map->w) ||
    161         (y < 0 || y >= game.map->h)) {
     266        (y < 0 || y >= game.map->h))
     267    {
    162268        // Outside the map bounds
    163269        return 1;
     
    167273}
    168274
    169 void gameRun()
    170 {
    171     gameInitMap();
    172 
    173     g_exit = false;
    174 
    175     // Game loop
    176     while (!g_exit) {
    177         gameLogic();
    178         dispRender(&game);
    179     }
    180 
    181     if (game.timeLeft == 0) {
    182         // Time's up!
    183         game.mapId = 0;
    184     }
    185     else {
    186         // Go to next map
    187         game.mapId++;
    188     }
    189 }
    190 
     275///////////////
    191276void gameTick()
    192277{
    193278    game.timeLeft--;
    194279
    195     if (game.timeLeft == 0) {
    196         g_exit = true;
    197     }
    198 }
    199 
    200 Game *gameInstance()
    201 {
    202     return &game;
    203 }
     280    if (game.timeLeft == 0)
     281    {
     282        game.exit = 1;
     283    }
     284}
     285
  • soft/giet_vm/applications/raycast/game.h

    r683 r708  
    22#define __GAME_H
    33
    4 #include <stdint.h>
    5 #include <stdbool.h>
    64
    75#define M_PI            (3.14159f)
     
    119#define TIME_TOTAL      (30)
    1210
    13 typedef struct
     11typedef struct 
    1412{
    1513    float x;
     
    2018typedef struct
    2119{
    22     uint8_t tile[10][10];
    23     uint8_t w;
    24     uint8_t h;
    25     float startX;
    26     float startY;
    27     float startDir;
     20    char    tile[10][10];
     21    char    w;
     22    char    h;
     23    float   startX;
     24    float   startY;
     25    float   startDir;
    2826} Map;
    2927
    3028typedef struct
    31 {
    32     Player player;
    33     Map *map;
    34     int mapId;
    35     int timeLeft;
     29{   
     30    Player   player;
     31    Map      *map;
     32    int      mapId;
     33    int      timeLeft;
     34    int      exit;        // exit requested
    3635} Game;
    3736
    38 int gameLocate(int x, int y);
    39 void gameRun();
     37
     38void gameInit();
     39int  gameLocate(int x, int y);
     40void gameControl();
    4041void gameTick();
    41 Game *gameInstance();
    4242
    4343#endif // __GAME_H
  • soft/giet_vm/applications/raycast/raycast.py

    r683 r708  
    1010#  This file describes the mapping of the multi-threaded "raycast" application
    1111#  on a multi-clusters, multi-processors architecture.
    12 #  The mapping of tasks on processors is the following:
    13 #    - one "main" task on (0,0,0)
    14 #    - one "render" task per processor but (0,0,0)
     12#  The mapping of threads on processors is the following:
     13#    - one "main" thread on (0,0,0)
     14#    - one "render" thread per processor but (0,0,0)
    1515#  The mapping of virtual segments is the following:
    1616#    - There is one shared data vseg in cluster[0][0]
     
    8989                mapping.addVseg( vspace, 'raycast_heap_%d_%d' %(x,y), base , size,
    9090                                 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM',
    91                                  local = False )
     91                                 local = False, big = True )
    9292
    93     # distributed tasks / one task per processor
     93    # distributed threads / one thread per processor
    9494    for x in xrange (x_size):
    9595        for y in xrange (y_size):
     
    9898                for p in xrange( nprocs ):
    9999                    trdid = (((x * y_size) + y) * nprocs) + p
    100                     if  ( x == 0 and y == 0 and p == 0 ):       # main task
    101                         task_index = 1
    102                         task_name  = 'main_%d_%d_%d' %(x,y,p)
    103                     else:                                       # render task
    104                         task_index = 0
    105                         task_name  = 'render_%d_%d_%d' % (x,y,p)
     100                    if  ( x == 0 and y == 0 and p == 0 ):       # main thread
     101                        start_id = 1
     102                        is_main  = True
     103                    else:                                       # render thread
     104                        start_id = 0
     105                        is_main  = False
    106106
    107                     mapping.addTask( vspace, task_name, trdid, x, y, p,
    108                                      'raycast_stack_%d_%d_%d' % (x,y,p),
    109                                      'raycast_heap_%d_%d' % (x,y),
    110                                      task_index )
     107                    mapping.addThread( vspace,
     108                                       'raycast_%d_%d_%d' % (x,y,p),
     109                                       is_main,
     110                                       x, y, p,
     111                                       'raycast_stack_%d_%d_%d' % (x,y,p),
     112                                       'raycast_heap_%d_%d' % (x,y),
     113                                       start_id )
    111114
    112115    # extend mapping name
  • soft/giet_vm/applications/shell/Makefile

    r589 r708  
    22APP_NAME = shell
    33
    4 OBJS = main.o
     4OBJS = shell.o
    55
    66LIBS = -L../../build/libs -luser
  • soft/giet_vm/applications/shell/shell.c

    r707 r708  
    11///////////////////////////////////////////////////////////////////////////////////////
    2 // File   : main.c   (for shell application)
     2// File   : shell.c   
    33// Date   : july 2015
    44// author : Clément Guérin
     
    1717{
    1818    char *name;
     19    char *desc;
    1920    void (*fn)(int, char**);
    2021};
     
    3536    for (i = 0; cmd[i].name; i++)
    3637    {
    37         giet_tty_printf("\t%s\n", cmd[i].name);
    38     }
    39 }
    40 
    41 ///////////////////////////////////////////////
    42 static void cmd_proctime(int argc, char** argv)
    43 {
    44     giet_tty_printf("%u\n", giet_proctime());
     38        giet_tty_printf("\t%s\t : %s\n", cmd[i].name , cmd[i].desc );
     39    }
     40}
     41
     42///////////////////////////////////////////
     43static void cmd_time(int argc, char** argv)
     44{
     45    giet_tty_printf("%d\n", giet_proctime());
    4546}
    4647
     
    5253
    5354    if (argc < 2)
    54         fd = giet_fat_opendir("/");
    55     else
    56         fd = giet_fat_opendir(argv[1]);
     55    {
     56        giet_tty_printf("  usage : %s <pathname>\n", argv[0]);
     57        return;
     58    }
     59
     60    fd = giet_fat_opendir(argv[1]);
    5761
    5862    if (fd < 0)
    5963    {
    60         giet_tty_printf("can't list directory (err=%d)\n", fd);
     64        giet_tty_printf("  error : cannot open %s / err = %d)\n", argv[1], fd);
    6165        return;
    6266    }
     
    8185    if (argc < 2)
    8286    {
    83         giet_tty_printf("%s <path>\n", argv[0]);
     87        giet_tty_printf("  usage : %s <path>\n", argv[0]);
    8488        return;
    8589    }
    8690
    8791    int ret = giet_fat_mkdir(argv[1]);
     92
    8893    if (ret < 0)
    8994    {
    90         giet_tty_printf("can't create directory (err=%d)\n", ret);
     95        giet_tty_printf("  error : cannot create directory %s / err = %d\n", argv[1], ret);
    9196    }
    9297}
     
    97102    if (argc < 3)
    98103    {
    99         giet_tty_printf("%s <src> <dst>\n", argv[0]);
     104        giet_tty_printf("  usage : %s <src> <dst>\n", argv[0]);
    100105        return;
    101106    }
     
    111116    if (src_fd < 0)
    112117    {
    113         giet_tty_printf("can't open %s (err=%d)\n", argv[1], src_fd);
     118        giet_tty_printf("  error : cannot open %s / err = %d\n", argv[1], src_fd);
    114119        goto exit;
    115120    }
    116121
    117122    giet_fat_file_info(src_fd, &info);
     123
    118124    if (info.is_dir)
    119125    {
    120         giet_tty_printf("can't copy a directory\n");
     126        giet_tty_printf("  error : %s is a directory\n", argv[1] );
    121127        goto exit;
    122128    }
     129
    123130    size = info.size;
    124131
    125132    dst_fd = giet_fat_open( argv[2] , O_CREATE | O_TRUNC );
     133
    126134    if (dst_fd < 0)
    127135    {
    128         giet_tty_printf("can't open %s (err=%d)\n", argv[2], dst_fd);
     136        giet_tty_printf("  error : cannot open %s / err = %d\n", argv[2], dst_fd);
    129137        goto exit;
    130138    }
    131139
    132140    giet_fat_file_info(dst_fd, &info);
     141
    133142    if (info.is_dir)
    134143    {
    135         giet_tty_printf("can't copy to a directory\n"); // TODO
     144        giet_tty_printf("error : %s is a directory\n", argv[2] ); // TODO
    136145        goto exit;
    137146    }
     
    149158        if (wlen != len)
    150159        {
    151             giet_tty_printf("\nwrite error\n");
     160            giet_tty_printf("  error : cannot write on device\n");
    152161            goto exit;
    153162        }
     
    168177    if (argc < 2)
    169178    {
    170         giet_tty_printf("%s <file>\n", argv[0]);
     179        giet_tty_printf("  usage : %s <file>\n", argv[0]);
    171180        return;
    172181    }
    173182
    174183    int ret = giet_fat_remove(argv[1], 0);
     184
    175185    if (ret < 0)
    176186    {
    177         giet_tty_printf("can't remove %s (err=%d)\n", argv[1], ret);
     187        giet_tty_printf("  error : cannot remove %s / err = %d\n", argv[1], ret );
    178188    }
    179189}
     
    184194    if (argc < 2)
    185195    {
    186         giet_tty_printf("%s <path>\n", argv[0]);
     196        giet_tty_printf("  usage : %s <pathname>\n", argv[0]);
    187197        return;
    188198    }
     
    191201    if (ret < 0)
    192202    {
    193         giet_tty_printf("can't remove %s (err=%d)\n", argv[1], ret);
     203        giet_tty_printf("  error : cannot remove %s / err = %d\n", argv[1], ret );
    194204    }
    195205}
     
    200210    if (argc < 3)
    201211    {
    202         giet_tty_printf("%s <src> <dst>\n", argv[0]);
     212        giet_tty_printf("  usage : %s <src> <dst>\n", argv[0]);
    203213        return;
    204214    }
     
    207217    if (ret < 0)
    208218    {
    209         giet_tty_printf("can't move %s to %s (err=%d)\n", argv[1], argv[2], ret);
     219        giet_tty_printf("error : cannot move %s to %s / err = %d\n", argv[1], argv[2], ret );
    210220    }
    211221}
     
    216226    if (argc < 2)
    217227    {
    218         giet_tty_printf("%s <pathname>\n", argv[0]);
     228        giet_tty_printf("  usage : %s <vspace_name>\n", argv[0]);
    219229        return;
    220230    }
     
    223233    if ( ret == -1 )
    224234    {
    225         giet_tty_printf("\n  error : %s not found\n", argv[1] );
     235        giet_tty_printf("  error : %s not found\n", argv[1] );
    226236    }
    227237}
     
    232242    if (argc < 2)
    233243    {
    234         giet_tty_printf("%s <pathname>\n", argv[0]);
     244        giet_tty_printf("  usage : %s <vspace_name>\n", argv[0]);
    235245        return;
    236246    }
     
    239249    if ( ret == -1 )
    240250    {
    241         giet_tty_printf("\n  error : %s not found\n", argv[1] );
     251        giet_tty_printf("  error : %s not found\n", argv[1] );
    242252    }
    243253    if ( ret == -2 )
    244254    {
    245         giet_tty_printf("\n  error : %s cannot be killed\n", argv[1] );
    246     }
    247 }
    248 
    249 ///////////////////////////////////////////////
     255        giet_tty_printf("  error : %s cannot be killed\n", argv[1] );
     256    }
     257}
     258
     259/////////////////////////////////////////
    250260static void cmd_ps(int argc, char** argv)
    251261{
    252     giet_tasks_status();
    253 }
    254 
    255 ///////////////////////////////////////////////
    256 static void cmd_sleep(int argc, char** argv)
    257 {
    258     int start = giet_proctime();
    259 
    260     if (argc < 2)
    261     {
    262         giet_tty_printf("%s <cycles>\n", argv[0]);
    263         return;
    264     }
    265 
    266     while (giet_proctime() < start + atoi(argv[1]));
    267 }
     262    giet_applications_status();
     263}
     264
     265////////////////////////////////////////////
     266static void cmd_pause(int argc, char** argv)
     267{
     268    if (argc < 3)
     269    {
     270        giet_tty_printf("  usage : %s <vspace_name> <thread_name>\n", argv[0] );
     271        return;
     272    }
     273
     274    int ret = giet_pthread_pause( argv[1] , argv[2] );
     275
     276    if ( ret == -1 )
     277    {
     278        giet_tty_printf("  error : vspace %s not found\n", argv[1] );
     279    }
     280    if ( ret == -2 )
     281    {
     282        giet_tty_printf("  error : thread %s not found\n", argv[2] );
     283    }
     284}
     285
     286/////////////////////////////////////////////
     287static void cmd_resume(int argc, char** argv)
     288{
     289    if (argc < 3)
     290    {
     291        giet_tty_printf("  usage : %s <vspace_name> <thread_name>\n", argv[0] );
     292        return;
     293    }
     294
     295    int ret = giet_pthread_resume( argv[1] , argv[2] );
     296
     297    if ( ret == -1 )
     298    {
     299        giet_tty_printf("  error : vspace %s not found\n", argv[1] );
     300    }
     301    if ( ret == -2 )
     302    {
     303        giet_tty_printf("  error : thread %s not found\n", argv[2] );
     304    }
     305}
     306
     307/////////////////////////////////////////////
     308static void cmd_context(int argc, char** argv)
     309{
     310    if (argc < 3)
     311    {
     312        giet_tty_printf("  usage : %s <vspace_name> <thread_name>\n", argv[0] );
     313        return;
     314    }
     315
     316    int ret = giet_pthread_context( argv[1] , argv[2] );
     317
     318    if ( ret == -1 )
     319    {
     320        giet_tty_printf("  error : vspace %s not found\n", argv[1] );
     321    }
     322    if ( ret == -2 )
     323    {
     324        giet_tty_printf("  error : thread %s not found\n", argv[2] );
     325    }
     326}
     327
    268328
    269329////////////////////////////////////////////////////////////////////
    270330struct command_t cmd[] =
    271331{
    272     { "help",       cmd_help },
    273     { "proctime",   cmd_proctime },
    274     { "ls",         cmd_ls },
    275     { "mkdir",      cmd_mkdir },
    276     { "cp",         cmd_cp },
    277     { "rm",         cmd_rm },
    278     { "rmdir",      cmd_rmdir },
    279     { "mv",         cmd_mv },
    280     { "exec",       cmd_exec },
    281     { "kill",       cmd_kill },
    282     { "ps",         cmd_ps },
    283     { "sleep",      cmd_sleep },
    284     { NULL,         NULL }
     332    { "help",       "list available commands",              cmd_help },
     333    { "time",       "return current date",                  cmd_time },
     334    { "ls",         "list content of a directory",          cmd_ls },
     335    { "mkdir",      "create a new directory",               cmd_mkdir },
     336    { "cp",         "replicate a file in file system",      cmd_cp },
     337    { "rm",         "remove a file from file system",       cmd_rm },
     338    { "rmdir",      "remove a directory from file system",  cmd_rmdir },
     339    { "mv",         "move a file in file system",           cmd_mv },
     340    { "exec",       "start an application",                 cmd_exec },
     341    { "kill",       "kill an application (all threads)",    cmd_kill },
     342    { "ps",         "list all mapped applications status",  cmd_ps },
     343    { "pause",      "pause a thread",                       cmd_pause },
     344    { "resume",     "resume a thread",                      cmd_resume },
     345    { "context",    "display a thread context",             cmd_context },
     346    { NULL,         NULL,                                   NULL }
    285347};
    286348
    287349// shell
    288350
    289 ///////////////////////////////////////
     351////////////////////////////
    290352static void parse(char *buf)
    291353{
     
    351413    // get a private TTY
    352414    giet_tty_alloc( 0 );
    353     giet_tty_printf( "~~~ shell ~~~\n" );
     415    giet_tty_printf( "~~~ shell ~~~\n\n" );
    354416
    355417    // display first prompt
  • soft/giet_vm/applications/shell/shell.py

    r643 r708  
    5858
    5959    # task
    60     mapping.addTask( vspace, 'shell', 0, 0, 0, 0, 'shell_stack', 'shell_heap', 0 )
     60    mapping.addThread( vspace, 'shell', True, 0, 0, 0, 'shell_stack', 'shell_heap', 0 )
    6161
    6262    # extend mapping name
  • soft/giet_vm/applications/transpose/Makefile

    r589 r708  
     1
     2CC = mipsel-unknown-elf-gcc
     3AS = mipsel-unknown-elf-as
     4LD = mipsel-unknown-elf-ld
     5DU = mipsel-unknown-elf-objdump
     6AR = mipsel-unknown-elf-ar
    17
    28APP_NAME = transpose
    39
    4 OBJS= main.o
     10OBJS= transpose.o
    511
    612LIBS= -L../../build/libs -luser
  • soft/giet_vm/applications/transpose/transpose.py

    r669 r708  
    1010#  This file describes the mapping of the multi-threaded "transpose"
    1111#  application on a multi-clusters, multi-processors architecture.
    12 #  This include both the mapping of virtual segments on the clusters,
    13 #  and the mapping of tasks on processors.
    14 #  There is one task per processor.
     12#  There is one thread per processor.
    1513#  The mapping of virtual segments is the following:
    1614#    - There is one shared data vseg in cluster[0][0]
     
    3735    # define vsegs base & size
    3836    code_base  = 0x10000000
    39     code_size  = 0x00010000     # 64 Kbytes (replicated in each cluster)
     37    code_size  = 0x00010000     # 64 Kbytes (per cluster)
    4038   
    4139    data_base  = 0x20000000
     
    4341
    4442    stack_base = 0x40000000
    45     stack_size = 0x00200000     # 2 Mbytes (per cluster)
     43    stack_size = 0x00010000     # 64 Kbytes (per thread)
    4644
    4745    heap_base  = 0x60000000
     
    7674                for p in xrange( nprocs ):
    7775                    proc_id = (((x * y_size) + y) * nprocs) + p
    78                     size    = (stack_size / nprocs) & 0xFFFFF000
    79                     base    = stack_base + (proc_id * size)
     76                    base    = stack_base + (proc_id * stack_size)
    8077
    8178                    mapping.addVseg( vspace, 'trsp_stack_%d_%d_%d' % (x,y,p),
    82                                      base, size, 'C_WU', vtype = 'BUFFER',
     79                                     base, stack_size, 'C_WU', vtype = 'BUFFER',
    8380                                     x = x , y = y , pseg = 'RAM',
    8481                                     local = True, big = True )
     
    9693                                 local = False, big = True )
    9794
    98     # distributed tasks / one task per processor
     95    # distribute one thread per processor / main on P[0,0,0]
    9996    for x in xrange (x_size):
    10097        for y in xrange (y_size):
     
    10299            if ( mapping.clusters[cluster_id].procs ):
    103100                for p in xrange( nprocs ):
    104                     trdid = (((x * y_size) + y) * nprocs) + p
     101                    if (x == 0) and (y == 0) and (p == 0) :   # main thread
     102                        startid = 1
     103                        is_main = True
     104                    else :                                    # other threads
     105                        startid = 0
     106                        is_main = False
    105107
    106                     mapping.addTask( vspace, 'trsp_%d_%d_%d' % (x,y,p),
    107                                      trdid, x, y, p,
    108                                      'trsp_stack_%d_%d_%d' % (x,y,p),
    109                                      'trsp_heap_%d_%d' % (x,y), 0 )
     108                    mapping.addThread( vspace,
     109                                       'trsp_%d_%d_%d' % (x,y,p),
     110                                       is_main,
     111                                       x, y, p,
     112                                       'trsp_stack_%d_%d_%d' % (x,y,p),
     113                                       'trsp_heap_%d_%d' % (x,y),
     114                                       startid )
    110115
    111116    # extend mapping name
Note: See TracChangeset for help on using the changeset viewer.