[317] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | from mapping import * |
---|
| 4 | |
---|
[502] | 5 | ################################################################################## |
---|
[589] | 6 | # file : transpose.py |
---|
[317] | 7 | # date : may 2014 |
---|
| 8 | # author : Alain Greiner |
---|
[502] | 9 | ################################################################################## |
---|
[317] | 10 | # This file describes the mapping of the multi-threaded "transpose" |
---|
| 11 | # application on a multi-clusters, multi-processors architecture. |
---|
[708] | 12 | # There is one thread per processor. |
---|
[502] | 13 | # The mapping of virtual segments is the following: |
---|
| 14 | # - There is one shared data vseg in cluster[0][0] |
---|
| 15 | # - The code vsegs are replicated on all clusters containing processors. |
---|
| 16 | # - There is one heap vseg per cluster containing processors. |
---|
[824] | 17 | # - The stacks vsegs are distributed on all clusters containing processors. |
---|
[317] | 18 | # This mapping uses 5 platform parameters, (obtained from the "mapping" argument) |
---|
[502] | 19 | # - x_size : number of clusters in a row |
---|
| 20 | # - y_size : number of clusters in a column |
---|
| 21 | # - x_width : number of bits coding x coordinate |
---|
| 22 | # - y_width : number of bits coding y coordinate |
---|
| 23 | # - nprocs : number of processors per cluster |
---|
| 24 | ################################################################################## |
---|
[317] | 25 | |
---|
[589] | 26 | ###################### |
---|
| 27 | def extend( mapping ): |
---|
[317] | 28 | |
---|
| 29 | x_size = mapping.x_size |
---|
| 30 | y_size = mapping.y_size |
---|
[444] | 31 | nprocs = mapping.nprocs |
---|
[317] | 32 | x_width = mapping.x_width |
---|
| 33 | y_width = mapping.y_width |
---|
| 34 | |
---|
| 35 | # define vsegs base & size |
---|
| 36 | code_base = 0x10000000 |
---|
[764] | 37 | code_size = 0x00010000 # 64 Kbytes (256 Mbytes max) |
---|
[317] | 38 | |
---|
| 39 | data_base = 0x20000000 |
---|
[764] | 40 | data_size = 0x00010000 # 64 Kbytes (256 Mbytes max) |
---|
[317] | 41 | |
---|
[764] | 42 | mmap_base = 0x30000000 |
---|
| 43 | mmap_size = 0x10000000 # 256 Mbytes (non mapped) |
---|
| 44 | |
---|
[317] | 45 | stack_base = 0x40000000 |
---|
[764] | 46 | stack_size = 0x00010000 # 64 Kbytes per thread (64 Mbytes max) |
---|
[317] | 47 | |
---|
[414] | 48 | heap_base = 0x60000000 |
---|
[764] | 49 | heap_size = 0x00200000 # 2 Mbytes per cluster (512 Mbytes max) |
---|
[317] | 50 | |
---|
[383] | 51 | # create vspace |
---|
[775] | 52 | vspace = mapping.addVspace( name = 'transpose', startname = 'trsp_data', active = False ) |
---|
[317] | 53 | |
---|
[383] | 54 | # data vseg : shared (only in cluster[0,0]) |
---|
| 55 | mapping.addVseg( vspace, 'trsp_data', data_base , data_size, |
---|
| 56 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
[610] | 57 | binpath = 'bin/transpose/appli.elf', |
---|
[383] | 58 | local = False ) |
---|
[317] | 59 | |
---|
[764] | 60 | # mmap vseg : non mapped in physical memory |
---|
| 61 | mapping.addVseg( vspace, 'trsp_mmap', mmap_base , mmap_size, |
---|
| 62 | 'C_WU', vtype = 'MMAP', local = False ) |
---|
| 63 | |
---|
[383] | 64 | # code vsegs : local (one copy in each cluster) |
---|
| 65 | for x in xrange (x_size): |
---|
| 66 | for y in xrange (y_size): |
---|
[502] | 67 | cluster_id = (x * y_size) + y |
---|
| 68 | if ( mapping.clusters[cluster_id].procs ): |
---|
[317] | 69 | |
---|
[502] | 70 | mapping.addVseg( vspace, 'trsp_code_%d_%d' %(x,y), |
---|
| 71 | code_base , code_size, |
---|
| 72 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
[610] | 73 | binpath = 'bin/transpose/appli.elf', |
---|
[502] | 74 | local = True ) |
---|
| 75 | |
---|
| 76 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) |
---|
[383] | 77 | for x in xrange (x_size): |
---|
| 78 | for y in xrange (y_size): |
---|
[502] | 79 | cluster_id = (x * y_size) + y |
---|
| 80 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 81 | for p in xrange( nprocs ): |
---|
| 82 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
[708] | 83 | base = stack_base + (proc_id * stack_size) |
---|
[764] | 84 | size = stack_size - 4096 |
---|
[502] | 85 | mapping.addVseg( vspace, 'trsp_stack_%d_%d_%d' % (x,y,p), |
---|
[764] | 86 | base , size , 'C_WU', vtype = 'BUFFER', |
---|
[502] | 87 | x = x , y = y , pseg = 'RAM', |
---|
[764] | 88 | local = True ) |
---|
[502] | 89 | |
---|
| 90 | # heap vsegs: distributed non local (all heap vsegs can be accessed by all tasks) |
---|
[383] | 91 | for x in xrange (x_size): |
---|
| 92 | for y in xrange (y_size): |
---|
| 93 | cluster_id = (x * y_size) + y |
---|
[502] | 94 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 95 | size = heap_size |
---|
| 96 | base = heap_base + (cluster_id * size) |
---|
[383] | 97 | |
---|
[502] | 98 | mapping.addVseg( vspace, 'trsp_heap_%d_%d' % (x,y), base, size, |
---|
| 99 | 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', |
---|
| 100 | local = False, big = True ) |
---|
| 101 | |
---|
[708] | 102 | # distribute one thread per processor / main on P[0,0,0] |
---|
[317] | 103 | for x in xrange (x_size): |
---|
| 104 | for y in xrange (y_size): |
---|
[502] | 105 | cluster_id = (x * y_size) + y |
---|
| 106 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 107 | for p in xrange( nprocs ): |
---|
[708] | 108 | if (x == 0) and (y == 0) and (p == 0) : # main thread |
---|
| 109 | startid = 1 |
---|
| 110 | is_main = True |
---|
| 111 | else : # other threads |
---|
| 112 | startid = 0 |
---|
| 113 | is_main = False |
---|
[317] | 114 | |
---|
[708] | 115 | mapping.addThread( vspace, |
---|
| 116 | 'trsp_%d_%d_%d' % (x,y,p), |
---|
| 117 | is_main, |
---|
| 118 | x, y, p, |
---|
| 119 | 'trsp_stack_%d_%d_%d' % (x,y,p), |
---|
| 120 | 'trsp_heap_%d_%d' % (x,y), |
---|
| 121 | startid ) |
---|
[502] | 122 | |
---|
[317] | 123 | # extend mapping name |
---|
| 124 | mapping.name += '_transpose' |
---|
| 125 | |
---|
| 126 | return vspace # useful for test |
---|
| 127 | |
---|
[502] | 128 | ################################ test ################################################## |
---|
[317] | 129 | |
---|
| 130 | if __name__ == '__main__': |
---|
| 131 | |
---|
[589] | 132 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) |
---|
[317] | 133 | print vspace.xml() |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | # Local Variables: |
---|
| 137 | # tab-width: 4; |
---|
| 138 | # c-basic-offset: 4; |
---|
| 139 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 140 | # indent-tabs-mode: nil; |
---|
| 141 | # End: |
---|
| 142 | # |
---|
| 143 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 144 | |
---|