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