| [317] | 1 | #!/usr/bin/env python | 
|---|
|  | 2 |  | 
|---|
|  | 3 | from mapping import * | 
|---|
|  | 4 |  | 
|---|
|  | 5 | ###################################################################################### | 
|---|
| [336] | 6 | #   file   : transpose.py  (for the transpose application) | 
|---|
| [317] | 7 | #   date   : may 2014 | 
|---|
|  | 8 | #   author : Alain Greiner | 
|---|
|  | 9 | ####################################################################################### | 
|---|
|  | 10 | #  This file describes the mapping of the multi-threaded "transpose" | 
|---|
|  | 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 | 
|---|
|  | 19 | #  - procs_max : number of processors per cluster | 
|---|
|  | 20 | #################################################################################### | 
|---|
|  | 21 |  | 
|---|
|  | 22 | ######################### | 
|---|
|  | 23 | def transpose( mapping ): | 
|---|
|  | 24 |  | 
|---|
|  | 25 | x_size    = mapping.x_size | 
|---|
|  | 26 | y_size    = mapping.y_size | 
|---|
|  | 27 | procs_max = mapping.procs_max | 
|---|
|  | 28 | x_width   = mapping.x_width | 
|---|
|  | 29 | y_width   = mapping.y_width | 
|---|
|  | 30 |  | 
|---|
|  | 31 | # define vsegs base & size | 
|---|
|  | 32 | code_base  = 0x10000000 | 
|---|
| [383] | 33 | code_size  = 0x00010000     # 64 Kbytes (replicated in each cluster) | 
|---|
| [317] | 34 |  | 
|---|
|  | 35 | data_base  = 0x20000000 | 
|---|
| [383] | 36 | data_size  = 0x00010000     # 64 Kbytes (non replicated) | 
|---|
| [317] | 37 |  | 
|---|
|  | 38 | ptab_base  = 0x30000000 | 
|---|
| [383] | 39 | ptab_size  = 0x00040000     # 256 Kbytes (replicated in each cluster) | 
|---|
| [317] | 40 |  | 
|---|
|  | 41 | stack_base = 0x40000000 | 
|---|
| [383] | 42 | stack_size = 0x00100000     # 1 Mbytes (to be divided between all tasks) | 
|---|
| [317] | 43 |  | 
|---|
|  | 44 | heap_base  = 0x50000000 | 
|---|
| [383] | 45 | heap_size  = 0x00010000     # 64 Kbytes (to be shared by all tasks) | 
|---|
| [317] | 46 |  | 
|---|
| [383] | 47 | # create vspace | 
|---|
| [317] | 48 | vspace = mapping.addVspace( name = 'transpose', startname = 'trsp_data' ) | 
|---|
|  | 49 |  | 
|---|
| [383] | 50 | # data vseg : shared (only in cluster[0,0]) | 
|---|
|  | 51 | mapping.addVseg( vspace, 'trsp_data', data_base , data_size, | 
|---|
|  | 52 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', | 
|---|
|  | 53 | binpath = 'build/transpose/transpose.elf', | 
|---|
|  | 54 | local = False ) | 
|---|
| [317] | 55 |  | 
|---|
| [383] | 56 | # code vsegs : local (one copy in each cluster) | 
|---|
|  | 57 | for x in xrange (x_size): | 
|---|
|  | 58 | for y in xrange (y_size): | 
|---|
|  | 59 | mapping.addVseg( vspace, 'trsp_code_%d_%d' %(x,y), code_base , code_size, | 
|---|
|  | 60 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', | 
|---|
|  | 61 | binpath = 'build/transpose/transpose.elf', | 
|---|
|  | 62 | local = True ) | 
|---|
| [317] | 63 |  | 
|---|
| [383] | 64 | # ptab vsegs : local (one specific ptab per cluster) | 
|---|
|  | 65 | for x in xrange (x_size): | 
|---|
|  | 66 | for y in xrange (y_size): | 
|---|
|  | 67 | mapping.addVseg( vspace, 'trsp_ptab_%d_%d' %(x,y), ptab_base , ptab_size, | 
|---|
|  | 68 | 'C_WU', vtype = 'PTAB', x = x, y = y, pseg = 'RAM', | 
|---|
|  | 69 | align = 13, | 
|---|
|  | 70 | local = True ) | 
|---|
| [317] | 71 |  | 
|---|
| [383] | 72 | # stacks vsegs: local (one stack per processor, procs_max stacks per cluster) | 
|---|
|  | 73 | for x in xrange (x_size): | 
|---|
|  | 74 | for y in xrange (y_size): | 
|---|
| [317] | 75 | for p in xrange( procs_max ): | 
|---|
| [383] | 76 | proc_id = (((x * y_size) + y) * procs_max) + p | 
|---|
|  | 77 | size    = stack_size / (x_size * y_size * procs_max) | 
|---|
|  | 78 | base    = stack_base + (proc_id * size) | 
|---|
|  | 79 | mapping.addVseg( vspace, 'trsp_stack_%d_%d_%d' % (x,y,p), base, size, | 
|---|
|  | 80 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', | 
|---|
|  | 81 | local = True ) | 
|---|
|  | 82 |  | 
|---|
|  | 83 | # heap vsegs: shared (all heap segments can be accessed by all tasks) | 
|---|
|  | 84 | for x in xrange (x_size): | 
|---|
|  | 85 | for y in xrange (y_size): | 
|---|
|  | 86 | cluster_id = (x * y_size) + y | 
|---|
|  | 87 | size  = heap_size / (x_size * y_size) | 
|---|
|  | 88 | base  = heap_base + (cluster_id * size) | 
|---|
|  | 89 | mapping.addVseg( vspace, 'trsp_heap_%d_%d' % (x,y), base, size, | 
|---|
|  | 90 | 'C_WU', vtype = 'BUFFER', x = x, y = y, pseg = 'RAM', | 
|---|
|  | 91 | local = False ) | 
|---|
|  | 92 |  | 
|---|
| [317] | 93 | # distributed tasks / one task per processor | 
|---|
|  | 94 | for x in xrange (x_size): | 
|---|
|  | 95 | for y in xrange (y_size): | 
|---|
|  | 96 | for p in xrange( procs_max ): | 
|---|
|  | 97 | trdid = (((x * y_size) + y) * procs_max) + p | 
|---|
| [383] | 98 | mapping.addTask( vspace, 'trsp_%d_%d_%d' % (x,y,p), trdid, x, y, p, | 
|---|
| [317] | 99 | 'trsp_stack_%d_%d_%d' % (x,y,p), | 
|---|
|  | 100 | 'trsp_heap_%d_%d' % (x,y), 0 ) | 
|---|
|  | 101 |  | 
|---|
|  | 102 | # extend mapping name | 
|---|
|  | 103 | mapping.name += '_transpose' | 
|---|
|  | 104 |  | 
|---|
|  | 105 | return vspace  # useful for test | 
|---|
|  | 106 |  | 
|---|
|  | 107 | ################################ test ###################################################### | 
|---|
|  | 108 |  | 
|---|
|  | 109 | if __name__ == '__main__': | 
|---|
|  | 110 |  | 
|---|
|  | 111 | vspace = transpose( Mapping( 'test', 2, 2, 4 ) ) | 
|---|
|  | 112 | print vspace.xml() | 
|---|
|  | 113 |  | 
|---|
|  | 114 |  | 
|---|
|  | 115 | # Local Variables: | 
|---|
|  | 116 | # tab-width: 4; | 
|---|
|  | 117 | # c-basic-offset: 4; | 
|---|
|  | 118 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); | 
|---|
|  | 119 | # indent-tabs-mode: nil; | 
|---|
|  | 120 | # End: | 
|---|
|  | 121 | # | 
|---|
|  | 122 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
|  | 123 |  | 
|---|