[317] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | from mapping import * |
---|
| 4 | |
---|
| 5 | ###################################################################################### |
---|
[336] | 6 | # file : transpose.py (for the transpose application) |
---|
[317] | 7 | # date : may 2014 |
---|
| 8 | # author : Alain Greiner |
---|
| 9 | ####################################################################################### |
---|
| 10 | # This file describes the mapping of the multi-threaded "transpose" |
---|
| 11 | # application on a multi-clusters, multi-processors architecture. |
---|
| 12 | # This include both the mapping of virtual segments on the clusters, |
---|
| 13 | # and the mapping of tasks on processors. |
---|
| 14 | # This mapping uses 5 platform parameters, (obtained from the "mapping" argument) |
---|
| 15 | # - x_size : number of clusters in a row |
---|
| 16 | # - y_size : number of clusters in a column |
---|
| 17 | # - x_width : number of bits coding x coordinate |
---|
| 18 | # - y_width : number of bits coding y coordinate |
---|
[414] | 19 | # - nprocs : number of processors per cluster |
---|
[317] | 20 | #################################################################################### |
---|
| 21 | |
---|
| 22 | ######################### |
---|
| 23 | def transpose( mapping ): |
---|
| 24 | |
---|
| 25 | x_size = mapping.x_size |
---|
| 26 | y_size = mapping.y_size |
---|
[444] | 27 | nprocs = mapping.nprocs |
---|
[317] | 28 | x_width = mapping.x_width |
---|
| 29 | y_width = mapping.y_width |
---|
| 30 | |
---|
| 31 | # define vsegs base & size |
---|
| 32 | code_base = 0x10000000 |
---|
[383] | 33 | code_size = 0x00010000 # 64 Kbytes (replicated in each cluster) |
---|
[317] | 34 | |
---|
| 35 | data_base = 0x20000000 |
---|
[383] | 36 | data_size = 0x00010000 # 64 Kbytes (non replicated) |
---|
[317] | 37 | |
---|
| 38 | stack_base = 0x40000000 |
---|
[414] | 39 | stack_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
[317] | 40 | |
---|
[414] | 41 | heap_base = 0x60000000 |
---|
| 42 | heap_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
[317] | 43 | |
---|
[383] | 44 | # create vspace |
---|
[317] | 45 | vspace = mapping.addVspace( name = 'transpose', startname = 'trsp_data' ) |
---|
| 46 | |
---|
[383] | 47 | # data vseg : shared (only in cluster[0,0]) |
---|
| 48 | mapping.addVseg( vspace, 'trsp_data', data_base , data_size, |
---|
| 49 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
| 50 | binpath = 'build/transpose/transpose.elf', |
---|
| 51 | local = False ) |
---|
[317] | 52 | |
---|
[383] | 53 | # code vsegs : local (one copy in each cluster) |
---|
| 54 | for x in xrange (x_size): |
---|
| 55 | for y in xrange (y_size): |
---|
| 56 | mapping.addVseg( vspace, 'trsp_code_%d_%d' %(x,y), code_base , code_size, |
---|
| 57 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
| 58 | binpath = 'build/transpose/transpose.elf', |
---|
| 59 | local = True ) |
---|
[317] | 60 | |
---|
[414] | 61 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) |
---|
[383] | 62 | for x in xrange (x_size): |
---|
| 63 | for y in xrange (y_size): |
---|
[414] | 64 | for p in xrange( nprocs ): |
---|
| 65 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
| 66 | size = stack_size / nprocs |
---|
[383] | 67 | base = stack_base + (proc_id * size) |
---|
| 68 | mapping.addVseg( vspace, 'trsp_stack_%d_%d_%d' % (x,y,p), base, size, |
---|
| 69 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
[414] | 70 | local = True, big = True ) |
---|
[383] | 71 | |
---|
[414] | 72 | # heap vsegs: distributed but non local (all heap vsegs can be accessed by all tasks) |
---|
[383] | 73 | for x in xrange (x_size): |
---|
| 74 | for y in xrange (y_size): |
---|
| 75 | cluster_id = (x * y_size) + y |
---|
[414] | 76 | size = heap_size |
---|
[383] | 77 | base = heap_base + (cluster_id * size) |
---|
| 78 | mapping.addVseg( vspace, 'trsp_heap_%d_%d' % (x,y), base, size, |
---|
| 79 | 'C_WU', vtype = 'BUFFER', x = x, y = y, pseg = 'RAM', |
---|
[414] | 80 | local = False, big = True ) |
---|
[383] | 81 | |
---|
[317] | 82 | # distributed tasks / one task per processor |
---|
| 83 | for x in xrange (x_size): |
---|
| 84 | for y in xrange (y_size): |
---|
[414] | 85 | for p in xrange( nprocs ): |
---|
| 86 | trdid = (((x * y_size) + y) * nprocs) + p |
---|
[383] | 87 | mapping.addTask( vspace, 'trsp_%d_%d_%d' % (x,y,p), trdid, x, y, p, |
---|
[317] | 88 | 'trsp_stack_%d_%d_%d' % (x,y,p), |
---|
| 89 | 'trsp_heap_%d_%d' % (x,y), 0 ) |
---|
| 90 | |
---|
| 91 | # extend mapping name |
---|
| 92 | mapping.name += '_transpose' |
---|
| 93 | |
---|
| 94 | return vspace # useful for test |
---|
| 95 | |
---|
| 96 | ################################ test ###################################################### |
---|
| 97 | |
---|
| 98 | if __name__ == '__main__': |
---|
| 99 | |
---|
| 100 | vspace = transpose( Mapping( 'test', 2, 2, 4 ) ) |
---|
| 101 | print vspace.xml() |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | # Local Variables: |
---|
| 105 | # tab-width: 4; |
---|
| 106 | # c-basic-offset: 4; |
---|
| 107 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 108 | # indent-tabs-mode: nil; |
---|
| 109 | # End: |
---|
| 110 | # |
---|
| 111 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 112 | |
---|