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 "netbsd.dts" file can be used to configure NetBSD. |
---|
16 | # 5) The optional "arch.bib" file can be used to configure ALMOS. |
---|
17 | # 6) An optional "map.xml" file can be generated for debug. |
---|
18 | ####################################################################################### |
---|
19 | # The hardware parameters are: |
---|
20 | # - x_size : number of clusters in a row |
---|
21 | # - y_size : number of clusters in a column |
---|
22 | # - nprocs : number of processors per cluster |
---|
23 | ####################################################################################### |
---|
24 | # The supported platforms are: |
---|
25 | # - tsar_generic_iob |
---|
26 | # - tsar_generic_leti |
---|
27 | ####################################################################################### |
---|
28 | # The supported parallel applications are: |
---|
29 | # - sort (one thread per processor) |
---|
30 | # - transpose (one thread per processor) |
---|
31 | # - convol (one thread per processor) |
---|
32 | ####################################################################################### |
---|
33 | |
---|
34 | from optparse import OptionParser |
---|
35 | from mapping import * |
---|
36 | |
---|
37 | import sys |
---|
38 | |
---|
39 | ###################################################################################### |
---|
40 | # define command line arguments |
---|
41 | ###################################################################################### |
---|
42 | |
---|
43 | parser = OptionParser() |
---|
44 | |
---|
45 | parser.add_option( '--arch', type = 'string', dest = 'arch_path', |
---|
46 | help = 'define pathname to architecture' ) |
---|
47 | |
---|
48 | parser.add_option( '--x', type = 'int', dest = 'x_size', |
---|
49 | default = 2, |
---|
50 | help = 'define number of clusters in a row' ) |
---|
51 | |
---|
52 | parser.add_option( '--y', type = 'int', dest = 'y_size', |
---|
53 | default = 2, |
---|
54 | help = 'define number of clusters in a column' ) |
---|
55 | |
---|
56 | parser.add_option( '--p', type = 'int', dest = 'nprocs', |
---|
57 | default = 2, |
---|
58 | help = 'define number of processors per cluster' ) |
---|
59 | |
---|
60 | parser.add_option( '--fbf', type = 'int', dest = 'fbf_size', |
---|
61 | default = 128, |
---|
62 | help = 'define frame buffer width and heigth' ) |
---|
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( '--linux', type = 'string', dest = 'linux_path', |
---|
72 | help = 'define pathname for the linux.dts file' ) |
---|
73 | |
---|
74 | parser.add_option( '--almos', type = 'string', dest = 'almos_path', |
---|
75 | help = 'define pathname for the arch.bib file' ) |
---|
76 | |
---|
77 | parser.add_option( '--giet', type = 'string', dest = 'giet_path', |
---|
78 | help = 'define pathname for the map.bin & vsegs.ld file ' ) |
---|
79 | |
---|
80 | parser.add_option( '--hard', type = 'string', dest = 'hard_path', |
---|
81 | help = 'define pathname for the hard_config.h file ' ) |
---|
82 | |
---|
83 | parser.add_option( '--xml', type = 'string', dest = 'xml_path', |
---|
84 | help = 'define pathname for the map.xml file' ) |
---|
85 | |
---|
86 | ############ supported applications ############################################### |
---|
87 | |
---|
88 | parser.add_option( '--transpose', action = 'store_true', dest = 'transpose', |
---|
89 | default = False, |
---|
90 | help = 'map the "transpose" application for the GietVM' ) |
---|
91 | |
---|
92 | parser.add_option( '--sort', action = 'store_true', dest = 'sort', |
---|
93 | default = False, |
---|
94 | help = 'map the "sort" application for the GietVM' ) |
---|
95 | |
---|
96 | parser.add_option( '--convol', action = 'store_true', dest = 'convol', |
---|
97 | default = False, |
---|
98 | help = 'map the "convol" application for the GietVM' ) |
---|
99 | |
---|
100 | parser.add_option( '--router', action = 'store_true', dest = 'router', |
---|
101 | default = False, |
---|
102 | help = 'map the "router" application for the GietVM' ) |
---|
103 | |
---|
104 | parser.add_option( '--display', action = 'store_true', dest = 'display', |
---|
105 | default = False, |
---|
106 | help = 'map the "display" application for the GietVM' ) |
---|
107 | |
---|
108 | ###################################################################################### |
---|
109 | # Get command line arguments |
---|
110 | ###################################################################################### |
---|
111 | |
---|
112 | (options,args) = parser.parse_args() |
---|
113 | |
---|
114 | x_size = options.x_size # number of clusters in a row |
---|
115 | y_size = options.y_size # number of clusters in a column |
---|
116 | nprocs = options.nprocs # number of processors in a cluster |
---|
117 | fbf_size = options.fbf_size # frame buffer width & heigth |
---|
118 | |
---|
119 | verbose = options.verbose # report on map.bin generation if True |
---|
120 | |
---|
121 | netbsd_path = options.netbsd_path # path for netbsd.dts file |
---|
122 | linux_path = options.linux_path # path for linux.dts file |
---|
123 | almos_path = options.almos_path # path for arch.bib file |
---|
124 | giet_path = options.giet_path # path for map.bin & vsegs.ld files |
---|
125 | hard_path = options.hard_path # path for the hard_config.h file |
---|
126 | |
---|
127 | arch_path = options.arch_path # path to selected architecture |
---|
128 | |
---|
129 | xml_path = options.xml_path # path for map.xml file |
---|
130 | |
---|
131 | map_transpose = options.transpose # map "transpose" application if True |
---|
132 | map_sort = options.sort # map "sort" application if True |
---|
133 | map_convol = options.convol # map "convol" application if True |
---|
134 | map_router = options.router # map "convol" application if True |
---|
135 | map_display = options.display # map "convol" application if True |
---|
136 | |
---|
137 | ###################################################################################### |
---|
138 | # build empty platform (no applications yet) |
---|
139 | ###################################################################################### |
---|
140 | |
---|
141 | if ( arch_path == None ): |
---|
142 | print 'You must select a generic architecture on the command line' |
---|
143 | sys.exit(1) |
---|
144 | |
---|
145 | # dynamically append the architecture to PYTHON path (directory pathname) |
---|
146 | sys.path.append( arch_path ) |
---|
147 | |
---|
148 | # dynamically import the PYTHON mapping generator module (file name) |
---|
149 | select = __import__( 'arch' ) |
---|
150 | |
---|
151 | # build mapping calling the function (function name) |
---|
152 | mapping = select.arch( x_size, y_size, nprocs, fbf_size ) |
---|
153 | print '[genmap] platform %s build' % mapping.name |
---|
154 | |
---|
155 | ###################################################################################### |
---|
156 | # complete mapping with application(s) as required |
---|
157 | ###################################################################################### |
---|
158 | |
---|
159 | if ( map_transpose ): |
---|
160 | app = __import__( 'transpose' ) |
---|
161 | app.transpose( mapping ) |
---|
162 | print '[genmap] application "transpose" will be loaded' |
---|
163 | |
---|
164 | if ( map_sort ): |
---|
165 | app = __import__( 'sort' ) |
---|
166 | app.sort( mapping ) |
---|
167 | print '[genmap] application "sort" will be loaded' |
---|
168 | |
---|
169 | if ( map_convol ): |
---|
170 | app = __import__( 'convol' ) |
---|
171 | app.convol( mapping ) |
---|
172 | print '[genmap] application "convol" will be loaded' |
---|
173 | |
---|
174 | if ( map_router ): |
---|
175 | app = __import__( 'router' ) |
---|
176 | app.router( mapping ) |
---|
177 | print '[genmap] application "router" will be loaded' |
---|
178 | |
---|
179 | if ( map_display ): |
---|
180 | app = __import__( 'display' ) |
---|
181 | app.display( mapping ) |
---|
182 | print '[genmap] application "display" will be loaded' |
---|
183 | |
---|
184 | ###################################################################################### |
---|
185 | # Generate xml file if required. |
---|
186 | # It can be used for debug. |
---|
187 | ###################################################################################### |
---|
188 | |
---|
189 | if ( xml_path != None ): |
---|
190 | pathname = xml_path + '/map.xml' |
---|
191 | f = open ( pathname, 'w' ) |
---|
192 | f.write( mapping.xml() ) |
---|
193 | print '[genmap] %s generated for debug' % pathname |
---|
194 | |
---|
195 | ###################################################################################### |
---|
196 | # Generate netbsd.dts file if required. |
---|
197 | # It is used for NetBSD configuration. |
---|
198 | ###################################################################################### |
---|
199 | |
---|
200 | if ( (netbsd_path != None) and (arch_path != None) ): |
---|
201 | pathname = netbsd_path + '/netbsd.dts' |
---|
202 | f = open ( pathname, 'w' ) |
---|
203 | f.write( mapping.netbsd_dts() ) |
---|
204 | print '[genmap] %s generated' % pathname |
---|
205 | |
---|
206 | ###################################################################################### |
---|
207 | # Generate linux.dts file if required. |
---|
208 | # It is used for LINUX configuration. |
---|
209 | ###################################################################################### |
---|
210 | |
---|
211 | if ( (linux_path != None) and (arch_path != None) ): |
---|
212 | pathname = linux_path + '/linux.dts' |
---|
213 | f = open ( pathname, 'w' ) |
---|
214 | f.write( mapping.linux_dts() ) |
---|
215 | print '[genmap] %s generated' % pathname |
---|
216 | |
---|
217 | ###################################################################################### |
---|
218 | # Generate arch.bib file if required. |
---|
219 | # It is used for ALMOS configuration. |
---|
220 | ###################################################################################### |
---|
221 | |
---|
222 | if ( (almos_path != None) and (arch_path != None) ): |
---|
223 | pathname = almos_path + '/arch.info' |
---|
224 | f = open ( pathname, 'w' ) |
---|
225 | f.write( mapping.almos_arch() ) |
---|
226 | print '[genmap] %s generated for almos' % pathname |
---|
227 | |
---|
228 | ###################################################################################### |
---|
229 | # Generate map.bin, giet_vsegs.ld, and hard_config.h files if required. |
---|
230 | # They are used for GietVM compilation and configuration. |
---|
231 | ###################################################################################### |
---|
232 | |
---|
233 | if ( (giet_path != None) and (arch_path != None) ): |
---|
234 | |
---|
235 | pathname = giet_path + '/map.bin' |
---|
236 | f = open ( pathname, 'w' ) |
---|
237 | f.write( str( mapping.cbin( verbose ) ) ) |
---|
238 | print '[genmap] %s generated for giet_vm' % pathname |
---|
239 | |
---|
240 | pathname = giet_path + '/hard_config.h' |
---|
241 | f = open ( pathname, 'w' ) |
---|
242 | f.write( mapping.hard_config() ) |
---|
243 | print '[genmap] %s generated for giet_vm' % pathname |
---|
244 | |
---|
245 | pathname = giet_path + '/giet_vsegs.ld' |
---|
246 | f = open ( pathname, 'w' ) |
---|
247 | f.write( mapping.giet_vsegs() ) |
---|
248 | print '[genmap] %s generated for giet_vm' % pathname |
---|
249 | |
---|
250 | ###################################################################################### |
---|
251 | # Generate hard_config.h file if required. |
---|
252 | ###################################################################################### |
---|
253 | |
---|
254 | if ( hard_path != None ): |
---|
255 | |
---|
256 | pathname = hard_path + '/hard_config.h' |
---|
257 | f = open ( pathname, 'w' ) |
---|
258 | f.write( mapping.hard_config() ) |
---|
259 | print '[genmap] %s generated for %s' % (pathname, arch_path) |
---|
260 | |
---|