1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from mapping import * |
---|
4 | |
---|
5 | ###################################################################################### |
---|
6 | # file : transpose.py (for the transpose application) |
---|
7 | # date : may 2014 |
---|
8 | # author : Alain Greiner |
---|
9 | ####################################################################################### |
---|
10 | # This file describes the mapping of the multi-threaded "transpose" |
---|
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 | # - nprocs : number of processors per cluster |
---|
20 | #################################################################################### |
---|
21 | |
---|
22 | ######################### |
---|
23 | def transpose( mapping ): |
---|
24 | |
---|
25 | x_size = mapping.x_size |
---|
26 | y_size = mapping.y_size |
---|
27 | nprocs = mapping.nprocs |
---|
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 (replicated in each cluster) |
---|
34 | |
---|
35 | data_base = 0x20000000 |
---|
36 | data_size = 0x00010000 # 64 Kbytes (non replicated) |
---|
37 | |
---|
38 | stack_base = 0x40000000 |
---|
39 | stack_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
40 | |
---|
41 | heap_base = 0x60000000 |
---|
42 | heap_size = 0x00200000 # 2 Mbytes (per cluster) |
---|
43 | |
---|
44 | # create vspace |
---|
45 | vspace = mapping.addVspace( name = 'transpose', startname = 'trsp_data' ) |
---|
46 | |
---|
47 | # data vseg : shared (only in cluster[0,0]) |
---|
48 | mapping.addVseg( vspace, 'trsp_data', data_base , data_size, |
---|
49 | 'C_WU', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
50 | binpath = 'build/transpose/transpose.elf', |
---|
51 | local = False ) |
---|
52 | |
---|
53 | # code vsegs : local (one copy in each cluster) |
---|
54 | for x in xrange (x_size): |
---|
55 | for y in xrange (y_size): |
---|
56 | mapping.addVseg( vspace, 'trsp_code_%d_%d' %(x,y), code_base , code_size, |
---|
57 | 'CXWU', vtype = 'ELF', x = x, y = y, pseg = 'RAM', |
---|
58 | binpath = 'build/transpose/transpose.elf', |
---|
59 | local = True ) |
---|
60 | |
---|
61 | # stacks vsegs: local (one stack per processor => nprocs stacks per cluster) |
---|
62 | for x in xrange (x_size): |
---|
63 | for y in xrange (y_size): |
---|
64 | for p in xrange( nprocs ): |
---|
65 | proc_id = (((x * y_size) + y) * nprocs) + p |
---|
66 | size = stack_size / nprocs |
---|
67 | base = stack_base + (proc_id * size) |
---|
68 | mapping.addVseg( vspace, 'trsp_stack_%d_%d_%d' % (x,y,p), base, size, |
---|
69 | 'C_WU', vtype = 'BUFFER', x = x , y = y , pseg = 'RAM', |
---|
70 | local = True, big = True ) |
---|
71 | |
---|
72 | # heap vsegs: distributed but non local (all heap vsegs can be accessed by all tasks) |
---|
73 | for x in xrange (x_size): |
---|
74 | for y in xrange (y_size): |
---|
75 | cluster_id = (x * y_size) + y |
---|
76 | size = heap_size |
---|
77 | base = heap_base + (cluster_id * size) |
---|
78 | mapping.addVseg( vspace, 'trsp_heap_%d_%d' % (x,y), base, size, |
---|
79 | 'C_WU', vtype = 'BUFFER', x = x, y = y, pseg = 'RAM', |
---|
80 | local = False, big = True ) |
---|
81 | |
---|
82 | # distributed tasks / one task per processor |
---|
83 | for x in xrange (x_size): |
---|
84 | for y in xrange (y_size): |
---|
85 | for p in xrange( nprocs ): |
---|
86 | trdid = (((x * y_size) + y) * nprocs) + p |
---|
87 | mapping.addTask( vspace, 'trsp_%d_%d_%d' % (x,y,p), trdid, x, y, p, |
---|
88 | 'trsp_stack_%d_%d_%d' % (x,y,p), |
---|
89 | 'trsp_heap_%d_%d' % (x,y), 0 ) |
---|
90 | |
---|
91 | # extend mapping name |
---|
92 | mapping.name += '_transpose' |
---|
93 | |
---|
94 | return vspace # useful for test |
---|
95 | |
---|
96 | ################################ test ###################################################### |
---|
97 | |
---|
98 | if __name__ == '__main__': |
---|
99 | |
---|
100 | vspace = transpose( 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 | |
---|