[723] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | from 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: |
---|
[741] | 14 | # - the "main" thread is running on P[0,0,0]. |
---|
[723] | 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 | ###################### |
---|
| 27 | def extend( mapping ): |
---|
| 28 | |
---|
| 29 | x_size = mapping.x_size |
---|
| 30 | y_size = mapping.y_size |
---|
| 31 | nprocs = mapping.nprocs |
---|
| 32 | |
---|
[736] | 33 | assert (nprocs >= 1) and (nprocs <= 4) |
---|
[723] | 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 |
---|
[736] | 43 | heap_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
[723] | 44 | |
---|
| 45 | stack_base = 0x40000000 |
---|
| 46 | stack_size = 0x00020000 # 128 Kbytes (per thread) |
---|
| 47 | |
---|
| 48 | # create vspace |
---|
| 49 | vspace = mapping.addVspace( name = 'mjpeg', |
---|
[736] | 50 | startname = 'mjpeg_data', |
---|
[780] | 51 | active = False ) |
---|
[723] | 52 | |
---|
| 53 | # data vseg : shared / cluster[0][0] |
---|
[736] | 54 | mapping.addVseg( vspace, 'mjpeg_data', data_base , data_size, |
---|
[723] | 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 | |
---|
[736] | 67 | mapping.addVseg( vspace, 'mjpeg_heap_%d_%d' %(x,y), base , size, |
---|
[723] | 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 | |
---|
[736] | 77 | mapping.addVseg( vspace, 'mjpeg_code_%d_%d' %(x,y), |
---|
[723] | 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) |
---|
[741] | 84 | # ... plus main_stack in cluster[0][0] |
---|
[723] | 85 | base = stack_base |
---|
[736] | 86 | mapping.addVseg( vspace, 'mjpeg_main_stack', |
---|
[723] | 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 | |
---|
[736] | 97 | mapping.addVseg( vspace, 'mjpeg_demux_stack_%d_%d' % (x,y), |
---|
[723] | 98 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 99 | x = x , y = y , pseg = 'RAM', |
---|
| 100 | local = True ) |
---|
| 101 | |
---|
| 102 | base += stack_size |
---|
| 103 | |
---|
[736] | 104 | mapping.addVseg( vspace, 'mjpeg_vld_stack_%d_%d' % (x,y), |
---|
[723] | 105 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 106 | x = x , y = y , pseg = 'RAM', |
---|
| 107 | local = True ) |
---|
| 108 | |
---|
| 109 | base += stack_size |
---|
| 110 | |
---|
[736] | 111 | mapping.addVseg( vspace, 'mjpeg_iqzz_stack_%d_%d' % (x,y), |
---|
[723] | 112 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 113 | x = x , y = y , pseg = 'RAM', |
---|
| 114 | local = True ) |
---|
| 115 | |
---|
| 116 | base += stack_size |
---|
| 117 | |
---|
[736] | 118 | mapping.addVseg( vspace, 'mjpeg_idct_stack_%d_%d' % (x,y), |
---|
[723] | 119 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 120 | x = x , y = y , pseg = 'RAM', |
---|
| 121 | local = True ) |
---|
| 122 | |
---|
| 123 | base += stack_size |
---|
| 124 | |
---|
[736] | 125 | mapping.addVseg( vspace, 'mjpeg_libu_stack_%d_%d' % (x,y), |
---|
[723] | 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 |
---|
[741] | 133 | # main mapped in cluster[0,0] |
---|
[723] | 134 | mapping.addThread( vspace, 'main', True, 0, 0, 0, |
---|
[736] | 135 | 'mjpeg_main_stack', |
---|
| 136 | 'mjpeg_heap_0_0', |
---|
[723] | 137 | 0 ) # index in start_vector |
---|
| 138 | |
---|
[741] | 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 | |
---|
[723] | 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, |
---|
[736] | 196 | 'mjpeg_demux_stack_%d_%d' % (x,y), |
---|
| 197 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[741] | 198 | 1 ) # start_index |
---|
[723] | 199 | |
---|
| 200 | mapping.addThread( vspace, 'vld_%d_%d' % (x,y), False , x, y, p_vld, |
---|
[736] | 201 | 'mjpeg_vld_stack_%d_%d' % (x,y), |
---|
| 202 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[741] | 203 | 2 ) # start_index |
---|
[723] | 204 | |
---|
| 205 | mapping.addThread( vspace, 'iqzz_%d_%d' % (x,y), False , x, y, p_iqzz, |
---|
[736] | 206 | 'mjpeg_iqzz_stack_%d_%d' % (x,y), |
---|
| 207 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[741] | 208 | 3 ) # start_index |
---|
[723] | 209 | |
---|
| 210 | mapping.addThread( vspace, 'idct_%d_%d' % (x,y), False , x, y, p_idct, |
---|
[736] | 211 | 'mjpeg_idct_stack_%d_%d' % (x,y), |
---|
| 212 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[741] | 213 | 4 ) # start_index |
---|
[723] | 214 | |
---|
| 215 | mapping.addThread( vspace, 'libu_%d_%d' % (x,y), False , x, y, p_libu, |
---|
[736] | 216 | 'mjpeg_libu_stack_%d_%d' % (x,y), |
---|
| 217 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[741] | 218 | 5 ) # start_index |
---|
[723] | 219 | |
---|
| 220 | # extend mapping name |
---|
| 221 | mapping.name += '_mjpeg' |
---|
| 222 | |
---|
| 223 | return vspace # useful for test |
---|
| 224 | |
---|
| 225 | ################################ test ############################################ |
---|
| 226 | |
---|
| 227 | if __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 | |
---|