source: soft/giet_vm/applications/classif/classif.py @ 720

Last change on this file since 720 was 720, checked in by alain, 9 years ago

Adapt the router application to the POSIX API.

File size: 6.4 KB
RevLine 
[457]1#!/usr/bin/env python
2
3from mapping import *
4
[502]5###################################################################################
[589]6#   file   : classif.py
[457]7#   date   : november 2014
8#   author : Alain Greiner
[502]9###################################################################################
[457]10#  This file describes the mapping of the multi-threaded "classif"
11#  application on a multi-clusters, multi-processors architecture.
[708]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.
[502]17#  The mapping of virtual segments is the following:
[473]18#    - There is one shared data vseg in cluster[0][0]
[502]19#    - The code vsegs are replicated on all clusters containing processors.
20#    - There is one heap vseg per cluster containing processors.
21#    - The stacks vsegs are distibuted on all clusters containing processors.
[457]22#  This mapping uses 5 platform parameters, (obtained from the "mapping" argument)
23#    - x_size    : number of clusters in a row
24#    - y_size    : number of clusters in a column
25#    - x_width   : number of bits for x field
26#    - y_width   : number of bits for y field
27#    - nprocs    : number of processors per cluster
28#
[488]29#  WARNING: The target architecture cannot contain less
30#           than 3 processors per cluster.
[502]31##################################################################################
[457]32
[589]33######################
34def extend( mapping ):
[457]35
36    x_size    = mapping.x_size
37    y_size    = mapping.y_size
38    nprocs    = mapping.nprocs
39    x_width   = mapping.x_width
40    y_width   = mapping.y_width
41
[708]42    assert (nprocs >= 3) and (nprocs <= 8)
[457]43
44    # define vsegs base & size
[708]45    code_base  = 0x10000000     
46    code_size  = 0x00010000     # 64 Kbytes (per cluster)
[457]47   
48    data_base  = 0x20000000
[708]49    data_size  = 0x00010000     # 64 Kbytes (non replicated)
[457]50
[473]51    heap_base  = 0x30000000
[708]52    heap_size  = 0x00200000     # 2M bytes (per cluster)     
[473]53
[457]54    stack_base = 0x40000000 
[708]55    stack_size = 0x00010000     # 64 Kbytes (per thread)
[457]56
57    # create vspace
[720]58    vspace = mapping.addVspace( name = 'classif', 
59                                startname = 'classif_data', 
60                                active = False )
[457]61   
[473]62    # data vseg : shared / cluster[0][0]
63    mapping.addVseg( vspace, 'classif_data', data_base , data_size, 
64                     'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', 
[610]65                     binpath = 'bin/classif/appli.elf',
[473]66                     local = False )
67
[502]68    # heap vsegs : shared (one per cluster)
[457]69    for x in xrange (x_size):
70        for y in xrange (y_size):
[502]71            cluster_id = (x * y_size) + y
72            if ( mapping.clusters[cluster_id].procs ):
73                size  = heap_size
74                base  = heap_base + (cluster_id * size)
[457]75
[502]76                mapping.addVseg( vspace, 'classif_heap_%d_%d' %(x,y), base , size, 
77                                 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', 
[708]78                                 local = False, big = True )
[457]79
[708]80    # code vsegs : local (one copy per cluster)
[457]81    for x in xrange (x_size):
82        for y in xrange (y_size):
[502]83            cluster_id = (x * y_size) + y
84            if ( mapping.clusters[cluster_id].procs ):
[457]85
[502]86                mapping.addVseg( vspace, 'classif_code_%d_%d' %(x,y), 
87                                 code_base , code_size,
88                                 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', 
[610]89                                 binpath = 'bin/classif/appli.elf',
[502]90                                 local = True )
[457]91
[720]92    # stacks vsegs: local (one stack per thread => nprocs stacks per cluster)
[708]93    # ... plus main_stack in cluster[0][0]
94    mapping.addVseg( vspace, 'main_stack',
95                     stack_base, stack_size, 'C_WU', vtype = 'BUFFER', 
96                     x = 0 , y = 0 , pseg = 'RAM',
97                     local = True )
98
[457]99    for x in xrange (x_size):
100        for y in xrange (y_size):
[502]101            cluster_id = (x * y_size) + y
102            if ( mapping.clusters[cluster_id].procs ):
103                for p in xrange( nprocs ):
104                    proc_id = (((x * y_size) + y) * nprocs) + p
[708]105                    base    = stack_base + (proc_id * stack_size) + stack_size
[457]106
[502]107                    mapping.addVseg( vspace, 'classif_stack_%d_%d_%d' % (x,y,p), 
[708]108                                     base, stack_size, 'C_WU', vtype = 'BUFFER', 
[502]109                                     x = x , y = y , pseg = 'RAM',
[708]110                                     local = True )
[457]111
[708]112    # distributed threads / one thread per processor
113    # ... plus main on P[0][0][0]
114    mapping.addThread( vspace, 'main', True, 0, 0, 1,
115                       'main_stack',
116                       'classif_heap_0_0',
117                       0 )                      # index in start_vector
118
[457]119    for x in xrange (x_size):
120        for y in xrange (y_size):
[502]121            cluster_id = (x * y_size) + y
122            if ( mapping.clusters[cluster_id].procs ):
123                for p in xrange( nprocs ):
[708]124                    if  ( p== 0 ):                              # thread load
125                        start_index = 3
126                        thread_name = 'load_%d_%d_%d' %(x,y,p)           
127                    elif  ( p== 1 ):                            # thread store
128                        start_index = 2
[712]129                        thread_name = 'stor_%d_%d_%d' %(x,y,p)           
[708]130                    else :                                      # thread analyse
131                        start_index = 1
[712]132                        thread_name = 'anal_%d_%d_%d' % (x,y,p)
[473]133
[708]134                    mapping.addThread( vspace, thread_name, False , x, y, p,
135                                       'classif_stack_%d_%d_%d' % (x,y,p), 
136                                       'classif_heap_%d_%d' % (x,y),
[720]137                                       start_index ) 
[457]138
139    # extend mapping name
140    mapping.name += '_classif'
141
142    return vspace  # useful for test
143           
[533]144################################ test ############################################
[457]145
146if __name__ == '__main__':
147
[589]148    vspace = extend( Mapping( 'test', 2, 2, 4 ) )
[457]149    print vspace.xml()
150
151
152# Local Variables:
153# tab-width: 4;
154# c-basic-offset: 4;
155# c-file-offsets:((innamespace . 0)(inline-open . 0));
156# indent-tabs-mode: nil;
157# End:
158#
159# vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
160
Note: See TracBrowser for help on using the repository browser.