1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from mapping import * |
---|
4 | |
---|
5 | ###################################################################################### |
---|
6 | # file : convol.py |
---|
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 | # There is one task per processor. |
---|
15 | # The mapping of virtual segments is the following: |
---|
16 | # - There is one shared data vseg in cluster[0][0] |
---|
17 | # - The code vsegs are replicated on all clusters containing processors. |
---|
18 | # - There is one heap vseg per cluster containing processors. |
---|
19 | # - The stacks vsegs are distibuted on all clusters containing processors. |
---|
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 coding x coordinate |
---|
24 | # - y_width : number of bits coding y coordinate |
---|
25 | # - nprocs : number of processors per cluster |
---|
26 | #################################################################################### |
---|
27 | |
---|
28 | ###################### |
---|
29 | def extend( mapping ): |
---|
30 | |
---|
31 | x_size = mapping.x_size |
---|
32 | y_size = mapping.y_size |
---|
33 | nprocs = mapping.nprocs |
---|
34 | x_width = mapping.x_width |
---|
35 | y_width = mapping.y_width |
---|
36 | |
---|
37 | # define vsegs base & size |
---|
38 | code_base = 0x10000000 |
---|
39 | code_size = 0x00010000 # 64 Kbytes (replicated in each cluster) |
---|
40 | |
---|
41 | data_base = 0x20000000 |
---|
42 | data_size = 0x00010000 # 64 Kbytes (non replicated) |
---|
43 | |
---|
44 | heap_base = 0x40000000 |
---|
45 | heap_size = 0x01000000 # 16 Mbytes (per cluster) |
---|
46 | |
---|
47 | stack_base = 0x50000000 |
---|
48 | stack_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
49 | |
---|
50 | # create Vspace |
---|
51 | vspace = mapping.addVspace( name = 'convol', startname = 'conv_data' ) |
---|
52 | |
---|
53 | # data vseg in cluster[0,0] : non local |
---|
54 | mapping.addVseg( vspace, 'conv_data', data_base , data_size, |
---|
55 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
56 | binpath = 'build/convol/appli.elf', |
---|
57 | local = False ) |
---|
58 | |
---|
59 | # code vsegs : local (one copy in each cluster) |
---|
60 | for x in xrange (x_size): |
---|
61 | for y in xrange (y_size): |
---|
62 | cluster_id = (x * y_size) + y |
---|
63 | if ( mapping.clusters[cluster_id].procs ): |
---|
64 | size = code_size |
---|
65 | base = code_base |
---|
66 | |
---|
67 | mapping.addVseg( vspace, 'conv_code_%d_%d' % (x,y), base, size, |
---|
68 | 'CXWU', vtype = 'ELF', x = x , y = y , pseg = 'RAM', |
---|
69 | binpath = 'build/convol/appli.elf', |
---|
70 | local = True ) |
---|
71 | |
---|
72 | # stack vsegs : local (one stack per processor) |
---|
73 | for x in xrange (x_size): |
---|
74 | for y in xrange (y_size): |
---|
75 | cluster_id = (x * y_size) + y |
---|
76 | if ( mapping.clusters[cluster_id].procs ): |
---|
77 | for p in xrange( nprocs ): |
---|
78 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
79 | size = (stack_size / nprocs) & 0xFFFFF000 |
---|
80 | base = stack_base + (proc_id * size) |
---|
81 | |
---|
82 | mapping.addVseg( vspace, 'conv_stack_%d_%d_%d' % (x,y,p), |
---|
83 | base, size, 'C_WU', vtype = 'BUFFER', |
---|
84 | x = x , y = y , pseg = 'RAM', |
---|
85 | local = True, big = True ) |
---|
86 | |
---|
87 | # heap vsegs : distributed but non local (any heap can be accessed by any task) |
---|
88 | for x in xrange (x_size): |
---|
89 | for y in xrange (y_size): |
---|
90 | cluster_id = (x * y_size) + y |
---|
91 | if ( mapping.clusters[cluster_id].procs ): |
---|
92 | size = heap_size |
---|
93 | base = heap_base + (cluster_id * size) |
---|
94 | |
---|
95 | mapping.addVseg( vspace, 'conv_heap_%d_%d' % (x,y), base, size, |
---|
96 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
97 | local = False, big = True ) |
---|
98 | |
---|
99 | # distributed tasks : one task per processor |
---|
100 | for x in xrange (x_size): |
---|
101 | for y in xrange (y_size): |
---|
102 | cluster_id = (x * y_size) + y |
---|
103 | if ( mapping.clusters[cluster_id].procs ): |
---|
104 | for p in xrange( nprocs ): |
---|
105 | trdid = (((x * y_size) + y) * nprocs) + p |
---|
106 | |
---|
107 | mapping.addTask( vspace, 'conv_%d_%d_%d' % (x,y,p), |
---|
108 | trdid, x, y, p, |
---|
109 | 'conv_stack_%d_%d_%d' % (x,y,p), |
---|
110 | 'conv_heap_%d_%d' % (x,y), 0 ) |
---|
111 | |
---|
112 | # extend mapping name |
---|
113 | mapping.name += '_convol' |
---|
114 | |
---|
115 | return vspace # useful for test |
---|
116 | |
---|
117 | ################################ test ################################################ |
---|
118 | |
---|
119 | if __name__ == '__main__': |
---|
120 | |
---|
121 | vspace = extend( Mapping( 'test', 2, 2, 4 ) ) |
---|
122 | print vspace.xml() |
---|
123 | |
---|
124 | |
---|
125 | # Local Variables: |
---|
126 | # tab-width: 4; |
---|
127 | # c-basic-offset: 4; |
---|
128 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
129 | # indent-tabs-mode: nil; |
---|
130 | # End: |
---|
131 | # |
---|
132 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
133 | |
---|