[334] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | from mapping import * |
---|
| 4 | |
---|
| 5 | ###################################################################################### |
---|
[589] | 6 | # file : convol.py |
---|
[334] | 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 tasks on processors. |
---|
[502] | 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. |
---|
[334] | 20 | # This mapping uses 5 platform parameters, (obtained from the "mapping" argument) |
---|
[502] | 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 |
---|
[334] | 26 | #################################################################################### |
---|
| 27 | |
---|
| 28 | ###################### |
---|
[589] | 29 | def extend( mapping ): |
---|
[334] | 30 | |
---|
| 31 | x_size = mapping.x_size |
---|
| 32 | y_size = mapping.y_size |
---|
[415] | 33 | nprocs = mapping.nprocs |
---|
[334] | 34 | x_width = mapping.x_width |
---|
| 35 | y_width = mapping.y_width |
---|
| 36 | |
---|
| 37 | # define vsegs base & size |
---|
| 38 | code_base = 0x10000000 |
---|
[415] | 39 | code_size = 0x00010000 # 64 Kbytes (replicated in each cluster) |
---|
[334] | 40 | |
---|
| 41 | data_base = 0x20000000 |
---|
[669] | 42 | data_size = 0x00020000 # 128 Kbytes (non replicated) |
---|
[334] | 43 | |
---|
| 44 | heap_base = 0x40000000 |
---|
[415] | 45 | heap_size = 0x01000000 # 16 Mbytes (per cluster) |
---|
[334] | 46 | |
---|
| 47 | stack_base = 0x50000000 |
---|
[415] | 48 | stack_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
[334] | 49 | |
---|
| 50 | # create Vspace |
---|
[669] | 51 | vspace = mapping.addVspace( name = 'convol', startname = 'conv_data', active = False ) |
---|
[334] | 52 | |
---|
[353] | 53 | # data vseg in cluster[0,0] : non local |
---|
[502] | 54 | mapping.addVseg( vspace, 'conv_data', data_base , data_size, |
---|
| 55 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
[610] | 56 | binpath = 'bin/convol/appli.elf', |
---|
[353] | 57 | local = False ) |
---|
[334] | 58 | |
---|
[415] | 59 | # code vsegs : local (one copy in each cluster) |
---|
[353] | 60 | for x in xrange (x_size): |
---|
| 61 | for y in xrange (y_size): |
---|
[502] | 62 | cluster_id = (x * y_size) + y |
---|
| 63 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 64 | size = code_size |
---|
| 65 | base = code_base |
---|
[334] | 66 | |
---|
[502] | 67 | mapping.addVseg( vspace, 'conv_code_%d_%d' % (x,y), base, size, |
---|
| 68 | 'CXWU', vtype = 'ELF', x = x , y = y , pseg = 'RAM', |
---|
[610] | 69 | binpath = 'bin/convol/appli.elf', |
---|
[502] | 70 | local = True ) |
---|
| 71 | |
---|
[353] | 72 | # stack vsegs : local (one stack per processor) |
---|
[334] | 73 | for x in xrange (x_size): |
---|
| 74 | for y in xrange (y_size): |
---|
[502] | 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 ) |
---|
[334] | 86 | |
---|
[502] | 87 | # heap vsegs : distributed but non local (any heap can be accessed by any task) |
---|
[334] | 88 | for x in xrange (x_size): |
---|
| 89 | for y in xrange (y_size): |
---|
[415] | 90 | cluster_id = (x * y_size) + y |
---|
[502] | 91 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 92 | size = heap_size |
---|
| 93 | base = heap_base + (cluster_id * size) |
---|
[353] | 94 | |
---|
[502] | 95 | mapping.addVseg( vspace, 'conv_heap_%d_%d' % (x,y), base, size, |
---|
| 96 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
| 97 | local = False, big = True ) |
---|
| 98 | |
---|
[353] | 99 | # distributed tasks : one task per processor |
---|
| 100 | for x in xrange (x_size): |
---|
| 101 | for y in xrange (y_size): |
---|
[502] | 102 | cluster_id = (x * y_size) + y |
---|
| 103 | if ( mapping.clusters[cluster_id].procs ): |
---|
| 104 | for p in xrange( nprocs ): |
---|
| 105 | trdid = (((x * y_size) + y) * nprocs) + p |
---|
[334] | 106 | |
---|
[502] | 107 | mapping.addTask( vspace, 'conv_%d_%d_%d' % (x,y,p), |
---|
| 108 | trdid, x, y, p, |
---|
| 109 | 'conv_stack_%d_%d_%d' % (x,y,p), |
---|
| 110 | 'conv_heap_%d_%d' % (x,y), 0 ) |
---|
| 111 | |
---|
[334] | 112 | # extend mapping name |
---|
| 113 | mapping.name += '_convol' |
---|
| 114 | |
---|
| 115 | return vspace # useful for test |
---|
| 116 | |
---|
[502] | 117 | ################################ test ################################################ |
---|
[334] | 118 | |
---|
| 119 | if __name__ == '__main__': |
---|
| 120 | |
---|
[589] | 121 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) |
---|
[334] | 122 | print vspace.xml() |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | # Local Variables: |
---|
| 126 | # tab-width: 4; |
---|
| 127 | # c-basic-offset: 4; |
---|
| 128 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 129 | # indent-tabs-mode: nil; |
---|
| 130 | # End: |
---|
| 131 | # |
---|
| 132 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 133 | |
---|