1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from mapping import * |
---|
4 | |
---|
5 | #################################################################################### |
---|
6 | # file : sort.py (for the sort application) |
---|
7 | # date : may 2014 |
---|
8 | # author : Alain Greiner |
---|
9 | #################################################################################### |
---|
10 | # This file describes the mapping of the multi-threaded "sort" |
---|
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 sort( 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 | ntasks = x_size * y_size * procs_max |
---|
32 | |
---|
33 | # define vsegs base & size |
---|
34 | code_base = 0x10000000 |
---|
35 | code_size = 0x00010000 # 64 Kbytes |
---|
36 | |
---|
37 | data_base = 0x20000000 |
---|
38 | data_size = 0x00010000 # 64 Kbytes |
---|
39 | |
---|
40 | ptab_base = 0x30000000 |
---|
41 | ptab_size = 0x00040000 # 256 Kbytes |
---|
42 | |
---|
43 | stack_base = 0x40000000 |
---|
44 | stack_size = 0x00010000 # 64 Kbytes |
---|
45 | |
---|
46 | heap_base = 0x50000000 |
---|
47 | heap_size = 0x00010000 # 64 Kbytes |
---|
48 | |
---|
49 | args_base = 0x60000000 |
---|
50 | args_size = 0x00000004 # 4 bytes |
---|
51 | |
---|
52 | # create Vspace |
---|
53 | vspace = mapping.addVspace( name = 'sort', startname = 'sort_data' ) |
---|
54 | |
---|
55 | # non replicated vsegs in cluster[0,0] |
---|
56 | mapping.addVseg( vspace, 'sort_code', code_base , code_size, 'CXWU', vtype = 'ELF', |
---|
57 | x = 0, y = 0, pseg = 'RAM', binpath = 'build/sort/sort.elf' ) |
---|
58 | |
---|
59 | mapping.addVseg( vspace, 'sort_data', data_base , data_size, 'C_WU', vtype = 'ELF', |
---|
60 | x = 0, y = 0, pseg = 'RAM', binpath = 'build/sort/sort.elf' ) |
---|
61 | |
---|
62 | mapping.addVseg( vspace, 'sort_args', args_base , args_size, 'C_WU', vtype = 'CONST', |
---|
63 | x = 0, y = 0, pseg = 'RAM', init = ntasks ) |
---|
64 | |
---|
65 | # distributed vsegs: one stack per task, one ptab and heap per cluster |
---|
66 | for c in mapping.clusters: |
---|
67 | x, y = c.x, c.y |
---|
68 | cluster_offset = ((x << y_width) + y) << 20 # 1 Mbytes per cluster |
---|
69 | mapping.addVseg( vspace, 'sort_heap_%d_%d' % (x, y), |
---|
70 | heap_base + cluster_offset, heap_size, 'C_WU', |
---|
71 | vtype = 'BUFFER', x = x, y = y, pseg = 'RAM' ) |
---|
72 | |
---|
73 | mapping.addVseg( vspace, 'sort_ptab_%d_%d' % (x, y), |
---|
74 | ptab_base + cluster_offset, ptab_size, 'C_WU', |
---|
75 | vtype = 'PTAB', x = x, y = y, pseg = 'RAM', align = 13 ) |
---|
76 | |
---|
77 | for p in c.procs: |
---|
78 | l = p.lpid |
---|
79 | proc_offset = cluster_offset + (l << 18) # 256 Kbytes per proc |
---|
80 | mapping.addVseg( vspace, 'sort_stack_%d_%d_%d' % (x, y, l), |
---|
81 | stack_base + proc_offset, stack_size, 'C_WU', |
---|
82 | vtype = 'BUFFER', x = x, y = y, pseg = 'RAM' ) |
---|
83 | |
---|
84 | # distributed tasks / one task per processor |
---|
85 | trdid = 0 |
---|
86 | for c in mapping.clusters: |
---|
87 | x, y = c.x, c.y |
---|
88 | for p in c.procs: |
---|
89 | l = p.lpid |
---|
90 | mapping.addTask( vspace, 'sort_%d_%d_%d' % (x, y, l), trdid, x, y, l, |
---|
91 | 'sort_stack_%d_%d_%d' % (x, y, l), |
---|
92 | 'sort_heap_%d_%d' % (x, y), 0 ) |
---|
93 | trdid += 1 |
---|
94 | |
---|
95 | # extend mapping name |
---|
96 | mapping.name += '_sort' |
---|
97 | |
---|
98 | return vspace # useful for test |
---|
99 | |
---|
100 | ################################ test ################################################### |
---|
101 | |
---|
102 | if __name__ == '__main__': |
---|
103 | |
---|
104 | vspace = sort( Mapping( 'test', 2, 2, 4 ) ) |
---|
105 | print vspace.xml() |
---|
106 | |
---|
107 | |
---|
108 | # Local Variables: |
---|
109 | # tab-width: 4; |
---|
110 | # c-basic-offset: 4; |
---|
111 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
112 | # indent-tabs-mode: nil; |
---|
113 | # End: |
---|
114 | # |
---|
115 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
116 | |
---|