[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. |
---|
| 17 | # - The stacks vsegs are distibuted 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 |
---|
[708] | 37 | code_size = 0x00010000 # 64 Kbytes (per cluster) |
---|
[317] | 38 | |
---|
| 39 | data_base = 0x20000000 |
---|
[383] | 40 | data_size = 0x00010000 # 64 Kbytes (non replicated) |
---|
[317] | 41 | |
---|
| 42 | stack_base = 0x40000000 |
---|
[708] | 43 | stack_size = 0x00010000 # 64 Kbytes (per thread) |
---|
[317] | 44 | |
---|
[414] | 45 | heap_base = 0x60000000 |
---|
| 46 | heap_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
[317] | 47 | |
---|
[383] | 48 | # create vspace |
---|
[669] | 49 | vspace = mapping.addVspace( name = 'transpose', startname = 'trsp_data', active = False ) |
---|
[317] | 50 | |
---|
[383] | 51 | # data vseg : shared (only in cluster[0,0]) |
---|
| 52 | mapping.addVseg( vspace, 'trsp_data', data_base , data_size, |
---|
| 53 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
[610] | 54 | binpath = 'bin/transpose/appli.elf', |
---|
[383] | 55 | local = False ) |
---|
[317] | 56 | |
---|
[383] | 57 | # code vsegs : local (one copy in each cluster) |
---|
| 58 | for x in xrange (x_size): |
---|
| 59 | for y in xrange (y_size): |
---|
[502] | 60 | cluster_id = (x * y_size) + y |
---|
| 61 | if ( mapping.clusters[cluster_id].procs ): |
---|
[317] | 62 | |
---|
[502] | 63 | mapping.addVseg( vspace, 'trsp_code_%d_%d' %(x,y), |
---|
| 64 | code_base , code_size, |
---|
| 65 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
[610] | 66 | binpath = 'bin/transpose/appli.elf', |
---|
[502] | 67 | local = True ) |
---|
| 68 | |
---|
| 69 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) |
---|
[383] | 70 | for x in xrange (x_size): |
---|
| 71 | for y in xrange (y_size): |
---|
[502] | 72 | cluster_id = (x * y_size) + y |
---|
| 73 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 74 | for p in xrange( nprocs ): |
---|
| 75 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
[708] | 76 | base = stack_base + (proc_id * stack_size) |
---|
[383] | 77 | |
---|
[502] | 78 | mapping.addVseg( vspace, 'trsp_stack_%d_%d_%d' % (x,y,p), |
---|
[708] | 79 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
[502] | 80 | x = x , y = y , pseg = 'RAM', |
---|
| 81 | local = True, big = True ) |
---|
| 82 | |
---|
| 83 | # heap vsegs: distributed non local (all heap vsegs can be accessed by all tasks) |
---|
[383] | 84 | for x in xrange (x_size): |
---|
| 85 | for y in xrange (y_size): |
---|
| 86 | cluster_id = (x * y_size) + y |
---|
[502] | 87 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 88 | size = heap_size |
---|
| 89 | base = heap_base + (cluster_id * size) |
---|
[383] | 90 | |
---|
[502] | 91 | mapping.addVseg( vspace, 'trsp_heap_%d_%d' % (x,y), base, size, |
---|
| 92 | 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', |
---|
| 93 | local = False, big = True ) |
---|
| 94 | |
---|
[708] | 95 | # distribute one thread per processor / main on P[0,0,0] |
---|
[317] | 96 | for x in xrange (x_size): |
---|
| 97 | for y in xrange (y_size): |
---|
[502] | 98 | cluster_id = (x * y_size) + y |
---|
| 99 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 100 | for p in xrange( nprocs ): |
---|
[708] | 101 | if (x == 0) and (y == 0) and (p == 0) : # main thread |
---|
| 102 | startid = 1 |
---|
| 103 | is_main = True |
---|
| 104 | else : # other threads |
---|
| 105 | startid = 0 |
---|
| 106 | is_main = False |
---|
[317] | 107 | |
---|
[708] | 108 | mapping.addThread( vspace, |
---|
| 109 | 'trsp_%d_%d_%d' % (x,y,p), |
---|
| 110 | is_main, |
---|
| 111 | x, y, p, |
---|
| 112 | 'trsp_stack_%d_%d_%d' % (x,y,p), |
---|
| 113 | 'trsp_heap_%d_%d' % (x,y), |
---|
| 114 | startid ) |
---|
[502] | 115 | |
---|
[317] | 116 | # extend mapping name |
---|
| 117 | mapping.name += '_transpose' |
---|
| 118 | |
---|
| 119 | return vspace # useful for test |
---|
| 120 | |
---|
[502] | 121 | ################################ test ################################################## |
---|
[317] | 122 | |
---|
| 123 | if __name__ == '__main__': |
---|
| 124 | |
---|
[589] | 125 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) |
---|
[317] | 126 | print vspace.xml() |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | # Local Variables: |
---|
| 130 | # tab-width: 4; |
---|
| 131 | # c-basic-offset: 4; |
---|
| 132 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 133 | # indent-tabs-mode: nil; |
---|
| 134 | # End: |
---|
| 135 | # |
---|
| 136 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 137 | |
---|