1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from mapping import * |
---|
4 | |
---|
5 | ################################################################################## |
---|
6 | # file : rosenfeld.py |
---|
7 | # date : January 2016 |
---|
8 | # author : Quentin Meunier |
---|
9 | ################################################################################## |
---|
10 | # This file describes the mapping of the single-threaded "rosenfeld". |
---|
11 | # This include both the mapping of virtual segments on the clusters, |
---|
12 | # and the mapping of tasks on processor. |
---|
13 | # The mapping of virtual segments is the following: |
---|
14 | # - There is one shared data vseg in cluster[0][0] |
---|
15 | # - The code vsegs are replicated on all clusters containing processors. |
---|
16 | # - There is one heap vseg per cluster containing processors. |
---|
17 | # - The stacks vsegs are distibuted on all clusters containing processors. |
---|
18 | # This mapping uses 5 platform parameters, (obtained from the "mapping" argument) |
---|
19 | # - x_size : number of clusters in a row |
---|
20 | # - y_size : number of clusters in a column |
---|
21 | # - x_width : number of bits coding x coordinate |
---|
22 | # - y_width : number of bits coding y coordinate |
---|
23 | # - nprocs : number of processors per cluster |
---|
24 | ################################################################################## |
---|
25 | |
---|
26 | ######################### |
---|
27 | def extend(mapping): |
---|
28 | |
---|
29 | x_size = mapping.x_size |
---|
30 | y_size = mapping.y_size |
---|
31 | nprocs = mapping.nprocs |
---|
32 | x_width = mapping.x_width |
---|
33 | y_width = mapping.y_width |
---|
34 | |
---|
35 | # define vsegs base & size |
---|
36 | code_base = 0x10000000 |
---|
37 | code_size = 0x00030000 # 192 Kbytes (replicated in each cluster) |
---|
38 | |
---|
39 | data_base = 0x20000000 |
---|
40 | data_size = 0x00010000 # 64 Kbytes (non replicated) |
---|
41 | |
---|
42 | # QM warning: if less than 8M per cluster (i.e. 2M per thread), small pages are required |
---|
43 | stack_base = 0x30000000 |
---|
44 | stack_size = 0x00080000 # 512K (per cluster) => 128K per thread |
---|
45 | #stack_size = 0x00400000 # 4M (per cluster) => 1M per thread |
---|
46 | |
---|
47 | heap_base = 0x40000000 |
---|
48 | #heap_size = 0x00800000 # 8 Mbytes (per cluster) |
---|
49 | heap_size = 0x10000000 # 256 Mbytes (default) |
---|
50 | |
---|
51 | # create vspace |
---|
52 | vspace = mapping.addVspace( name = 'rosenfeld', startname = 'rosen_data', active = True ) |
---|
53 | |
---|
54 | # data vseg : shared (only in cluster[0,0]) |
---|
55 | mapping.addVseg( vspace, 'rosen_data', data_base, data_size, |
---|
56 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
57 | binpath = 'bin/rosenfeld/appli.elf', |
---|
58 | local = False ) |
---|
59 | |
---|
60 | # code vsegs : local (one copy in each cluster) |
---|
61 | for x in xrange (x_size): |
---|
62 | for y in xrange (y_size): |
---|
63 | cluster_id = (x * y_size) + y |
---|
64 | if (mapping.clusters[cluster_id].procs): |
---|
65 | |
---|
66 | mapping.addVseg( vspace, 'rosen_code_%d_%d' %(x,y), |
---|
67 | code_base , code_size, |
---|
68 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
69 | binpath = 'bin/rosenfeld/appli.elf', |
---|
70 | local = True ) |
---|
71 | |
---|
72 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) |
---|
73 | for x in xrange (x_size): |
---|
74 | for y in xrange (y_size): |
---|
75 | cluster_id = (x * y_size) + y |
---|
76 | if (mapping.clusters[cluster_id].procs): |
---|
77 | for p in xrange(nprocs): |
---|
78 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
79 | size = (stack_size / nprocs) & 0xFFFFF000 |
---|
80 | base = stack_base + (proc_id * size) |
---|
81 | |
---|
82 | mapping.addVseg( vspace, 'rosen_stack_%d_%d_%d' % (x,y,p), |
---|
83 | base, size, 'C_WU', vtype = 'BUFFER', |
---|
84 | x = x , y = y , pseg = 'RAM', |
---|
85 | local = True, big = False ) |
---|
86 | |
---|
87 | # heap vsegs: distributed non local (all heap vsegs can be accessed by all tasks) |
---|
88 | for x in xrange (x_size): |
---|
89 | for y in xrange (y_size): |
---|
90 | cluster_id = (x * y_size) + y |
---|
91 | if (mapping.clusters[cluster_id].procs): |
---|
92 | nclusters = x_size * y_size |
---|
93 | if x == 0 and y == 0 and x_size * y_size == 1: |
---|
94 | # only one cluster: takes all heap |
---|
95 | base = heap_base |
---|
96 | size = 0x20000000 # 512 Mo |
---|
97 | elif x_size * y_size == 4: |
---|
98 | # 4 clusters: 128 Mo to all clusters |
---|
99 | size = 0x08000000 # 128 Mo |
---|
100 | base = heap_base + ((y * x_size) + x) * size |
---|
101 | elif x_size * y_size == 16: |
---|
102 | # 16 clusters: 64 Mo to cluster 0, 32 to others |
---|
103 | if x == 0 and y == 0: |
---|
104 | base = heap_base |
---|
105 | size = 0x04000000 # 64 Mo |
---|
106 | else: |
---|
107 | size = 0x02000000 # 32 Mo |
---|
108 | base = heap_base + 0x04000000 + ((y * x_size) + x - 1) * size |
---|
109 | else: |
---|
110 | size = heap_size / (2 * nclusters) |
---|
111 | base = heap_base + heap_size / 2 + ((y * x_size) + x - 1) * size |
---|
112 | mapping.addVseg(vspace, 'rosen_heap_%d_%d' % (x, y), base, size, |
---|
113 | 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', |
---|
114 | local = False, big = True ) |
---|
115 | |
---|
116 | # distributed tasks / one task per processor |
---|
117 | for x in xrange (x_size): |
---|
118 | for y in xrange (y_size): |
---|
119 | cluster_id = (x * y_size) + y |
---|
120 | if (mapping.clusters[cluster_id].procs): |
---|
121 | for p in xrange(nprocs): |
---|
122 | trdid = (((x * y_size) + y) * nprocs) + p |
---|
123 | if trdid == 0: |
---|
124 | startid = 0 |
---|
125 | is_main = 1 |
---|
126 | else: |
---|
127 | startid = 1 |
---|
128 | is_main = 0 |
---|
129 | #startid = trdid == 0 and 0 or 1 |
---|
130 | #is_main = startid == 0 |
---|
131 | |
---|
132 | mapping.addThread(vspace, 'rosen_%d_%d_%d' % (x, y, p), |
---|
133 | is_main, x, y, p, |
---|
134 | 'rosen_stack_%d_%d_%d' % (x,y,p), |
---|
135 | 'rosen_heap_%d_%d' % (x,y), startid) |
---|
136 | |
---|
137 | |
---|
138 | # extend mapping name |
---|
139 | mapping.name += '_rosenfeld' |
---|
140 | |
---|
141 | return vspace # useful for test |
---|
142 | |
---|
143 | ################################ test ################################################## |
---|
144 | |
---|
145 | if __name__ == '__main__': |
---|
146 | |
---|
147 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) |
---|
148 | print vspace.xml() |
---|
149 | |
---|
150 | |
---|
151 | # Local Variables: |
---|
152 | # tab-width: 4; |
---|
153 | # c-basic-offset: 4; |
---|
154 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
155 | # indent-tabs-mode: nil; |
---|
156 | # End: |
---|
157 | # |
---|
158 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
159 | |
---|