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