[425] | 1 | #!/usr/bin/env python |
---|
[319] | 2 | |
---|
[539] | 3 | ################################################################################### |
---|
[328] | 4 | # file : genmap |
---|
[319] | 5 | # date : april 2014 |
---|
| 6 | # author : Alain Greiner |
---|
[539] | 7 | ################################################################################### |
---|
[520] | 8 | # This generic script maps one or several applications on a specific |
---|
[319] | 9 | # instance of the multi-processors/multi-clusters TSAR architecture. |
---|
| 10 | # It generates the files required for hardware and software compilation: |
---|
[520] | 11 | # 1) The "hard_config.h" file is used to generate the top.cpp file (hardware), |
---|
[539] | 12 | # and to compile the tsar_preloader.elf, GietVM boot.elf and kernel.elf files. |
---|
[319] | 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. |
---|
[411] | 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. |
---|
[539] | 18 | ################################################################################### |
---|
[319] | 19 | # The hardware parameters are: |
---|
| 20 | # - x_size : number of clusters in a row |
---|
| 21 | # - y_size : number of clusters in a column |
---|
[453] | 22 | # - nb_procs : number of processors per cluster |
---|
| 23 | # - nb_ttys : number of TTY channels |
---|
| 24 | # - fbf_size : frame buffer width & heigth |
---|
[539] | 25 | ################################################################################### |
---|
[319] | 26 | # The supported platforms are: |
---|
| 27 | # - tsar_generic_iob |
---|
| 28 | # - tsar_generic_leti |
---|
[520] | 29 | # - tsar_geberic_mwmr |
---|
[539] | 30 | ################################################################################### |
---|
[462] | 31 | # The supported applications are: |
---|
| 32 | # - sort |
---|
| 33 | # - transpose |
---|
| 34 | # - convol |
---|
| 35 | # - router |
---|
| 36 | # - classif |
---|
| 37 | # - display |
---|
[500] | 38 | # - gameoflife |
---|
[520] | 39 | # - coproc |
---|
[539] | 40 | ################################################################################### |
---|
[319] | 41 | |
---|
| 42 | from optparse import OptionParser |
---|
| 43 | from mapping import * |
---|
| 44 | |
---|
| 45 | import sys |
---|
| 46 | |
---|
[539] | 47 | ################################################################################### |
---|
[319] | 48 | # define command line arguments |
---|
[539] | 49 | ################################################################################### |
---|
[319] | 50 | |
---|
| 51 | parser = OptionParser() |
---|
| 52 | |
---|
| 53 | parser.add_option( '--arch', type = 'string', dest = 'arch_path', |
---|
| 54 | help = 'define pathname to architecture' ) |
---|
| 55 | |
---|
| 56 | parser.add_option( '--x', type = 'int', dest = 'x_size', |
---|
| 57 | default = 2, |
---|
| 58 | help = 'define number of clusters in a row' ) |
---|
| 59 | |
---|
| 60 | parser.add_option( '--y', type = 'int', dest = 'y_size', |
---|
| 61 | default = 2, |
---|
| 62 | help = 'define number of clusters in a column' ) |
---|
| 63 | |
---|
[453] | 64 | parser.add_option( '--p', type = 'int', dest = 'nb_procs', |
---|
[319] | 65 | default = 2, |
---|
| 66 | help = 'define number of processors per cluster' ) |
---|
| 67 | |
---|
[453] | 68 | parser.add_option( '--tty', type = 'int', dest = 'nb_ttys', |
---|
| 69 | default = 1, |
---|
| 70 | help = 'define number of tty channels' ) |
---|
| 71 | |
---|
[411] | 72 | parser.add_option( '--fbf', type = 'int', dest = 'fbf_size', |
---|
| 73 | default = 128, |
---|
| 74 | help = 'define frame buffer width and heigth' ) |
---|
| 75 | |
---|
[319] | 76 | parser.add_option( '--v', action = 'store_true', dest = 'verbose', |
---|
| 77 | default = False, |
---|
| 78 | help = 'display detailed report on map.bin file generation' ) |
---|
| 79 | |
---|
| 80 | parser.add_option( '--netbsd', type = 'string', dest = 'netbsd_path', |
---|
| 81 | help = 'define pathname for the netbsd.dts file' ) |
---|
| 82 | |
---|
[411] | 83 | parser.add_option( '--linux', type = 'string', dest = 'linux_path', |
---|
| 84 | help = 'define pathname for the linux.dts file' ) |
---|
| 85 | |
---|
[319] | 86 | parser.add_option( '--almos', type = 'string', dest = 'almos_path', |
---|
| 87 | help = 'define pathname for the arch.bib file' ) |
---|
| 88 | |
---|
| 89 | parser.add_option( '--giet', type = 'string', dest = 'giet_path', |
---|
| 90 | help = 'define pathname for the map.bin & vsegs.ld file ' ) |
---|
| 91 | |
---|
[401] | 92 | parser.add_option( '--hard', type = 'string', dest = 'hard_path', |
---|
| 93 | help = 'define pathname for the hard_config.h file ' ) |
---|
| 94 | |
---|
[319] | 95 | parser.add_option( '--xml', type = 'string', dest = 'xml_path', |
---|
| 96 | help = 'define pathname for the map.xml file' ) |
---|
| 97 | |
---|
[539] | 98 | ############ supported applications ############################################ |
---|
[319] | 99 | |
---|
| 100 | parser.add_option( '--transpose', action = 'store_true', dest = 'transpose', |
---|
| 101 | default = False, |
---|
[328] | 102 | help = 'map the "transpose" application for the GietVM' ) |
---|
[319] | 103 | |
---|
| 104 | parser.add_option( '--sort', action = 'store_true', dest = 'sort', |
---|
| 105 | default = False, |
---|
[328] | 106 | help = 'map the "sort" application for the GietVM' ) |
---|
[319] | 107 | |
---|
[338] | 108 | parser.add_option( '--convol', action = 'store_true', dest = 'convol', |
---|
[328] | 109 | default = False, |
---|
| 110 | help = 'map the "convol" application for the GietVM' ) |
---|
| 111 | |
---|
[421] | 112 | parser.add_option( '--router', action = 'store_true', dest = 'router', |
---|
| 113 | default = False, |
---|
| 114 | help = 'map the "router" application for the GietVM' ) |
---|
| 115 | |
---|
[441] | 116 | parser.add_option( '--display', action = 'store_true', dest = 'display', |
---|
| 117 | default = False, |
---|
| 118 | help = 'map the "display" application for the GietVM' ) |
---|
| 119 | |
---|
[462] | 120 | parser.add_option( '--classif', action = 'store_true', dest = 'classif', |
---|
| 121 | default = False, |
---|
| 122 | help = 'map the "classif" application for the GietVM' ) |
---|
| 123 | |
---|
[500] | 124 | parser.add_option( '--gameoflife', action = 'store_true', dest = 'gameoflife', |
---|
| 125 | default = False, |
---|
| 126 | help = 'map the "gameoflife" application for the GietVM' ) |
---|
| 127 | |
---|
[520] | 128 | parser.add_option( '--coproc', action = 'store_true', dest = 'coproc', |
---|
| 129 | default = False, |
---|
| 130 | help = 'map the "coproc" application for the GietVM' ) |
---|
| 131 | |
---|
[539] | 132 | ################################################################################### |
---|
[319] | 133 | # Get command line arguments |
---|
[539] | 134 | ################################################################################### |
---|
[319] | 135 | |
---|
| 136 | (options,args) = parser.parse_args() |
---|
| 137 | |
---|
[500] | 138 | x_size = options.x_size # number of clusters in a row |
---|
| 139 | y_size = options.y_size # number of clusters in a column |
---|
| 140 | nb_procs = options.nb_procs # number of processors in a cluster |
---|
| 141 | nb_ttys = options.nb_ttys # number of TTY channels |
---|
| 142 | fbf_size = options.fbf_size # frame buffer width & heigth |
---|
[319] | 143 | |
---|
[500] | 144 | verbose = options.verbose # report on map.bin generation if True |
---|
[319] | 145 | |
---|
[500] | 146 | netbsd_path = options.netbsd_path # path for netbsd.dts file |
---|
| 147 | linux_path = options.linux_path # path for linux.dts file |
---|
| 148 | almos_path = options.almos_path # path for arch.bib file |
---|
| 149 | giet_path = options.giet_path # path for map.bin & vsegs.ld files |
---|
| 150 | hard_path = options.hard_path # path for the hard_config.h file |
---|
[319] | 151 | |
---|
[500] | 152 | arch_path = options.arch_path # path to selected architecture |
---|
[319] | 153 | |
---|
[500] | 154 | xml_path = options.xml_path # path for map.xml file |
---|
[319] | 155 | |
---|
[500] | 156 | map_transpose = options.transpose # map "transpose" application if True |
---|
| 157 | map_sort = options.sort # map "sort" application if True |
---|
| 158 | map_convol = options.convol # map "convol" application if True |
---|
| 159 | map_router = options.router # map "router" application if True |
---|
| 160 | map_display = options.display # map "display" application if True |
---|
| 161 | map_classif = options.classif # map "classif" application if True |
---|
| 162 | map_gameoflife = options.gameoflife # map "gameoflife" application if True |
---|
[520] | 163 | map_coproc = options.coproc # map "coproc" application if True |
---|
[319] | 164 | |
---|
[539] | 165 | ################################################################################### |
---|
[319] | 166 | # build empty platform (no applications yet) |
---|
[539] | 167 | ################################################################################### |
---|
[319] | 168 | |
---|
| 169 | if ( arch_path == None ): |
---|
| 170 | print 'You must select a generic architecture on the command line' |
---|
| 171 | sys.exit(1) |
---|
| 172 | |
---|
| 173 | # dynamically append the architecture to PYTHON path (directory pathname) |
---|
| 174 | sys.path.append( arch_path ) |
---|
| 175 | |
---|
| 176 | # dynamically import the PYTHON mapping generator module (file name) |
---|
[338] | 177 | select = __import__( 'arch' ) |
---|
[319] | 178 | |
---|
| 179 | # build mapping calling the function (function name) |
---|
[453] | 180 | mapping = select.arch( x_size, y_size, nb_procs, nb_ttys, fbf_size ) |
---|
[328] | 181 | print '[genmap] platform %s build' % mapping.name |
---|
[319] | 182 | |
---|
[539] | 183 | ################################################################################### |
---|
[319] | 184 | # complete mapping with application(s) as required |
---|
[539] | 185 | ################################################################################### |
---|
[319] | 186 | |
---|
[401] | 187 | if ( map_transpose ): |
---|
| 188 | app = __import__( 'transpose' ) |
---|
| 189 | app.transpose( mapping ) |
---|
[441] | 190 | print '[genmap] application "transpose" will be loaded' |
---|
[319] | 191 | |
---|
| 192 | if ( map_sort ): |
---|
[401] | 193 | app = __import__( 'sort' ) |
---|
| 194 | app.sort( mapping ) |
---|
[441] | 195 | print '[genmap] application "sort" will be loaded' |
---|
[319] | 196 | |
---|
[328] | 197 | if ( map_convol ): |
---|
[401] | 198 | app = __import__( 'convol' ) |
---|
| 199 | app.convol( mapping ) |
---|
[441] | 200 | print '[genmap] application "convol" will be loaded' |
---|
[328] | 201 | |
---|
[432] | 202 | if ( map_router ): |
---|
| 203 | app = __import__( 'router' ) |
---|
| 204 | app.router( mapping ) |
---|
[441] | 205 | print '[genmap] application "router" will be loaded' |
---|
[432] | 206 | |
---|
[441] | 207 | if ( map_display ): |
---|
| 208 | app = __import__( 'display' ) |
---|
| 209 | app.display( mapping ) |
---|
| 210 | print '[genmap] application "display" will be loaded' |
---|
| 211 | |
---|
[462] | 212 | if ( map_classif ): |
---|
| 213 | app = __import__( 'classif' ) |
---|
| 214 | app.classif( mapping ) |
---|
| 215 | print '[genmap] application "classif" will be loaded' |
---|
| 216 | |
---|
[500] | 217 | if ( map_gameoflife ): |
---|
| 218 | app = __import__( 'gameoflife' ) |
---|
| 219 | app.gameoflife( mapping ) |
---|
| 220 | print '[genmap] application "gameoflife" will be loaded' |
---|
| 221 | |
---|
[520] | 222 | if ( map_coproc ): |
---|
| 223 | app = __import__( 'coproc' ) |
---|
| 224 | app.coproc( mapping ) |
---|
| 225 | print '[genmap] application "coproc" will be loaded' |
---|
| 226 | |
---|
[539] | 227 | ################################################################################### |
---|
[319] | 228 | # Generate xml file if required. |
---|
| 229 | # It can be used for debug. |
---|
[539] | 230 | ################################################################################### |
---|
[319] | 231 | |
---|
| 232 | if ( xml_path != None ): |
---|
| 233 | pathname = xml_path + '/map.xml' |
---|
| 234 | f = open ( pathname, 'w' ) |
---|
| 235 | f.write( mapping.xml() ) |
---|
[328] | 236 | print '[genmap] %s generated for debug' % pathname |
---|
[319] | 237 | |
---|
[539] | 238 | ################################################################################### |
---|
[319] | 239 | # Generate netbsd.dts file if required. |
---|
| 240 | # It is used for NetBSD configuration. |
---|
[539] | 241 | ################################################################################### |
---|
[319] | 242 | |
---|
| 243 | if ( (netbsd_path != None) and (arch_path != None) ): |
---|
| 244 | pathname = netbsd_path + '/netbsd.dts' |
---|
| 245 | f = open ( pathname, 'w' ) |
---|
| 246 | f.write( mapping.netbsd_dts() ) |
---|
[411] | 247 | print '[genmap] %s generated' % pathname |
---|
[319] | 248 | |
---|
[539] | 249 | ################################################################################### |
---|
[411] | 250 | # Generate linux.dts file if required. |
---|
| 251 | # It is used for LINUX configuration. |
---|
[539] | 252 | ################################################################################### |
---|
[411] | 253 | |
---|
| 254 | if ( (linux_path != None) and (arch_path != None) ): |
---|
| 255 | pathname = linux_path + '/linux.dts' |
---|
| 256 | f = open ( pathname, 'w' ) |
---|
| 257 | f.write( mapping.linux_dts() ) |
---|
| 258 | print '[genmap] %s generated' % pathname |
---|
| 259 | |
---|
[539] | 260 | ################################################################################### |
---|
[319] | 261 | # Generate arch.bib file if required. |
---|
| 262 | # It is used for ALMOS configuration. |
---|
[539] | 263 | ################################################################################### |
---|
[319] | 264 | |
---|
| 265 | if ( (almos_path != None) and (arch_path != None) ): |
---|
| 266 | pathname = almos_path + '/arch.info' |
---|
| 267 | f = open ( pathname, 'w' ) |
---|
| 268 | f.write( mapping.almos_arch() ) |
---|
[328] | 269 | print '[genmap] %s generated for almos' % pathname |
---|
[319] | 270 | |
---|
[539] | 271 | ################################################################################### |
---|
[319] | 272 | # Generate map.bin, giet_vsegs.ld, and hard_config.h files if required. |
---|
| 273 | # They are used for GietVM compilation and configuration. |
---|
[539] | 274 | ################################################################################### |
---|
[319] | 275 | |
---|
| 276 | if ( (giet_path != None) and (arch_path != None) ): |
---|
| 277 | |
---|
| 278 | pathname = giet_path + '/map.bin' |
---|
| 279 | f = open ( pathname, 'w' ) |
---|
| 280 | f.write( str( mapping.cbin( verbose ) ) ) |
---|
[328] | 281 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 282 | |
---|
| 283 | pathname = giet_path + '/hard_config.h' |
---|
| 284 | f = open ( pathname, 'w' ) |
---|
| 285 | f.write( mapping.hard_config() ) |
---|
[328] | 286 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 287 | |
---|
| 288 | pathname = giet_path + '/giet_vsegs.ld' |
---|
| 289 | f = open ( pathname, 'w' ) |
---|
| 290 | f.write( mapping.giet_vsegs() ) |
---|
[328] | 291 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 292 | |
---|
[539] | 293 | ################################################################################### |
---|
[401] | 294 | # Generate hard_config.h file if required. |
---|
[539] | 295 | ################################################################################### |
---|
[401] | 296 | |
---|
| 297 | if ( hard_path != None ): |
---|
| 298 | |
---|
| 299 | pathname = hard_path + '/hard_config.h' |
---|
| 300 | f = open ( pathname, 'w' ) |
---|
| 301 | f.write( mapping.hard_config() ) |
---|
| 302 | print '[genmap] %s generated for %s' % (pathname, arch_path) |
---|
| 303 | |
---|