source: soft/giet_vm/applications/mjpeg/mjpeg.py @ 780

Last change on this file since 780 was 780, checked in by alain, 8 years ago

active = False in mjpeg.py

File size: 8.7 KB
Line 
1#!/usr/bin/env python
2
3from mapping import *
4
5###################################################################################
6#   file   : mjpeg.py
7#   date   : november 2015
8#   author : Alain Greiner
9###################################################################################
10#  This file describes the mapping of the multi-threaded "mjpeg"
11#  application on a multi-clusters, multi-processors architecture.
12#
13#  The mapping of threads on processors is the following:
14#    - the "main" thread is running on P[0,0,0].
15#    - the "demux", "iqzz", "idct", "vld", and "libu" threads, implementing
16#      a block-level pipe-line, are replicated in all clusters.
17#  In each cluster the actual mapping depends on the <nprocs> parameter.
18#
19#  The mapping of virtual segments is the following:
20#    - There is one shared data vseg in cluster[0][0]
21#    - The code vsegs are replicated in all clusters.
22#    - There is one heap vseg per cluster (containing MWMR channels).
23#    - The stacks vsegs are distibuted in all clusters.
24##################################################################################
25
26######################
27def extend( mapping ):
28
29    x_size    = mapping.x_size
30    y_size    = mapping.y_size
31    nprocs    = mapping.nprocs
32
33    assert (nprocs >= 1) and (nprocs <= 4)
34
35    # define vsegs base & size
36    code_base  = 0x10000000     
37    code_size  = 0x00010000     # 64 Kbytes (per cluster)
38   
39    data_base  = 0x20000000
40    data_size  = 0x00010000     # 64 Kbytes (non replicated)
41
42    heap_base  = 0x30000000
43    heap_size  = 0x00200000     # 2 Mbytes (per cluster)     
44
45    stack_base = 0x40000000 
46    stack_size = 0x00020000     # 128 Kbytes (per thread)
47
48    # create vspace
49    vspace = mapping.addVspace( name = 'mjpeg', 
50                                startname = 'mjpeg_data', 
51                                active = False )
52   
53    # data vseg : shared / cluster[0][0]
54    mapping.addVseg( vspace, 'mjpeg_data', data_base , data_size, 
55                     'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', 
56                     binpath = 'bin/mjpeg/appli.elf',
57                     local = False )
58
59    # heap vsegs : shared (one per cluster)
60    for x in xrange (x_size):
61        for y in xrange (y_size):
62            cluster_id = (x * y_size) + y
63            if ( mapping.clusters[cluster_id].procs ):
64                size  = heap_size
65                base  = heap_base + (cluster_id * size)
66
67                mapping.addVseg( vspace, 'mjpeg_heap_%d_%d' %(x,y), base , size, 
68                                 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', 
69                                 local = False, big = True )
70
71    # code vsegs : local (one copy per cluster)
72    for x in xrange (x_size):
73        for y in xrange (y_size):
74            cluster_id = (x * y_size) + y
75            if ( mapping.clusters[cluster_id].procs ):
76
77                mapping.addVseg( vspace, 'mjpeg_code_%d_%d' %(x,y), 
78                                 code_base , code_size,
79                                 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', 
80                                 binpath = 'bin/mjpeg/appli.elf',
81                                 local = True )
82
83    # stacks vsegs: local (one stack per thread => 5 stacks per cluster)
84    # ... plus main_stack in cluster[0][0]
85    base = stack_base
86    mapping.addVseg( vspace, 'mjpeg_main_stack',
87                     base, stack_size, 'C_WU', vtype = 'BUFFER', 
88                     x = 0 , y = 0 , pseg = 'RAM',
89                     local = True )
90
91    base += stack_size
92
93    for x in xrange (x_size):
94        for y in xrange (y_size):
95            if ( mapping.clusters[cluster_id].procs ):
96
97                mapping.addVseg( vspace, 'mjpeg_demux_stack_%d_%d' % (x,y), 
98                                 base, stack_size, 'C_WU', vtype = 'BUFFER', 
99                                 x = x , y = y , pseg = 'RAM',
100                                 local = True )
101
102                base += stack_size
103
104                mapping.addVseg( vspace, 'mjpeg_vld_stack_%d_%d' % (x,y), 
105                                 base, stack_size, 'C_WU', vtype = 'BUFFER', 
106                                 x = x , y = y , pseg = 'RAM',
107                                 local = True )
108
109                base += stack_size
110
111                mapping.addVseg( vspace, 'mjpeg_iqzz_stack_%d_%d' % (x,y), 
112                                 base, stack_size, 'C_WU', vtype = 'BUFFER', 
113                                 x = x , y = y , pseg = 'RAM',
114                                 local = True )
115
116                base += stack_size
117
118                mapping.addVseg( vspace, 'mjpeg_idct_stack_%d_%d' % (x,y), 
119                                 base, stack_size, 'C_WU', vtype = 'BUFFER', 
120                                 x = x , y = y , pseg = 'RAM',
121                                 local = True )
122
123                base += stack_size
124
125                mapping.addVseg( vspace, 'mjpeg_libu_stack_%d_%d' % (x,y), 
126                                 base, stack_size, 'C_WU', vtype = 'BUFFER', 
127                                 x = x , y = y , pseg = 'RAM',
128                                 local = True )
129
130                base += stack_size
131
132    # threads mapping: demux, vld, iqzz, idct, libu replicated in all clusters
133    # main  mapped in cluster[0,0]
134    mapping.addThread( vspace, 'main', True, 0, 0, 0,
135                       'mjpeg_main_stack',
136                       'mjpeg_heap_0_0',
137                       0 )                      # index in start_vector
138
139    if ( x==0 and y==0 ):        # tasks mapping in cluster[0,0]
140        if ( nprocs == 1 ):
141            p_demux = 0
142            p_vld   = 0
143            p_iqzz  = 0
144            p_idct  = 0
145            p_libu  = 0
146        elif ( nprocs == 2 ):
147            p_demux = 1
148            p_vld   = 1
149            p_iqzz  = 1
150            p_idct  = 1
151            p_libu  = 1
152        elif ( nprocs == 3 ):
153            p_demux = 1
154            p_vld   = 2
155            p_iqzz  = 1
156            p_idct  = 1
157            p_libu  = 1
158        elif ( nprocs == 4 ):
159            p_demux = 1
160            p_vld   = 2
161            p_iqzz  = 1
162            p_idct  = 3
163            p_libu  = 1
164    else:                        # tasks mapping in other clusters
165        if ( nprocs == 1 ):
166            p_demux = 0
167            p_vld   = 0
168            p_iqzz  = 0
169            p_idct  = 0
170            p_libu  = 0
171        elif ( nprocs == 2 ):
172            p_demux = 0
173            p_vld   = 1
174            p_iqzz  = 0
175            p_idct  = 0
176            p_libu  = 0
177        elif ( nprocs == 3 ):
178            p_demux = 0
179            p_vld   = 1
180            p_iqzz  = 0
181            p_idct  = 2
182            p_libu  = 1
183        elif ( nprocs == 4 ):
184            p_demux = 0
185            p_vld   = 1
186            p_iqzz  = 2
187            p_idct  = 3
188            p_libu  = 2
189
190   
191    for x in xrange (x_size):
192        for y in xrange (y_size):
193            if ( mapping.clusters[cluster_id].procs ):
194
195                mapping.addThread( vspace, 'demux_%d_%d' % (x,y), False , x, y, p_demux,
196                                   'mjpeg_demux_stack_%d_%d' % (x,y), 
197                                   'mjpeg_heap_%d_%d' % (x,y),
198                                   1 )   # start_index 
199
200                mapping.addThread( vspace, 'vld_%d_%d' % (x,y), False , x, y, p_vld,
201                                   'mjpeg_vld_stack_%d_%d' % (x,y), 
202                                   'mjpeg_heap_%d_%d' % (x,y),
203                                   2 )   # start_index 
204
205                mapping.addThread( vspace, 'iqzz_%d_%d' % (x,y), False , x, y, p_iqzz,
206                                   'mjpeg_iqzz_stack_%d_%d' % (x,y), 
207                                   'mjpeg_heap_%d_%d' % (x,y),
208                                   3 )   # start_index 
209
210                mapping.addThread( vspace, 'idct_%d_%d' % (x,y), False , x, y, p_idct,
211                                   'mjpeg_idct_stack_%d_%d' % (x,y), 
212                                   'mjpeg_heap_%d_%d' % (x,y),
213                                   4 )   # start_index 
214
215                mapping.addThread( vspace, 'libu_%d_%d' % (x,y), False , x, y, p_libu,
216                                   'mjpeg_libu_stack_%d_%d' % (x,y), 
217                                   'mjpeg_heap_%d_%d' % (x,y),
218                                   5 )   # start_index 
219
220    # extend mapping name
221    mapping.name += '_mjpeg'
222
223    return vspace  # useful for test
224           
225################################ test ############################################
226
227if __name__ == '__main__':
228
229    vspace = extend( Mapping( 'test', 2, 2, 4 ) )
230    print vspace.xml()
231
232
233# Local Variables:
234# tab-width: 4;
235# c-basic-offset: 4;
236# c-file-offsets:((innamespace . 0)(inline-open . 0));
237# indent-tabs-mode: nil;
238# End:
239#
240# vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
241
Note: See TracBrowser for help on using the repository browser.