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