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 | # - one "store" task per cluster, |
---|
15 | # - (nprocs-2) "analyse" task per cluster. |
---|
16 | # The mapping of virtual segments on the clusters is the following: |
---|
17 | # - The code vsegs are replicated on all clusters. |
---|
18 | # - There is one shared data vseg in cluster[0][0] |
---|
19 | # - There is one heap vseg per cluster. |
---|
20 | # - The stacks vsegs are distibuted on all clusters. |
---|
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 = 0x00008000 # 32 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_x_y vsegs : shared / one per cluster |
---|
66 | for x in xrange (x_size): |
---|
67 | for y in xrange (y_size): |
---|
68 | base = heap_base + ( (4*x + y) * heap_size ) |
---|
69 | |
---|
70 | mapping.addVseg( vspace, 'classif_heap_%d_%d' %(x,y), base , heap_size, |
---|
71 | 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', |
---|
72 | local = False ) |
---|
73 | |
---|
74 | # code vsegs : local (one copy in each cluster) |
---|
75 | for x in xrange (x_size): |
---|
76 | for y in xrange (y_size): |
---|
77 | |
---|
78 | mapping.addVseg( vspace, 'classif_code_%d_%d' %(x,y), code_base , code_size, |
---|
79 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
80 | binpath = 'build/classif/classif.elf', |
---|
81 | local = True ) |
---|
82 | |
---|
83 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) |
---|
84 | for x in xrange (x_size): |
---|
85 | for y in xrange (y_size): |
---|
86 | for p in xrange( nprocs ): |
---|
87 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
88 | size = (stack_size / nprocs) & 0xFFFFF000 |
---|
89 | base = stack_base + (proc_id * size) |
---|
90 | |
---|
91 | mapping.addVseg( vspace, 'classif_stack_%d_%d_%d' % (x,y,p), base, size, |
---|
92 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
93 | local = True, big = True ) |
---|
94 | |
---|
95 | # distributed tasks / one task per processor |
---|
96 | for x in xrange (x_size): |
---|
97 | for y in xrange (y_size): |
---|
98 | for p in xrange( nprocs ): |
---|
99 | trdid = (((x * y_size) + y) * nprocs) + p |
---|
100 | if ( p== 0 ): # task load |
---|
101 | task_index = 0 |
---|
102 | task_name = 'load_%d_%d_%d' %(x,y,p) |
---|
103 | elif ( p== 1 ): # task store |
---|
104 | task_index = 1 |
---|
105 | task_name = 'store_%d_%d_%d' %(x,y,p) |
---|
106 | else : # task analyse |
---|
107 | task_index = 2 |
---|
108 | task_name = 'analyse_%d_%d_%d' % (x,y,p) |
---|
109 | |
---|
110 | mapping.addTask( vspace, task_name, trdid, x, y, p, |
---|
111 | 'classif_stack_%d_%d_%d' % (x,y,p), |
---|
112 | 'classif_heap_%d_%d' % (x,y), |
---|
113 | task_index ) |
---|
114 | |
---|
115 | # extend mapping name |
---|
116 | mapping.name += '_classif' |
---|
117 | |
---|
118 | return vspace # useful for test |
---|
119 | |
---|
120 | ################################ test ###################################################### |
---|
121 | |
---|
122 | if __name__ == '__main__': |
---|
123 | |
---|
124 | vspace = classif( Mapping( 'test', 2, 2, 4 ) ) |
---|
125 | print vspace.xml() |
---|
126 | |
---|
127 | |
---|
128 | # Local Variables: |
---|
129 | # tab-width: 4; |
---|
130 | # c-basic-offset: 4; |
---|
131 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
132 | # indent-tabs-mode: nil; |
---|
133 | # End: |
---|
134 | # |
---|
135 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
136 | |
---|