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