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', startname = 'classif_data', active = False ) |
---|
59 | |
---|
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', |
---|
63 | binpath = 'bin/classif/appli.elf', |
---|
64 | local = False ) |
---|
65 | |
---|
66 | # heap vsegs : shared (one per cluster) |
---|
67 | for x in xrange (x_size): |
---|
68 | for y in xrange (y_size): |
---|
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) |
---|
73 | |
---|
74 | mapping.addVseg( vspace, 'classif_heap_%d_%d' %(x,y), base , size, |
---|
75 | 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', |
---|
76 | local = False, big = True ) |
---|
77 | |
---|
78 | # code vsegs : local (one copy per cluster) |
---|
79 | for x in xrange (x_size): |
---|
80 | for y in xrange (y_size): |
---|
81 | cluster_id = (x * y_size) + y |
---|
82 | if ( mapping.clusters[cluster_id].procs ): |
---|
83 | |
---|
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', |
---|
87 | binpath = 'bin/classif/appli.elf', |
---|
88 | local = True ) |
---|
89 | |
---|
90 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) |
---|
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 | |
---|
97 | for x in xrange (x_size): |
---|
98 | for y in xrange (y_size): |
---|
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 |
---|
103 | base = stack_base + (proc_id * stack_size) + stack_size |
---|
104 | |
---|
105 | mapping.addVseg( vspace, 'classif_stack_%d_%d_%d' % (x,y,p), |
---|
106 | base, stack_size, 'C_WU', vtype = 'BUFFER', |
---|
107 | x = x , y = y , pseg = 'RAM', |
---|
108 | local = True ) |
---|
109 | |
---|
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 | |
---|
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 | 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 |
---|
127 | thread_name = 'stor_%d_%d_%d' %(x,y,p) |
---|
128 | else : # thread analyse |
---|
129 | start_index = 1 |
---|
130 | thread_name = 'anal_%d_%d_%d' % (x,y,p) |
---|
131 | |
---|
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 |
---|
136 | |
---|
137 | # extend mapping name |
---|
138 | mapping.name += '_classif' |
---|
139 | |
---|
140 | return vspace # useful for test |
---|
141 | |
---|
142 | ################################ test ############################################ |
---|
143 | |
---|
144 | if __name__ == '__main__': |
---|
145 | |
---|
146 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) |
---|
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 | |
---|