[305] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | from mapping import * |
---|
| 4 | |
---|
| 5 | ###################################################################################### |
---|
| 6 | # file : transpose.py |
---|
| 7 | # date : april 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 |
---|
| 19 | # - nb_procs : number of processors per cluster |
---|
| 20 | #################################################################################### |
---|
| 21 | |
---|
| 22 | ######################### |
---|
| 23 | def transpose( mapping ): |
---|
| 24 | |
---|
| 25 | x_size = mapping.x_size |
---|
| 26 | y_size = mapping.y_size |
---|
| 27 | nb_procs = mapping.nb_procs |
---|
| 28 | x_width = mapping.x_width |
---|
| 29 | y_width = mapping.y_width |
---|
| 30 | |
---|
| 31 | # define vsegs base & size |
---|
| 32 | code_base = 0x10000000 |
---|
| 33 | code_size = 0x00010000 # 64 Kbytes |
---|
| 34 | |
---|
| 35 | data_base = 0x20000000 |
---|
| 36 | data_size = 0x00010000 # 64 Kbytes |
---|
| 37 | |
---|
| 38 | ptab_base = 0x30000000 |
---|
| 39 | ptab_size = 0x00040000 # 256 Kbytes |
---|
| 40 | |
---|
| 41 | stack_base = 0x40000000 |
---|
| 42 | stack_size = 0x00010000 # 64 Kbytes |
---|
| 43 | |
---|
| 44 | heap_base = 0x50000000 |
---|
| 45 | heap_size = 0x00010000 # 64 Kbytes |
---|
| 46 | |
---|
| 47 | # create Vspace |
---|
| 48 | vspace = Vspace( 'transpose', 'data' ) |
---|
| 49 | |
---|
| 50 | # non replicated vsegs in cluster[0,0] |
---|
| 51 | vseg = Vseg( 'seg_code', code_base , 'CXWU', 0, 0, 'PSEG_RAM' ) |
---|
| 52 | vseg.add( Vobj( 'code' , code_size , 'ELF', binpath = 'build/transpose/transpose.elf' ) ) |
---|
| 53 | vspace.addVseg( vseg ) |
---|
| 54 | |
---|
| 55 | vseg = Vseg( 'seg_data', data_base , 'C_WU', 0, 0, 'PSEG_RAM' ) |
---|
| 56 | vseg.add( Vobj( 'data' , data_size , 'ELF', binpath = 'build/transpose/transpose.elf' ) ) |
---|
| 57 | vspace.addVseg( vseg ) |
---|
| 58 | |
---|
| 59 | vseg = Vseg( 'seg_ptab', ptab_base , 'C_WU', 0, 0, 'PSEG_RAM' ) |
---|
| 60 | vseg.add( Vobj( 'ptab' , ptab_size , 'PTAB', align = 13 ) ) |
---|
| 61 | vspace.addVseg( vseg ) |
---|
| 62 | |
---|
| 63 | # distributed vsegs: one stack per processor/task, one heap per cluster |
---|
| 64 | for x in xrange (x_size): |
---|
| 65 | for y in xrange (y_size): |
---|
| 66 | cluster_offset = ((x << y_width) + y) << 20 # max 1 Mbytes heap per cluster |
---|
| 67 | vseg = Vseg( 'seg_heap_%d_%d' % (x,y), \ |
---|
| 68 | heap_base + cluster_offset, \ |
---|
| 69 | 'C_WU' , x, y, 'PSEG_RAM' ) |
---|
| 70 | vseg.add( Vobj( 'heap_%d_%d' % (x,y), heap_size , 'BUFFER' ) ) |
---|
| 71 | vspace.addVseg ( vseg ) |
---|
| 72 | |
---|
| 73 | for p in xrange( nb_procs ): |
---|
| 74 | proc_offset = p << 18 # max 256 Kbytes stack per proc |
---|
| 75 | vseg = Vseg( 'seg_stack_%d_%d_%d' % (x,y,p), \ |
---|
| 76 | stack_base + proc_offset + cluster_offset, \ |
---|
| 77 | 'C_WU' , x, y, 'PSEG_RAM' ) |
---|
| 78 | vseg.add( Vobj( 'stack_%d_%d_%d' % (x,y,p), stack_size , 'BUFFER' ) ) |
---|
| 79 | vspace.addVseg ( vseg ) |
---|
| 80 | |
---|
| 81 | # distributed tasks / one task per processor |
---|
| 82 | for x in xrange (x_size): |
---|
| 83 | for y in xrange (y_size): |
---|
| 84 | for p in xrange( nb_procs ): |
---|
| 85 | |
---|
| 86 | trdid = (((x * y_size) + y) * nb_procs) + p |
---|
| 87 | task = Task( 'trsp_%d_%d_%d' % (x,y,p), trdid, x, y, p, \ |
---|
| 88 | 'stack_%d_%d_%d' % (x,y,p), 'heap_%d_%d' % (x,y), 0 ) |
---|
| 89 | vspace.addTask ( task ) |
---|
| 90 | |
---|
| 91 | return vspace |
---|
| 92 | |
---|
| 93 | ################################ test ###################################################### |
---|
| 94 | |
---|
| 95 | if __name__ == '__main__': |
---|
| 96 | print transpose( Mapping( 'test', 2, 2, 4 ) ) |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | # Local Variables: |
---|
| 100 | # tab-width: 4; |
---|
| 101 | # c-basic-offset: 4; |
---|
| 102 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 103 | # indent-tabs-mode: nil; |
---|
| 104 | # End: |
---|
| 105 | # |
---|
| 106 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 107 | |
---|