source: soft/giet_vm/applications/router/router.py

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

Adapt the router application to the POSIX API.

File size: 6.0 KB
Line 
1#!/usr/bin/env python
2
3from mapping import *
4
5######################################################################################
6#   file   : router.py
7#   date   : november 2014
8#   author : Alain Greiner
9#######################################################################################
10#  This file describes the mapping of the multi-threaded "router"
11#  application on a multi-clusters, multi-processors architecture.
12#  This application contains N+2 parallel threads communicating through MWMR channels:
13#  The mapping of virtual segments on the clusters is the following:
14#    - the data vseg is mapped on cluster[0,0].
15#    - The code vsegs are replicated on all clusters.
16#    - the stack vsegs are distibuted on all clusters.
17#    - the heap vsegs are distributed on all clusters
18#  The mapping of threads on processors is the following:
19#    - the "main" thread      => on proc[0,0,0]
20#    - the "producer" thread  => on proc[0,0,0]
21#    - the "consume"  thread  => on proc[0,0,1]
22#    - N   "compute"  threads => on all others processors
23#  This mapping uses 5 platform parameters, (obtained from the "mapping" argument)
24#    - x_size    : number of clusters in a row
25#    - y_size    : number of clusters in a column
26#    - nprocs    : number of processors per cluster
27####################################################################################
28
29######################
30def extend( mapping ):
31
32    x_size    = mapping.x_size
33    y_size    = mapping.y_size
34    nprocs    = mapping.nprocs
35    x_width   = mapping.x_width
36    y_width   = mapping.y_width
37
38    # define vsegs base & size
39    code_base    = 0x10000000
40    code_size    = 0x00010000     # 64 Kbytes (replicated in each cluster)
41   
42    data_base    = 0x20000000
43    data_size    = 0x00010000     # 64 Kbytes (non replicated)
44
45    stack_base   = 0x30000000 
46    stack_size   = 0x00010000     # 64 Kbytes (per thread)
47
48    heap_base    = 0x40000000
49    heap_size    = 0x00200000     # 2 Mbytes (per cluster)
50
51    # create vspace
52    vspace = mapping.addVspace( name = 'router', 
53                                startname = 'router_data',
54                                active = False )
55   
56    # data vseg : shared / in cluster [0,0]
57    mapping.addVseg( vspace, 'router_data', data_base , data_size, 
58                     'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', 
59                     binpath = 'bin/router/appli.elf',
60                     local = False )
61
62    # code vsegs : local (one copy in each cluster)
63    for x in xrange (x_size):
64        for y in xrange (y_size):
65            mapping.addVseg( vspace, 'router_code_%d_%d' %(x,y), code_base , code_size,
66                             'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', 
67                             binpath = 'bin/router/router.elf',
68                             local = True )
69
70    # heap vsegs : shared (one per cluster)
71    for x in xrange (x_size):
72        for y in xrange (y_size):
73            cluster_id = (x * y_size) + y
74            if ( mapping.clusters[cluster_id].procs ):
75                size  = heap_size
76                base  = heap_base + (cluster_id * size)
77
78                mapping.addVseg( vspace, 'router_heap_%d_%d' %(x,y), base , size, 
79                                 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', 
80                                 local = False, big = True )
81
82    # stacks vsegs: local (one stack per thread => nprocs stacks per cluster)
83    # ... plus main_stack in cluster[0][0]
84    mapping.addVseg( vspace, 'main_stack',
85                     stack_base, stack_size, 'C_WU', vtype = 'BUFFER', 
86                     x = 0 , y = 0 , pseg = 'RAM',
87                     local = True )
88
89    for x in xrange (x_size):
90        for y in xrange (y_size):
91            cluster_id = (x * y_size) + y
92            if ( mapping.clusters[cluster_id].procs ):
93                for p in xrange( nprocs ):
94                    proc_id = (((x * y_size) + y) * nprocs) + p
95                    base    = stack_base + (proc_id * stack_size) + stack_size
96
97                    mapping.addVseg( vspace, 'router_stack_%d_%d_%d' % (x,y,p), 
98                                     base, stack_size, 'C_WU', vtype = 'BUFFER', 
99                                     x = x , y = y , pseg = 'RAM',
100                                     local = True )
101
102    # distributed threads / one thread per processor
103    # ... plus main on P[0][0][0]
104    mapping.addThread( vspace, 'main', True, 0, 0, 1,
105                       'main_stack',
106                       'router_heap_0_0',
107                       0 )                      # index in start_vector
108
109    for x in xrange (x_size):
110        for y in xrange (y_size):
111            cluster_id = (x * y_size) + y
112            if ( mapping.clusters[cluster_id].procs ):
113                for p in xrange( nprocs ):
114                    if   (x==0) and (y==0) and (p==0):  # thread producer
115                        start_index = 3
116                        thread_name  = 'producer_0_0_0'           
117                    elif (x==0) and (y==0) and (p==1):  # thread consumer
118                        start_index = 2 
119                        thread_name  = 'consumer_0_0_1'
120                    else :                              # thread compute
121                        start_index = 1
122                        thread_name  = 'compute_%d_%d_%d' % (x,y,p)
123
124                    mapping.addThread( vspace, thread_name, False , x, y, p,
125                                      'router_stack_%d_%d_%d' % (x,y,p),
126                                      'router_heap_%d_%d' %(x,y),
127                                      start_index )
128
129    # extend mapping name
130    mapping.name += '_router'
131
132    return vspace  # useful for test
133           
134################################ test ######################################################
135
136if __name__ == '__main__':
137
138    vspace = extend( Mapping( 'test', 2, 2, 4 ) )
139    print vspace.xml()
140
141
142# Local Variables:
143# tab-width: 4;
144# c-basic-offset: 4;
145# c-file-offsets:((innamespace . 0)(inline-open . 0));
146# indent-tabs-mode: nil;
147# End:
148#
149# vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
150
Note: See TracBrowser for help on using the repository browser.