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