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