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