[305] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | from mapping import * |
---|
| 4 | |
---|
| 5 | #################################################################################### |
---|
| 6 | # file : sort.py |
---|
| 7 | # date : april 2014 |
---|
| 8 | # author : Alain Greiner |
---|
| 9 | #################################################################################### |
---|
| 10 | # This file describes the mapping of the multi-threaded "sort" |
---|
| 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 sort( 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 | args_base = 0x60000000 |
---|
| 48 | args_size = 0x00000004 # 4 Kbytes |
---|
| 49 | |
---|
| 50 | # create Vspace |
---|
| 51 | vspace = Vspace( 'sort', 'data' ) |
---|
| 52 | |
---|
| 53 | # non replicated vsegs in cluster[0,0] |
---|
| 54 | vseg = Vseg( 'seg_code', code_base , 'CXWU', 0, 0, 'PSEG_RAM' ) |
---|
| 55 | vseg.add( Vobj( 'code' , code_size , 'ELF', binpath = 'build/sort/sort.elf' ) ) |
---|
| 56 | vspace.addVseg( vseg ) |
---|
| 57 | |
---|
| 58 | vseg = Vseg( 'seg_data', data_base , 'C_WU', 0, 0, 'PSEG_RAM' ) |
---|
| 59 | vseg.add( Vobj( 'data' , data_size , 'ELF', binpath = 'build/sort/sort.elf' ) ) |
---|
| 60 | vspace.addVseg( vseg ) |
---|
| 61 | |
---|
| 62 | vseg = Vseg( 'seg_ptab', ptab_base , 'C_WU', 0, 0, 'PSEG_RAM' ) |
---|
| 63 | vseg.add( Vobj( 'ptab' , ptab_size , 'PTAB', align = 13 ) ) |
---|
| 64 | vspace.addVseg( vseg ) |
---|
| 65 | |
---|
| 66 | vseg = Vseg( 'seg_args', args_base , 'C_WU', 0, 0, 'PSEG_RAM' ) |
---|
| 67 | vseg.add( Vobj( 'args' , args_size , 'CONST' , init = 16 ) ) |
---|
| 68 | vspace.addVseg( vseg ) |
---|
| 69 | |
---|
| 70 | # distributed vsegs: one stack per processor/task, one heap per cluster |
---|
| 71 | for x in xrange (x_size): |
---|
| 72 | for y in xrange (y_size): |
---|
| 73 | cluster_offset = ((x << y_width) + y) << 20 # max 1 Mbytes heap per cluster |
---|
| 74 | vseg = Vseg( 'seg_heap_%d_%d' % (x,y), \ |
---|
| 75 | heap_base + cluster_offset, \ |
---|
| 76 | 'C_WU' , x, y, 'PSEG_RAM' ) |
---|
| 77 | vseg.add( Vobj( 'heap_%d_%d' % (x,y), heap_size , 'BUFFER' ) ) |
---|
| 78 | vspace.addVseg ( vseg ) |
---|
| 79 | |
---|
| 80 | for p in xrange( nb_procs ): |
---|
| 81 | proc_offset = p << 18 # max 256 Kbytes stack per proc |
---|
| 82 | vseg = Vseg( 'seg_stack_%d_%d_%d' % (x,y,p), \ |
---|
| 83 | stack_base + proc_offset + cluster_offset, \ |
---|
| 84 | 'C_WU' , x, y, 'PSEG_RAM' ) |
---|
| 85 | vseg.add( Vobj( 'stack_%d_%d_%d' % (x,y,p), stack_size , 'BUFFER' ) ) |
---|
| 86 | vspace.addVseg ( vseg ) |
---|
| 87 | |
---|
| 88 | # distributed tasks / one task per processor |
---|
| 89 | for x in xrange (x_size): |
---|
| 90 | for y in xrange (y_size): |
---|
| 91 | for p in xrange( nb_procs ): |
---|
| 92 | |
---|
| 93 | trdid = (((x * y_size) + y) * nb_procs) + p |
---|
| 94 | task = Task( 'sort_%d_%d_%d' % (x,y,p), trdid, x, y, p, \ |
---|
| 95 | 'stack_%d_%d_%d' % (x,y,p), 'heap_%d_%d' % (x,y), 0 ) |
---|
| 96 | vspace.addTask ( task ) |
---|
| 97 | |
---|
| 98 | return vspace |
---|
| 99 | |
---|
| 100 | ################################ test ###################################################### |
---|
| 101 | |
---|
| 102 | if __name__ == '__main__': |
---|
| 103 | print sort( Mapping( 'test', 2, 2, 4 ) ) |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | # Local Variables: |
---|
| 107 | # tab-width: 4; |
---|
| 108 | # c-basic-offset: 4; |
---|
| 109 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 110 | # indent-tabs-mode: nil; |
---|
| 111 | # End: |
---|
| 112 | # |
---|
| 113 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 114 | |
---|