1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from mapping import * |
---|
4 | |
---|
5 | ###################################################################################### |
---|
6 | # file : convol.py (for the convol application) |
---|
7 | # date : may 2014 |
---|
8 | # author : Alain Greiner |
---|
9 | ####################################################################################### |
---|
10 | # This file describes the mapping of the multi-threaded "convol" |
---|
11 | # application on a multi-clusters, multi-processors architecture. |
---|
12 | # This include both the mapping of virtual segments on the clusters, |
---|
13 | # and the mapping of tasks on processors. |
---|
14 | # This mapping uses 5 platform parameters, (obtained from the "mapping" argument) |
---|
15 | # - x_size : number of clusters in a row |
---|
16 | # - y_size : number of clusters in a column |
---|
17 | # - x_width : number of bits coding x coordinate |
---|
18 | # - y_width : number of bits coding y coordinate |
---|
19 | # - procs_max : number of processors per cluster |
---|
20 | #################################################################################### |
---|
21 | |
---|
22 | ###################### |
---|
23 | def convol( mapping ): |
---|
24 | |
---|
25 | x_size = mapping.x_size |
---|
26 | y_size = mapping.y_size |
---|
27 | procs_max = mapping.procs_max |
---|
28 | x_width = mapping.x_width |
---|
29 | y_width = mapping.y_width |
---|
30 | |
---|
31 | # define vsegs base & size |
---|
32 | code_base = 0x10000000 |
---|
33 | code_size = 0x00010000 # 64 Kbytes |
---|
34 | |
---|
35 | data_base = 0x20000000 |
---|
36 | data_size = 0x00010000 # 64 Kbytes |
---|
37 | |
---|
38 | ptab_base = 0x30000000 |
---|
39 | ptab_size = 0x00040000 # 256 Kbytes |
---|
40 | |
---|
41 | heap_base = 0x40000000 |
---|
42 | heap_size = 0x01000000 # max 16 Mbytes (for all clusters) |
---|
43 | |
---|
44 | stack_base = 0x50000000 |
---|
45 | stack_size = 0x02000000 # max 32 Mbytes (for all processors) |
---|
46 | |
---|
47 | # create Vspace |
---|
48 | vspace = mapping.addVspace( name = 'convol', startname = 'conv_data' ) |
---|
49 | |
---|
50 | # data vseg in cluster[0,0] : non local |
---|
51 | mapping.addVseg( vspace, 'conv_data', data_base , data_size, 'C_WU', vtype = 'ELF', |
---|
52 | x = 0, y = 0, pseg = 'RAM', binpath = 'build/convol/convol.elf', |
---|
53 | local = False ) |
---|
54 | |
---|
55 | # code vsegs : local (one replicated vseg per cluster) |
---|
56 | for x in xrange (x_size): |
---|
57 | for y in xrange (y_size): |
---|
58 | size = code_size |
---|
59 | base = code_base |
---|
60 | mapping.addVseg( vspace, 'conv_code_%d_%d' % (x,y), base, size, |
---|
61 | 'CXWU', vtype = 'ELF', x = x , y = y , pseg = 'RAM', |
---|
62 | binpath = 'build/convol/convol.elf', |
---|
63 | local = True ) |
---|
64 | |
---|
65 | # heap vsegs : non local (one communication buffer per cluster) |
---|
66 | for x in xrange (x_size): |
---|
67 | for y in xrange (y_size): |
---|
68 | cluster_id = (x * y_size) + y |
---|
69 | size = heap_size / (x_size * y_size) |
---|
70 | base = heap_base + (cluster_id * size) |
---|
71 | mapping.addVseg( vspace, 'conv_heap_%d_%d' % (x,y), base, size, |
---|
72 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
73 | local = False ) |
---|
74 | |
---|
75 | # stack vsegs : local (one stack per processor) |
---|
76 | for x in xrange (x_size): |
---|
77 | for y in xrange (y_size): |
---|
78 | for p in xrange( procs_max ): |
---|
79 | proc_id = (((x * y_size) + y) * procs_max) + p |
---|
80 | size = stack_size / (x_size * y_size * procs_max) |
---|
81 | base = stack_base + (proc_id * size) |
---|
82 | mapping.addVseg( vspace, 'conv_stack_%d_%d_%d' % (x,y,p), base, size, |
---|
83 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
84 | local = True ) |
---|
85 | |
---|
86 | # ptab vsegs : local (one ptab per cluster) |
---|
87 | for x in xrange (x_size): |
---|
88 | for y in xrange (y_size): |
---|
89 | size = ptab_size |
---|
90 | base = ptab_base |
---|
91 | mapping.addVseg( vspace, 'conv_ptab_%d_%d' %(x,y), base , size, |
---|
92 | 'C_WU', vtype = 'PTAB', x = x , y = y , pseg = 'RAM', |
---|
93 | align = 13, |
---|
94 | local = True ) |
---|
95 | |
---|
96 | # distributed tasks : one task per processor |
---|
97 | for x in xrange (x_size): |
---|
98 | for y in xrange (y_size): |
---|
99 | for p in xrange( procs_max ): |
---|
100 | trdid = (((x * y_size) + y) * procs_max) + p |
---|
101 | mapping.addTask( vspace, 'conv_%d_%d_%d' % (x,y,p), trdid, x, y, p, |
---|
102 | 'conv_stack_%d_%d_%d' % (x,y,p), |
---|
103 | 'conv_heap_%d_%d' % (x,y), 0 ) |
---|
104 | |
---|
105 | # extend mapping name |
---|
106 | mapping.name += '_convol' |
---|
107 | |
---|
108 | return vspace # useful for test |
---|
109 | |
---|
110 | ################################ test ###################################################### |
---|
111 | |
---|
112 | if __name__ == '__main__': |
---|
113 | |
---|
114 | vspace = convol( Mapping( 'test', 2, 2, 4 ) ) |
---|
115 | print vspace.xml() |
---|
116 | |
---|
117 | |
---|
118 | # Local Variables: |
---|
119 | # tab-width: 4; |
---|
120 | # c-basic-offset: 4; |
---|
121 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
122 | # indent-tabs-mode: nil; |
---|
123 | # End: |
---|
124 | # |
---|
125 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
126 | |
---|