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