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 | # non replicated vsegs in cluster[0,0] |
---|
51 | mapping.addVseg( vspace, 'conv_code', code_base , code_size, 'CXWU', vtype = 'ELF', |
---|
52 | x = 0, y = 0, pseg = 'RAM', binpath = 'build/convol/convol.elf' ) |
---|
53 | |
---|
54 | mapping.addVseg( vspace, 'conv_data', data_base , data_size, 'C_WU', vtype = 'ELF', |
---|
55 | x = 0, y = 0, pseg = 'RAM', binpath = 'build/convol/convol.elf' ) |
---|
56 | |
---|
57 | mapping.addVseg( vspace, 'conv_ptab', ptab_base , ptab_size, 'C_WU', vtype = 'PTAB', |
---|
58 | x = 0, y = 0, pseg = 'RAM', align = 13 ) |
---|
59 | |
---|
60 | # distributed heaps: one heap per cluster : size = 16 Mbytes/NCLUSTERS |
---|
61 | for x in xrange (x_size): |
---|
62 | for y in xrange (y_size): |
---|
63 | |
---|
64 | cluster_id = (x * y_size) + y |
---|
65 | size = heap_size / (x_size * y_size) |
---|
66 | base = heap_base + (cluster_id * size) |
---|
67 | mapping.addVseg( vspace, 'conv_heap_%d_%d' % (x,y), base, size, |
---|
68 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM' ) |
---|
69 | |
---|
70 | # distributed stacks: one stack per processor : size = 32 Mbytes/(NCLUSTERS*NPROCS) |
---|
71 | for x in xrange (x_size): |
---|
72 | for y in xrange (y_size): |
---|
73 | for p in xrange( procs_max ): |
---|
74 | |
---|
75 | proc_id = (((x * y_size) + y) * procs_max) + p |
---|
76 | size = stack_size / (x_size * y_size * procs_max) |
---|
77 | base = stack_base + (proc_id * size) |
---|
78 | mapping.addVseg( vspace, 'conv_stack_%d_%d_%d' % (x,y,p), base, size, |
---|
79 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM' ) |
---|
80 | |
---|
81 | # distributed tasks / one task per processor |
---|
82 | for x in xrange (x_size): |
---|
83 | for y in xrange (y_size): |
---|
84 | for p in xrange( procs_max ): |
---|
85 | |
---|
86 | trdid = (((x * y_size) + y) * procs_max) + p |
---|
87 | mapping.addTask( vspace, 'sort_%d_%d_%d' % (x,y,p), trdid, x, y, p, |
---|
88 | 'conv_stack_%d_%d_%d' % (x,y,p), |
---|
89 | 'conv_heap_%d_%d' % (x,y), 0 ) |
---|
90 | |
---|
91 | # extend mapping name |
---|
92 | mapping.name += '_convol' |
---|
93 | |
---|
94 | return vspace # useful for test |
---|
95 | |
---|
96 | ################################ test ###################################################### |
---|
97 | |
---|
98 | if __name__ == '__main__': |
---|
99 | |
---|
100 | vspace = convol( Mapping( 'test', 2, 2, 4 ) ) |
---|
101 | print vspace.xml() |
---|
102 | |
---|
103 | |
---|
104 | # Local Variables: |
---|
105 | # tab-width: 4; |
---|
106 | # c-basic-offset: 4; |
---|
107 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
108 | # indent-tabs-mode: nil; |
---|
109 | # End: |
---|
110 | # |
---|
111 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
112 | |
---|