| 1 | #!/usr/bin/env python | 
|---|
| 2 |  | 
|---|
| 3 | from mapping import * | 
|---|
| 4 |  | 
|---|
| 5 | ##################################################################################### | 
|---|
| 6 | #   file   : convol.py | 
|---|
| 7 | #   date   : may 2014 | 
|---|
| 8 | #   author : Alain Greiner | 
|---|
| 9 | ##################################################################################### | 
|---|
| 10 | #  This file describes the mapping of the multi-threaded "convol" | 
|---|
| 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 threads on processors. | 
|---|
| 14 | #  There is one thread 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 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  = 0x00020000     # 128 Kbytes (non replicated) | 
|---|
| 43 |  | 
|---|
| 44 | heap_base  = 0x40000000 | 
|---|
| 45 | heap_size  = 0x01000000     # 16 Mbytes (per cluster) | 
|---|
| 46 |  | 
|---|
| 47 | stack_base = 0x50000000 | 
|---|
| 48 | stack_size = 0x00200000     # 2 Mbytes (per cluster) | 
|---|
| 49 |  | 
|---|
| 50 | # create Vspace | 
|---|
| 51 | vspace = mapping.addVspace( name = 'convol', startname = 'conv_data', active = False ) | 
|---|
| 52 |  | 
|---|
| 53 | # data vseg in cluster[0,0] : non local | 
|---|
| 54 | mapping.addVseg( vspace, 'conv_data', data_base , data_size, | 
|---|
| 55 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', | 
|---|
| 56 | binpath = 'bin/convol/appli.elf', | 
|---|
| 57 | local = False ) | 
|---|
| 58 |  | 
|---|
| 59 | # code vsegs : local (one copy in each 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       = code_size | 
|---|
| 65 | base       = code_base | 
|---|
| 66 |  | 
|---|
| 67 | mapping.addVseg( vspace, 'conv_code_%d_%d' % (x,y), base, size, | 
|---|
| 68 | 'CXWU', vtype = 'ELF', x = x , y = y , pseg = 'RAM', | 
|---|
| 69 | binpath = 'bin/convol/appli.elf', | 
|---|
| 70 | local = True ) | 
|---|
| 71 |  | 
|---|
| 72 | # stack vsegs : local (one stack per processor) | 
|---|
| 73 | for x in xrange (x_size): | 
|---|
| 74 | for y in xrange (y_size): | 
|---|
| 75 | cluster_id = (x * y_size) + y | 
|---|
| 76 | if ( mapping.clusters[cluster_id].procs ): | 
|---|
| 77 | for p in xrange( nprocs ): | 
|---|
| 78 | proc_id = (((x * y_size) + y) * nprocs) + p | 
|---|
| 79 | size    = (stack_size / nprocs) & 0xFFFFF000 | 
|---|
| 80 | base    = stack_base + (proc_id * size) | 
|---|
| 81 |  | 
|---|
| 82 | mapping.addVseg( vspace, 'conv_stack_%d_%d_%d' % (x,y,p), | 
|---|
| 83 | base, size, 'C_WU', vtype = 'BUFFER', | 
|---|
| 84 | x = x , y = y , pseg = 'RAM', | 
|---|
| 85 | local = True, big = True ) | 
|---|
| 86 |  | 
|---|
| 87 | # heap vsegs : distributed but non local (any heap can be accessed by any thread) | 
|---|
| 88 | for x in xrange (x_size): | 
|---|
| 89 | for y in xrange (y_size): | 
|---|
| 90 | cluster_id = (x * y_size) + y | 
|---|
| 91 | if ( mapping.clusters[cluster_id].procs ): | 
|---|
| 92 | size       = heap_size | 
|---|
| 93 | base       = heap_base + (cluster_id * size) | 
|---|
| 94 |  | 
|---|
| 95 | mapping.addVseg( vspace, 'conv_heap_%d_%d' % (x,y), base, size, | 
|---|
| 96 | 'C_WU', vtype = 'HEAP', x = x , y = y , pseg = 'RAM', | 
|---|
| 97 | local = False, big = True ) | 
|---|
| 98 |  | 
|---|
| 99 | # distributed threads : one thread per processor | 
|---|
| 100 | for x in xrange (x_size): | 
|---|
| 101 | for y in xrange (y_size): | 
|---|
| 102 | cluster_id = (x * y_size) + y | 
|---|
| 103 | if ( mapping.clusters[cluster_id].procs ): | 
|---|
| 104 | for p in xrange( nprocs ): | 
|---|
| 105 | if (x == 0) and (y == 0) and (p == 0) :   # main thread | 
|---|
| 106 | startid = 1 | 
|---|
| 107 | is_main = True | 
|---|
| 108 | else :                                    # trsp thread | 
|---|
| 109 | startid = 0 | 
|---|
| 110 | is_main = False | 
|---|
| 111 |  | 
|---|
| 112 | mapping.addThread( vspace, | 
|---|
| 113 | 'conv_%d_%d_%d' % (x,y,p), | 
|---|
| 114 | is_main, | 
|---|
| 115 | x, y, p, | 
|---|
| 116 | 'conv_stack_%d_%d_%d' % (x,y,p), | 
|---|
| 117 | 'conv_heap_%d_%d' % (x,y), | 
|---|
| 118 | startid ) | 
|---|
| 119 |  | 
|---|
| 120 | # extend mapping name | 
|---|
| 121 | mapping.name += '_convol' | 
|---|
| 122 |  | 
|---|
| 123 | return vspace  # useful for test | 
|---|
| 124 |  | 
|---|
| 125 | ################################ test ################################################ | 
|---|
| 126 |  | 
|---|
| 127 | if __name__ == '__main__': | 
|---|
| 128 |  | 
|---|
| 129 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) | 
|---|
| 130 | print vspace.xml() | 
|---|
| 131 |  | 
|---|
| 132 |  | 
|---|
| 133 | # Local Variables: | 
|---|
| 134 | # tab-width: 4; | 
|---|
| 135 | # c-basic-offset: 4; | 
|---|
| 136 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); | 
|---|
| 137 | # indent-tabs-mode: nil; | 
|---|
| 138 | # End: | 
|---|
| 139 | # | 
|---|
| 140 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
| 141 |  | 
|---|