[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 | |
---|
[736] | 34 | assert (nprocs >= 1) and (nprocs <= 4) |
---|
[723] | 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 |
---|
[736] | 44 | heap_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
[723] | 45 | |
---|
| 46 | stack_base = 0x40000000 |
---|
| 47 | stack_size = 0x00020000 # 128 Kbytes (per thread) |
---|
| 48 | |
---|
| 49 | # create vspace |
---|
| 50 | vspace = mapping.addVspace( name = 'mjpeg', |
---|
[736] | 51 | startname = 'mjpeg_data', |
---|
[723] | 52 | active = True ) |
---|
| 53 | |
---|
| 54 | # data vseg : shared / cluster[0][0] |
---|
[736] | 55 | mapping.addVseg( vspace, 'mjpeg_data', data_base , data_size, |
---|
[723] | 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 | |
---|
[736] | 68 | mapping.addVseg( vspace, 'mjpeg_heap_%d_%d' %(x,y), base , size, |
---|
[723] | 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 | |
---|
[736] | 78 | mapping.addVseg( vspace, 'mjpeg_code_%d_%d' %(x,y), |
---|
[723] | 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 |
---|
[736] | 87 | mapping.addVseg( vspace, 'mjpeg_main_stack', |
---|
[723] | 88 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 89 | x = 0 , y = 0 , pseg = 'RAM', |
---|
| 90 | local = True ) |
---|
| 91 | |
---|
| 92 | base += stack_size |
---|
| 93 | |
---|
[736] | 94 | mapping.addVseg( vspace, 'mjpeg_tg_stack', |
---|
[723] | 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 | |
---|
[736] | 105 | mapping.addVseg( vspace, 'mjpeg_demux_stack_%d_%d' % (x,y), |
---|
[723] | 106 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 107 | x = x , y = y , pseg = 'RAM', |
---|
| 108 | local = True ) |
---|
| 109 | |
---|
| 110 | base += stack_size |
---|
| 111 | |
---|
[736] | 112 | mapping.addVseg( vspace, 'mjpeg_vld_stack_%d_%d' % (x,y), |
---|
[723] | 113 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 114 | x = x , y = y , pseg = 'RAM', |
---|
| 115 | local = True ) |
---|
| 116 | |
---|
| 117 | base += stack_size |
---|
| 118 | |
---|
[736] | 119 | mapping.addVseg( vspace, 'mjpeg_iqzz_stack_%d_%d' % (x,y), |
---|
[723] | 120 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 121 | x = x , y = y , pseg = 'RAM', |
---|
| 122 | local = True ) |
---|
| 123 | |
---|
| 124 | base += stack_size |
---|
| 125 | |
---|
[736] | 126 | mapping.addVseg( vspace, 'mjpeg_idct_stack_%d_%d' % (x,y), |
---|
[723] | 127 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
| 128 | x = x , y = y , pseg = 'RAM', |
---|
| 129 | local = True ) |
---|
| 130 | |
---|
| 131 | base += stack_size |
---|
| 132 | |
---|
[736] | 133 | mapping.addVseg( vspace, 'mjpeg_libu_stack_%d_%d' % (x,y), |
---|
[723] | 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 |
---|
[736] | 141 | # main & tg are mapped in cluster[0,0] |
---|
[723] | 142 | mapping.addThread( vspace, 'main', True, 0, 0, 0, |
---|
[736] | 143 | 'mjpeg_main_stack', |
---|
| 144 | 'mjpeg_heap_0_0', |
---|
[723] | 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 |
---|
[736] | 164 | p_vld = 2 |
---|
[723] | 165 | p_iqzz = 1 |
---|
[736] | 166 | p_idct = 1 |
---|
[723] | 167 | p_libu = 1 |
---|
| 168 | elif ( nprocs == 4 ): |
---|
| 169 | p_tg = 0 |
---|
| 170 | p_demux = 1 |
---|
[736] | 171 | p_vld = 3 |
---|
[723] | 172 | p_iqzz = 2 |
---|
| 173 | p_idct = 3 |
---|
| 174 | p_libu = 2 |
---|
| 175 | |
---|
| 176 | mapping.addThread( vspace, 'tg', False, 0, 0, p_tg, |
---|
[736] | 177 | 'mjpeg_tg_stack', |
---|
| 178 | 'mjpeg_heap_0_0', |
---|
[723] | 179 | 1 ) # index in start_vector |
---|
| 180 | |
---|
| 181 | for x in xrange (x_size): |
---|
| 182 | for y in xrange (y_size): |
---|
| 183 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 184 | |
---|
| 185 | mapping.addThread( vspace, 'demux_%d_%d' % (x,y), False , x, y, p_demux, |
---|
[736] | 186 | 'mjpeg_demux_stack_%d_%d' % (x,y), |
---|
| 187 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[723] | 188 | 2 ) # start_index |
---|
| 189 | |
---|
| 190 | mapping.addThread( vspace, 'vld_%d_%d' % (x,y), False , x, y, p_vld, |
---|
[736] | 191 | 'mjpeg_vld_stack_%d_%d' % (x,y), |
---|
| 192 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[723] | 193 | 3 ) # start_index |
---|
| 194 | |
---|
| 195 | mapping.addThread( vspace, 'iqzz_%d_%d' % (x,y), False , x, y, p_iqzz, |
---|
[736] | 196 | 'mjpeg_iqzz_stack_%d_%d' % (x,y), |
---|
| 197 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[723] | 198 | 4 ) # start_index |
---|
| 199 | |
---|
| 200 | mapping.addThread( vspace, 'idct_%d_%d' % (x,y), False , x, y, p_idct, |
---|
[736] | 201 | 'mjpeg_idct_stack_%d_%d' % (x,y), |
---|
| 202 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[723] | 203 | 5 ) # start_index |
---|
| 204 | |
---|
| 205 | mapping.addThread( vspace, 'libu_%d_%d' % (x,y), False , x, y, p_libu, |
---|
[736] | 206 | 'mjpeg_libu_stack_%d_%d' % (x,y), |
---|
| 207 | 'mjpeg_heap_%d_%d' % (x,y), |
---|
[723] | 208 | 6 ) # start_index |
---|
| 209 | |
---|
| 210 | # extend mapping name |
---|
| 211 | mapping.name += '_mjpeg' |
---|
| 212 | |
---|
| 213 | return vspace # useful for test |
---|
| 214 | |
---|
| 215 | ################################ test ############################################ |
---|
| 216 | |
---|
| 217 | if __name__ == '__main__': |
---|
| 218 | |
---|
| 219 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) |
---|
| 220 | print vspace.xml() |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | # Local Variables: |
---|
| 224 | # tab-width: 4; |
---|
| 225 | # c-basic-offset: 4; |
---|
| 226 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 227 | # indent-tabs-mode: nil; |
---|
| 228 | # End: |
---|
| 229 | # |
---|
| 230 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 231 | |
---|