1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ####################################################################################### |
---|
4 | # file : genmap |
---|
5 | # date : april 2014 |
---|
6 | # author : Alain Greiner |
---|
7 | ####################################################################################### |
---|
8 | # This generic script maps one or several multi-tasks applications on a specific |
---|
9 | # instance of the multi-processors/multi-clusters TSAR architecture. |
---|
10 | # It generates the files required for hardware and software compilation: |
---|
11 | # 1) The "hard_config.h" file is used to generate the top.cppnetbsd file (hardware), |
---|
12 | # and to compile the tsar_preloader.elf, the GietVM boot.elf and kernel.elf files. |
---|
13 | # 2) The optionals "map.bin" and vsegs.ld" files are used to configure the GietVM. |
---|
14 | # 3) The optional "netbsd.dts" file can be used to configure NetBSD. |
---|
15 | # 4) The optional "arch.bib" file can be used to configure ALMOS. |
---|
16 | # 5) An optional "map.xml" file can be generated for debug. |
---|
17 | ####################################################################################### |
---|
18 | # The hardware parameters are: |
---|
19 | # - x_size : number of clusters in a row |
---|
20 | # - y_size : number of clusters in a column |
---|
21 | # - nprocs : number of processors per cluster |
---|
22 | ####################################################################################### |
---|
23 | # The supported platforms are: |
---|
24 | # - tsar_generic_iob |
---|
25 | # - tsar_generic_leti |
---|
26 | ####################################################################################### |
---|
27 | # The supported parallel applications are: |
---|
28 | # - sort (one thread per processor) |
---|
29 | # - transpose (one thread per processor) |
---|
30 | # - convol (one thread per processor) |
---|
31 | ####################################################################################### |
---|
32 | |
---|
33 | from optparse import OptionParser |
---|
34 | |
---|
35 | from mapping import * |
---|
36 | |
---|
37 | from transpose import * |
---|
38 | from sort import * |
---|
39 | from convol import * |
---|
40 | |
---|
41 | import sys |
---|
42 | |
---|
43 | ###################################################################################### |
---|
44 | # define command line arguments |
---|
45 | ###################################################################################### |
---|
46 | |
---|
47 | parser = OptionParser() |
---|
48 | |
---|
49 | parser.add_option( '--arch', type = 'string', dest = 'arch_path', |
---|
50 | help = 'define pathname to architecture' ) |
---|
51 | |
---|
52 | parser.add_option( '--x', type = 'int', dest = 'x_size', |
---|
53 | default = 2, |
---|
54 | help = 'define number of clusters in a row' ) |
---|
55 | |
---|
56 | parser.add_option( '--y', type = 'int', dest = 'y_size', |
---|
57 | default = 2, |
---|
58 | help = 'define number of clusters in a column' ) |
---|
59 | |
---|
60 | parser.add_option( '--p', type = 'int', dest = 'nprocs', |
---|
61 | default = 2, |
---|
62 | help = 'define number of processors per cluster' ) |
---|
63 | |
---|
64 | parser.add_option( '--v', action = 'store_true', dest = 'verbose', |
---|
65 | default = False, |
---|
66 | help = 'display detailed report on map.bin file generation' ) |
---|
67 | |
---|
68 | parser.add_option( '--netbsd', type = 'string', dest = 'netbsd_path', |
---|
69 | help = 'define pathname for the netbsd.dts file' ) |
---|
70 | |
---|
71 | parser.add_option( '--almos', type = 'string', dest = 'almos_path', |
---|
72 | help = 'define pathname for the arch.bib file' ) |
---|
73 | |
---|
74 | parser.add_option( '--giet', type = 'string', dest = 'giet_path', |
---|
75 | help = 'define pathname for the map.bin & vsegs.ld file ' ) |
---|
76 | |
---|
77 | parser.add_option( '--xml', type = 'string', dest = 'xml_path', |
---|
78 | help = 'define pathname for the map.xml file' ) |
---|
79 | |
---|
80 | ############ supported applications ############################################### |
---|
81 | |
---|
82 | parser.add_option( '--transpose', action = 'store_true', dest = 'transpose', |
---|
83 | default = False, |
---|
84 | help = 'map the "transpose" application for the GietVM' ) |
---|
85 | |
---|
86 | parser.add_option( '--sort', action = 'store_true', dest = 'sort', |
---|
87 | default = False, |
---|
88 | help = 'map the "sort" application for the GietVM' ) |
---|
89 | |
---|
90 | parser.add_option( '--convol', action = 'store_true', dest = 'convol', |
---|
91 | default = False, |
---|
92 | help = 'map the "convol" application for the GietVM' ) |
---|
93 | |
---|
94 | ###################################################################################### |
---|
95 | # Get command line arguments |
---|
96 | ###################################################################################### |
---|
97 | |
---|
98 | (options,args) = parser.parse_args() |
---|
99 | |
---|
100 | x_size = options.x_size # number of clusters in a row |
---|
101 | y_size = options.y_size # number of clusters in a column |
---|
102 | nprocs = options.nprocs # number of processors in a cluster |
---|
103 | |
---|
104 | verbose = options.verbose # report on map.bin generation if True |
---|
105 | |
---|
106 | netbsd_path = options.netbsd_path # path for netbsd.dts file |
---|
107 | almos_path = options.almos_path # path for arch.bib file |
---|
108 | giet_path = options.giet_path # path for map.bin & vsegs.ld files |
---|
109 | |
---|
110 | arch_path = options.arch_path # path to selected architecture |
---|
111 | |
---|
112 | xml_path = options.xml_path # path for map.xml file |
---|
113 | |
---|
114 | map_transpose = options.transpose # map "transpose" application if True |
---|
115 | map_sort = options.sort # map "sort" application if True |
---|
116 | map_convol = options.convol # map "convol" application if True |
---|
117 | |
---|
118 | ###################################################################################### |
---|
119 | # build empty platform (no applications yet) |
---|
120 | ###################################################################################### |
---|
121 | |
---|
122 | if ( arch_path == None ): |
---|
123 | print 'You must select a generic architecture on the command line' |
---|
124 | sys.exit(1) |
---|
125 | |
---|
126 | # dynamically append the architecture to PYTHON path (directory pathname) |
---|
127 | sys.path.append( arch_path ) |
---|
128 | |
---|
129 | # dynamically import the PYTHON mapping generator module (file name) |
---|
130 | select = __import__( 'arch' ) |
---|
131 | |
---|
132 | # build mapping calling the function (function name) |
---|
133 | mapping = select.arch( x_size, y_size, nprocs ) |
---|
134 | print '[genmap] platform %s build' % mapping.name |
---|
135 | |
---|
136 | ###################################################################################### |
---|
137 | # complete mapping with application(s) as required |
---|
138 | ###################################################################################### |
---|
139 | |
---|
140 | if ( map_transpose ): |
---|
141 | transpose( mapping ) |
---|
142 | print '[genmap] application "transpose" loaded' |
---|
143 | |
---|
144 | if ( map_sort ): |
---|
145 | sort( mapping ) |
---|
146 | print '[genmap] application "sort" loaded' |
---|
147 | |
---|
148 | if ( map_convol ): |
---|
149 | convol( mapping ) |
---|
150 | print '[genmap] application "convol" loaded' |
---|
151 | |
---|
152 | ###################################################################################### |
---|
153 | # Generate xml file if required. |
---|
154 | # It can be used for debug. |
---|
155 | ###################################################################################### |
---|
156 | |
---|
157 | if ( xml_path != None ): |
---|
158 | pathname = xml_path + '/map.xml' |
---|
159 | f = open ( pathname, 'w' ) |
---|
160 | f.write( mapping.xml() ) |
---|
161 | print '[genmap] %s generated for debug' % pathname |
---|
162 | |
---|
163 | ###################################################################################### |
---|
164 | # Generate netbsd.dts file if required. |
---|
165 | # It is used for NetBSD configuration. |
---|
166 | ###################################################################################### |
---|
167 | |
---|
168 | if ( (netbsd_path != None) and (arch_path != None) ): |
---|
169 | pathname = netbsd_path + '/netbsd.dts' |
---|
170 | f = open ( pathname, 'w' ) |
---|
171 | f.write( mapping.netbsd_dts() ) |
---|
172 | print '[genmap] %s generated for netbsd' % pathname |
---|
173 | |
---|
174 | ###################################################################################### |
---|
175 | # Generate arch.bib file if required. |
---|
176 | # It is used for ALMOS configuration. |
---|
177 | ###################################################################################### |
---|
178 | |
---|
179 | if ( (almos_path != None) and (arch_path != None) ): |
---|
180 | pathname = almos_path + '/arch.info' |
---|
181 | f = open ( pathname, 'w' ) |
---|
182 | f.write( mapping.almos_arch() ) |
---|
183 | print '[genmap] %s generated for almos' % pathname |
---|
184 | |
---|
185 | ###################################################################################### |
---|
186 | # Generate map.bin, giet_vsegs.ld, and hard_config.h files if required. |
---|
187 | # They are used for GietVM compilation and configuration. |
---|
188 | ###################################################################################### |
---|
189 | |
---|
190 | if ( (giet_path != None) and (arch_path != None) ): |
---|
191 | |
---|
192 | pathname = giet_path + '/map.bin' |
---|
193 | f = open ( pathname, 'w' ) |
---|
194 | f.write( str( mapping.cbin( verbose ) ) ) |
---|
195 | print '[genmap] %s generated for giet_vm' % pathname |
---|
196 | |
---|
197 | pathname = giet_path + '/hard_config.h' |
---|
198 | f = open ( pathname, 'w' ) |
---|
199 | f.write( mapping.hard_config() ) |
---|
200 | print '[genmap] %s generated for giet_vm' % pathname |
---|
201 | |
---|
202 | pathname = giet_path + '/giet_vsegs.ld' |
---|
203 | f = open ( pathname, 'w' ) |
---|
204 | f.write( mapping.giet_vsegs() ) |
---|
205 | print '[genmap] %s generated for giet_vm' % pathname |
---|
206 | |
---|