| [457] | 1 | #!/usr/bin/env python | 
|---|
 | 2 |  | 
|---|
 | 3 | from mapping import * | 
|---|
 | 4 |  | 
|---|
| [502] | 5 | ################################################################################### | 
|---|
| [589] | 6 | #   file   : classif.py  | 
|---|
| [457] | 7 | #   date   : november 2014 | 
|---|
 | 8 | #   author : Alain Greiner | 
|---|
| [502] | 9 | ################################################################################### | 
|---|
| [457] | 10 | #  This file describes the mapping of the multi-threaded "classif"  | 
|---|
 | 11 | #  application on a multi-clusters, multi-processors architecture. | 
|---|
 | 12 | #  The mapping of tasks on processors is the following: | 
|---|
| [502] | 13 | #    - one "load" task per cluster containing processors,  | 
|---|
 | 14 | #    - one "store" task per cluster containing processors,  | 
|---|
 | 15 | #    - (nprocs-2) "analyse" task per cluster containing processors. | 
|---|
 | 16 | #  The mapping of virtual segments is the following: | 
|---|
| [473] | 17 | #    - There is one shared data vseg in cluster[0][0] | 
|---|
| [502] | 18 | #    - The code vsegs are replicated on all clusters containing processors. | 
|---|
 | 19 | #    - There is one heap vseg per cluster containing processors. | 
|---|
 | 20 | #    - The stacks vsegs are distibuted on all clusters containing processors. | 
|---|
| [457] | 21 | #  This mapping uses 5 platform parameters, (obtained from the "mapping" argument) | 
|---|
 | 22 | #    - x_size    : number of clusters in a row | 
|---|
 | 23 | #    - y_size    : number of clusters in a column | 
|---|
 | 24 | #    - x_width   : number of bits for x field | 
|---|
 | 25 | #    - y_width   : number of bits for y field | 
|---|
 | 26 | #    - nprocs    : number of processors per cluster | 
|---|
 | 27 | # | 
|---|
| [488] | 28 | #  WARNING: The target architecture cannot contain less | 
|---|
 | 29 | #           than 3 processors per cluster. | 
|---|
| [502] | 30 | ################################################################################## | 
|---|
| [457] | 31 |  | 
|---|
| [589] | 32 | ###################### | 
|---|
 | 33 | def extend( mapping ): | 
|---|
| [457] | 34 |  | 
|---|
 | 35 |     x_size    = mapping.x_size | 
|---|
 | 36 |     y_size    = mapping.y_size | 
|---|
 | 37 |     nprocs    = mapping.nprocs | 
|---|
 | 38 |     x_width   = mapping.x_width | 
|---|
 | 39 |     y_width   = mapping.y_width | 
|---|
 | 40 |  | 
|---|
| [488] | 41 |     assert (nprocs >= 3) | 
|---|
| [457] | 42 |  | 
|---|
 | 43 |     # define vsegs base & size | 
|---|
 | 44 |     code_base  = 0x10000000 | 
|---|
 | 45 |     code_size  = 0x00010000     # 64 Kbytes (replicated in each cluster) | 
|---|
 | 46 |      | 
|---|
 | 47 |     data_base  = 0x20000000 | 
|---|
| [473] | 48 |     data_size  = 0x00010000     # 64 Kbytes  | 
|---|
| [457] | 49 |  | 
|---|
| [473] | 50 |     heap_base  = 0x30000000 | 
|---|
| [502] | 51 |     heap_size  = 0x00040000     # 256 Kbytes (per cluster)       | 
|---|
| [473] | 52 |  | 
|---|
| [457] | 53 |     stack_base = 0x40000000  | 
|---|
 | 54 |     stack_size = 0x00200000     # 2 Mbytes (per cluster) | 
|---|
 | 55 |  | 
|---|
 | 56 |     # create vspace | 
|---|
| [473] | 57 |     vspace = mapping.addVspace( name = 'classif', startname = 'classif_data' ) | 
|---|
| [457] | 58 |      | 
|---|
| [473] | 59 |     # data vseg : shared / cluster[0][0] | 
|---|
 | 60 |     mapping.addVseg( vspace, 'classif_data', data_base , data_size,  | 
|---|
 | 61 |                      'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM',  | 
|---|
| [610] | 62 |                      binpath = 'bin/classif/appli.elf', | 
|---|
| [473] | 63 |                      local = False ) | 
|---|
 | 64 |  | 
|---|
| [502] | 65 |     # heap vsegs : shared (one per cluster)  | 
|---|
| [457] | 66 |     for x in xrange (x_size): | 
|---|
 | 67 |         for y in xrange (y_size): | 
|---|
| [502] | 68 |             cluster_id = (x * y_size) + y | 
|---|
 | 69 |             if ( mapping.clusters[cluster_id].procs ): | 
|---|
 | 70 |                 size  = heap_size | 
|---|
 | 71 |                 base  = heap_base + (cluster_id * size) | 
|---|
| [457] | 72 |  | 
|---|
| [502] | 73 |                 mapping.addVseg( vspace, 'classif_heap_%d_%d' %(x,y), base , size,  | 
|---|
 | 74 |                                  'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM',  | 
|---|
 | 75 |                                  local = False ) | 
|---|
| [457] | 76 |  | 
|---|
 | 77 |     # code vsegs : local (one copy in each cluster) | 
|---|
 | 78 |     for x in xrange (x_size): | 
|---|
 | 79 |         for y in xrange (y_size): | 
|---|
| [502] | 80 |             cluster_id = (x * y_size) + y | 
|---|
 | 81 |             if ( mapping.clusters[cluster_id].procs ): | 
|---|
| [457] | 82 |  | 
|---|
| [502] | 83 |                 mapping.addVseg( vspace, 'classif_code_%d_%d' %(x,y),  | 
|---|
 | 84 |                                  code_base , code_size, | 
|---|
 | 85 |                                  'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM',  | 
|---|
| [610] | 86 |                                  binpath = 'bin/classif/appli.elf', | 
|---|
| [502] | 87 |                                  local = True ) | 
|---|
| [457] | 88 |  | 
|---|
| [502] | 89 |     # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) | 
|---|
| [457] | 90 |     for x in xrange (x_size): | 
|---|
 | 91 |         for y in xrange (y_size): | 
|---|
| [502] | 92 |             cluster_id = (x * y_size) + y | 
|---|
 | 93 |             if ( mapping.clusters[cluster_id].procs ): | 
|---|
 | 94 |                 for p in xrange( nprocs ): | 
|---|
 | 95 |                     proc_id = (((x * y_size) + y) * nprocs) + p | 
|---|
 | 96 |                     size    = (stack_size / nprocs) & 0xFFFFF000 | 
|---|
 | 97 |                     base    = stack_base + (proc_id * size) | 
|---|
| [457] | 98 |  | 
|---|
| [502] | 99 |                     mapping.addVseg( vspace, 'classif_stack_%d_%d_%d' % (x,y,p),  | 
|---|
 | 100 |                                      base, size, 'C_WU', vtype = 'BUFFER',  | 
|---|
 | 101 |                                      x = x , y = y , pseg = 'RAM', | 
|---|
 | 102 |                                      local = True, big = True ) | 
|---|
| [457] | 103 |  | 
|---|
 | 104 |     # distributed tasks / one task per processor | 
|---|
 | 105 |     for x in xrange (x_size): | 
|---|
 | 106 |         for y in xrange (y_size): | 
|---|
| [502] | 107 |             cluster_id = (x * y_size) + y | 
|---|
 | 108 |             if ( mapping.clusters[cluster_id].procs ): | 
|---|
 | 109 |                 for p in xrange( nprocs ): | 
|---|
 | 110 |                     trdid = (((x * y_size) + y) * nprocs) + p | 
|---|
 | 111 |                     if  ( p== 0 ):                              # task load | 
|---|
| [610] | 112 |                         task_index = 2 | 
|---|
| [502] | 113 |                         task_name  = 'load_%d_%d_%d' %(x,y,p)             | 
|---|
 | 114 |                     elif  ( p== 1 ):                            # task store | 
|---|
 | 115 |                         task_index = 1 | 
|---|
 | 116 |                         task_name  = 'store_%d_%d_%d' %(x,y,p)             | 
|---|
 | 117 |                     else :                                      # task analyse | 
|---|
| [610] | 118 |                         task_index = 0 | 
|---|
| [502] | 119 |                         task_name  = 'analyse_%d_%d_%d' % (x,y,p) | 
|---|
| [473] | 120 |  | 
|---|
| [502] | 121 |                     mapping.addTask( vspace, task_name, trdid, x, y, p, | 
|---|
 | 122 |                                      'classif_stack_%d_%d_%d' % (x,y,p),  | 
|---|
 | 123 |                                      'classif_heap_%d_%d' % (x,y), | 
|---|
 | 124 |                                      task_index ) | 
|---|
| [457] | 125 |  | 
|---|
 | 126 |     # extend mapping name | 
|---|
 | 127 |     mapping.name += '_classif' | 
|---|
 | 128 |  | 
|---|
 | 129 |     return vspace  # useful for test | 
|---|
 | 130 |              | 
|---|
| [533] | 131 | ################################ test ############################################ | 
|---|
| [457] | 132 |  | 
|---|
 | 133 | if __name__ == '__main__': | 
|---|
 | 134 |  | 
|---|
| [589] | 135 |     vspace = extend( Mapping( 'test', 2, 2, 4 ) ) | 
|---|
| [457] | 136 |     print vspace.xml() | 
|---|
 | 137 |  | 
|---|
 | 138 |  | 
|---|
 | 139 | # Local Variables: | 
|---|
 | 140 | # tab-width: 4; | 
|---|
 | 141 | # c-basic-offset: 4; | 
|---|
 | 142 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); | 
|---|
 | 143 | # indent-tabs-mode: nil; | 
|---|
 | 144 | # End: | 
|---|
 | 145 | # | 
|---|
 | 146 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
 | 147 |  | 
|---|