| 1 | #!/usr/bin/env python | 
|---|
| 2 |  | 
|---|
| 3 | from mapping import * | 
|---|
| 4 |  | 
|---|
| 5 | ################################################################################## | 
|---|
| 6 | #   file   : gameoflife.py | 
|---|
| 7 | #   date   : february 2015 | 
|---|
| 8 | #   author : Alain Greiner | 
|---|
| 9 | ################################################################################## | 
|---|
| 10 | #  This file describes the mapping of the multi-threaded "gameoflife" | 
|---|
| 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 | #    - The stack vsegs are distributed on all clusters containing processors. | 
|---|
| 19 | #    - The heap vsegs are distributed 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 extend( 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  = 0x00010000     # 64 Kbytes (replicated in each cluster) | 
|---|
| 40 |  | 
|---|
| 41 | data_base  = 0x20000000 | 
|---|
| 42 | data_size  = 0x00200000     # 2 Mbytes (non replicated) | 
|---|
| 43 |  | 
|---|
| 44 | heap_base  = 0x30000000 | 
|---|
| 45 | heap_size  = 0x00040000     # 256 Kbytes (per cluster) | 
|---|
| 46 |  | 
|---|
| 47 | stack_base = 0x40000000 | 
|---|
| 48 | stack_size = 0x00200000     # 2 Mbytes (per cluster) | 
|---|
| 49 |  | 
|---|
| 50 | # create vspace | 
|---|
| 51 | vspace = mapping.addVspace( name = 'gol', startname = 'gol_data' ) | 
|---|
| 52 |  | 
|---|
| 53 | # data vseg : shared (only in cluster[0,0]) | 
|---|
| 54 | mapping.addVseg( vspace, 'gol_data', data_base , data_size, | 
|---|
| 55 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', | 
|---|
| 56 | binpath = 'bin/gameoflife/appli.elf', | 
|---|
| 57 | local = False , big = True ) | 
|---|
| 58 |  | 
|---|
| 59 | # heap vsegs : shared (one per cluster) | 
|---|
| 60 | for x in xrange (x_size): | 
|---|
| 61 | for y in xrange (y_size): | 
|---|
| 62 | cluster_id = (x * y_size) + y | 
|---|
| 63 | if ( mapping.clusters[cluster_id].procs ): | 
|---|
| 64 | size  = heap_size | 
|---|
| 65 | base  = heap_base + (cluster_id * size) | 
|---|
| 66 |  | 
|---|
| 67 | mapping.addVseg( vspace, 'gol_heap_%d_%d' %(x,y), base , size, | 
|---|
| 68 | 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', | 
|---|
| 69 | local = False ) | 
|---|
| 70 |  | 
|---|
| 71 | # code vsegs : local (one copy in each cluster) | 
|---|
| 72 | for x in xrange (x_size): | 
|---|
| 73 | for y in xrange (y_size): | 
|---|
| 74 | cluster_id = (x * y_size) + y | 
|---|
| 75 | if ( mapping.clusters[cluster_id].procs ): | 
|---|
| 76 |  | 
|---|
| 77 | mapping.addVseg( vspace, 'gol_code_%d_%d' %(x,y), | 
|---|
| 78 | code_base , code_size, | 
|---|
| 79 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', | 
|---|
| 80 | binpath = 'bin/gameoflife/appli.elf', | 
|---|
| 81 | local = True ) | 
|---|
| 82 |  | 
|---|
| 83 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) | 
|---|
| 84 | for x in xrange (x_size): | 
|---|
| 85 | for y in xrange (y_size): | 
|---|
| 86 | cluster_id = (x * y_size) + y | 
|---|
| 87 | if ( mapping.clusters[cluster_id].procs ): | 
|---|
| 88 | for p in xrange( nprocs ): | 
|---|
| 89 | proc_id = (((x * y_size) + y) * nprocs) + p | 
|---|
| 90 | size    = (stack_size / nprocs) & 0xFFFFF000 | 
|---|
| 91 | base    = stack_base + (proc_id * size) | 
|---|
| 92 |  | 
|---|
| 93 | mapping.addVseg( vspace, 'gol_stack_%d_%d_%d' % (x,y,p), | 
|---|
| 94 | base, size, 'C_WU', vtype = 'BUFFER', | 
|---|
| 95 | x = x , y = y , pseg = 'RAM', | 
|---|
| 96 | local = True, big = True ) | 
|---|
| 97 |  | 
|---|
| 98 | # distributed tasks / one task per processor | 
|---|
| 99 | for x in xrange (x_size): | 
|---|
| 100 | for y in xrange (y_size): | 
|---|
| 101 | cluster_id = (x * y_size) + y | 
|---|
| 102 | if ( mapping.clusters[cluster_id].procs ): | 
|---|
| 103 | for p in xrange( nprocs ): | 
|---|
| 104 | trdid = (((x * y_size) + y) * nprocs) + p | 
|---|
| 105 |  | 
|---|
| 106 | mapping.addTask( vspace, 'gol_%d_%d_%d' % (x,y,p), | 
|---|
| 107 | trdid, x, y, p, | 
|---|
| 108 | 'gol_stack_%d_%d_%d' % (x,y,p), | 
|---|
| 109 | 'gol_heap_%d_%d' %(x,y) , 0 ) | 
|---|
| 110 |  | 
|---|
| 111 | # extend mapping name | 
|---|
| 112 | mapping.name += '_gol' | 
|---|
| 113 |  | 
|---|
| 114 | return vspace  # useful for test | 
|---|
| 115 |  | 
|---|
| 116 | ################################ test ################################################## | 
|---|
| 117 |  | 
|---|
| 118 | if __name__ == '__main__': | 
|---|
| 119 |  | 
|---|
| 120 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) | 
|---|
| 121 | print vspace.xml() | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 | # Local Variables: | 
|---|
| 125 | # tab-width: 4; | 
|---|
| 126 | # c-basic-offset: 4; | 
|---|
| 127 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); | 
|---|
| 128 | # indent-tabs-mode: nil; | 
|---|
| 129 | # End: | 
|---|
| 130 | # | 
|---|
| 131 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
| 132 |  | 
|---|