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