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