[334] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | from mapping import * |
---|
| 4 | |
---|
| 5 | ###################################################################################### |
---|
| 6 | # file : convol.py (for the convol application) |
---|
| 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. |
---|
| 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 |
---|
[415] | 19 | # - nprocs : number of processors per cluster |
---|
[334] | 20 | #################################################################################### |
---|
| 21 | |
---|
| 22 | ###################### |
---|
| 23 | def convol( mapping ): |
---|
| 24 | |
---|
| 25 | x_size = mapping.x_size |
---|
| 26 | y_size = mapping.y_size |
---|
[415] | 27 | nprocs = mapping.nprocs |
---|
[334] | 28 | x_width = mapping.x_width |
---|
| 29 | y_width = mapping.y_width |
---|
| 30 | |
---|
| 31 | # define vsegs base & size |
---|
| 32 | code_base = 0x10000000 |
---|
[415] | 33 | code_size = 0x00010000 # 64 Kbytes (replicated in each cluster) |
---|
[334] | 34 | |
---|
| 35 | data_base = 0x20000000 |
---|
[415] | 36 | data_size = 0x00010000 # 64 Kbytes (non replicated) |
---|
[334] | 37 | |
---|
| 38 | heap_base = 0x40000000 |
---|
[415] | 39 | heap_size = 0x01000000 # 16 Mbytes (per cluster) |
---|
[334] | 40 | |
---|
| 41 | stack_base = 0x50000000 |
---|
[415] | 42 | stack_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
[334] | 43 | |
---|
| 44 | # create Vspace |
---|
| 45 | vspace = mapping.addVspace( name = 'convol', startname = 'conv_data' ) |
---|
| 46 | |
---|
[353] | 47 | # data vseg in cluster[0,0] : non local |
---|
[334] | 48 | mapping.addVseg( vspace, 'conv_data', data_base , data_size, 'C_WU', vtype = 'ELF', |
---|
[353] | 49 | x = 0, y = 0, pseg = 'RAM', binpath = 'build/convol/convol.elf', |
---|
| 50 | local = False ) |
---|
[334] | 51 | |
---|
[415] | 52 | # code vsegs : local (one copy in each cluster) |
---|
[353] | 53 | for x in xrange (x_size): |
---|
| 54 | for y in xrange (y_size): |
---|
| 55 | size = code_size |
---|
| 56 | base = code_base |
---|
| 57 | mapping.addVseg( vspace, 'conv_code_%d_%d' % (x,y), base, size, |
---|
| 58 | 'CXWU', vtype = 'ELF', x = x , y = y , pseg = 'RAM', |
---|
| 59 | binpath = 'build/convol/convol.elf', |
---|
| 60 | local = True ) |
---|
[334] | 61 | |
---|
[353] | 62 | # stack vsegs : local (one stack per processor) |
---|
[334] | 63 | for x in xrange (x_size): |
---|
| 64 | for y in xrange (y_size): |
---|
[415] | 65 | for p in xrange( nprocs ): |
---|
| 66 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
[457] | 67 | size = (stack_size / nprocs) & 0xFFFFF000 |
---|
[334] | 68 | base = stack_base + (proc_id * size) |
---|
| 69 | mapping.addVseg( vspace, 'conv_stack_%d_%d_%d' % (x,y,p), base, size, |
---|
[353] | 70 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
[415] | 71 | local = True, big = True ) |
---|
[334] | 72 | |
---|
[415] | 73 | # heap vsegs : distributed but non local (all heap vsegs can be accessed by all tasks) |
---|
[334] | 74 | for x in xrange (x_size): |
---|
| 75 | for y in xrange (y_size): |
---|
[415] | 76 | cluster_id = (x * y_size) + y |
---|
| 77 | size = heap_size |
---|
| 78 | base = heap_base + (cluster_id * size) |
---|
| 79 | mapping.addVseg( vspace, 'conv_heap_%d_%d' % (x,y), base, size, |
---|
| 80 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
| 81 | local = False, big = True ) |
---|
[353] | 82 | |
---|
| 83 | # distributed tasks : one task per processor |
---|
| 84 | for x in xrange (x_size): |
---|
| 85 | for y in xrange (y_size): |
---|
[415] | 86 | for p in xrange( nprocs ): |
---|
| 87 | trdid = (((x * y_size) + y) * nprocs) + p |
---|
[401] | 88 | mapping.addTask( vspace, 'conv_%d_%d_%d' % (x,y,p), trdid, x, y, p, |
---|
[334] | 89 | 'conv_stack_%d_%d_%d' % (x,y,p), |
---|
| 90 | 'conv_heap_%d_%d' % (x,y), 0 ) |
---|
| 91 | |
---|
| 92 | # extend mapping name |
---|
| 93 | mapping.name += '_convol' |
---|
| 94 | |
---|
| 95 | return vspace # useful for test |
---|
| 96 | |
---|
| 97 | ################################ test ###################################################### |
---|
| 98 | |
---|
| 99 | if __name__ == '__main__': |
---|
| 100 | |
---|
| 101 | vspace = convol( Mapping( 'test', 2, 2, 4 ) ) |
---|
| 102 | print vspace.xml() |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | # Local Variables: |
---|
| 106 | # tab-width: 4; |
---|
| 107 | # c-basic-offset: 4; |
---|
| 108 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 109 | # indent-tabs-mode: nil; |
---|
| 110 | # End: |
---|
| 111 | # |
---|
| 112 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 113 | |
---|