[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 |
---|
| 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) |
---|
[328] | 31 | # - convol (one thread per processor) |
---|
[319] | 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 | |
---|
[411] | 60 | parser.add_option( '--fbf', type = 'int', dest = 'fbf_size', |
---|
| 61 | default = 128, |
---|
| 62 | help = 'define frame buffer width and heigth' ) |
---|
| 63 | |
---|
[319] | 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 | |
---|
[411] | 71 | parser.add_option( '--linux', type = 'string', dest = 'linux_path', |
---|
| 72 | help = 'define pathname for the linux.dts file' ) |
---|
| 73 | |
---|
[319] | 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 | |
---|
[401] | 80 | parser.add_option( '--hard', type = 'string', dest = 'hard_path', |
---|
| 81 | help = 'define pathname for the hard_config.h file ' ) |
---|
| 82 | |
---|
[319] | 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, |
---|
[328] | 90 | help = 'map the "transpose" application for the GietVM' ) |
---|
[319] | 91 | |
---|
| 92 | parser.add_option( '--sort', action = 'store_true', dest = 'sort', |
---|
| 93 | default = False, |
---|
[328] | 94 | help = 'map the "sort" application for the GietVM' ) |
---|
[319] | 95 | |
---|
[338] | 96 | parser.add_option( '--convol', action = 'store_true', dest = 'convol', |
---|
[328] | 97 | default = False, |
---|
| 98 | help = 'map the "convol" application for the GietVM' ) |
---|
| 99 | |
---|
[421] | 100 | parser.add_option( '--router', action = 'store_true', dest = 'router', |
---|
| 101 | default = False, |
---|
| 102 | help = 'map the "router" application for the GietVM' ) |
---|
| 103 | |
---|
[319] | 104 | ###################################################################################### |
---|
| 105 | # Get command line arguments |
---|
| 106 | ###################################################################################### |
---|
| 107 | |
---|
| 108 | (options,args) = parser.parse_args() |
---|
| 109 | |
---|
| 110 | x_size = options.x_size # number of clusters in a row |
---|
| 111 | y_size = options.y_size # number of clusters in a column |
---|
| 112 | nprocs = options.nprocs # number of processors in a cluster |
---|
[411] | 113 | fbf_size = options.fbf_size # frame buffer width & heigth |
---|
[319] | 114 | |
---|
| 115 | verbose = options.verbose # report on map.bin generation if True |
---|
| 116 | |
---|
| 117 | netbsd_path = options.netbsd_path # path for netbsd.dts file |
---|
[411] | 118 | linux_path = options.linux_path # path for linux.dts file |
---|
[319] | 119 | almos_path = options.almos_path # path for arch.bib file |
---|
| 120 | giet_path = options.giet_path # path for map.bin & vsegs.ld files |
---|
[401] | 121 | hard_path = options.hard_path # path for the hard_config.h file |
---|
[319] | 122 | |
---|
| 123 | arch_path = options.arch_path # path to selected architecture |
---|
| 124 | |
---|
| 125 | xml_path = options.xml_path # path for map.xml file |
---|
| 126 | |
---|
[328] | 127 | map_transpose = options.transpose # map "transpose" application if True |
---|
| 128 | map_sort = options.sort # map "sort" application if True |
---|
[338] | 129 | map_convol = options.convol # map "convol" application if True |
---|
[319] | 130 | |
---|
| 131 | ###################################################################################### |
---|
| 132 | # build empty platform (no applications yet) |
---|
| 133 | ###################################################################################### |
---|
| 134 | |
---|
| 135 | if ( arch_path == None ): |
---|
| 136 | print 'You must select a generic architecture on the command line' |
---|
| 137 | sys.exit(1) |
---|
| 138 | |
---|
| 139 | # dynamically append the architecture to PYTHON path (directory pathname) |
---|
| 140 | sys.path.append( arch_path ) |
---|
| 141 | |
---|
| 142 | # dynamically import the PYTHON mapping generator module (file name) |
---|
[338] | 143 | select = __import__( 'arch' ) |
---|
[319] | 144 | |
---|
| 145 | # build mapping calling the function (function name) |
---|
[411] | 146 | mapping = select.arch( x_size, y_size, nprocs, fbf_size ) |
---|
[328] | 147 | print '[genmap] platform %s build' % mapping.name |
---|
[319] | 148 | |
---|
| 149 | ###################################################################################### |
---|
| 150 | # complete mapping with application(s) as required |
---|
| 151 | ###################################################################################### |
---|
| 152 | |
---|
[401] | 153 | if ( map_transpose ): |
---|
| 154 | app = __import__( 'transpose' ) |
---|
| 155 | app.transpose( mapping ) |
---|
[328] | 156 | print '[genmap] application "transpose" loaded' |
---|
[319] | 157 | |
---|
| 158 | if ( map_sort ): |
---|
[401] | 159 | app = __import__( 'sort' ) |
---|
| 160 | app.sort( mapping ) |
---|
[328] | 161 | print '[genmap] application "sort" loaded' |
---|
[319] | 162 | |
---|
[328] | 163 | if ( map_convol ): |
---|
[401] | 164 | app = __import__( 'convol' ) |
---|
| 165 | app.convol( mapping ) |
---|
[328] | 166 | print '[genmap] application "convol" loaded' |
---|
| 167 | |
---|
[319] | 168 | ###################################################################################### |
---|
| 169 | # Generate xml file if required. |
---|
| 170 | # It can be used for debug. |
---|
| 171 | ###################################################################################### |
---|
| 172 | |
---|
| 173 | if ( xml_path != None ): |
---|
| 174 | pathname = xml_path + '/map.xml' |
---|
| 175 | f = open ( pathname, 'w' ) |
---|
| 176 | f.write( mapping.xml() ) |
---|
[328] | 177 | print '[genmap] %s generated for debug' % pathname |
---|
[319] | 178 | |
---|
| 179 | ###################################################################################### |
---|
| 180 | # Generate netbsd.dts file if required. |
---|
| 181 | # It is used for NetBSD configuration. |
---|
| 182 | ###################################################################################### |
---|
| 183 | |
---|
| 184 | if ( (netbsd_path != None) and (arch_path != None) ): |
---|
| 185 | pathname = netbsd_path + '/netbsd.dts' |
---|
| 186 | f = open ( pathname, 'w' ) |
---|
| 187 | f.write( mapping.netbsd_dts() ) |
---|
[411] | 188 | print '[genmap] %s generated' % pathname |
---|
[319] | 189 | |
---|
| 190 | ###################################################################################### |
---|
[411] | 191 | # Generate linux.dts file if required. |
---|
| 192 | # It is used for LINUX configuration. |
---|
| 193 | ###################################################################################### |
---|
| 194 | |
---|
| 195 | if ( (linux_path != None) and (arch_path != None) ): |
---|
| 196 | pathname = linux_path + '/linux.dts' |
---|
| 197 | f = open ( pathname, 'w' ) |
---|
| 198 | f.write( mapping.linux_dts() ) |
---|
| 199 | print '[genmap] %s generated' % pathname |
---|
| 200 | |
---|
| 201 | ###################################################################################### |
---|
[319] | 202 | # Generate arch.bib file if required. |
---|
| 203 | # It is used for ALMOS configuration. |
---|
| 204 | ###################################################################################### |
---|
| 205 | |
---|
| 206 | if ( (almos_path != None) and (arch_path != None) ): |
---|
| 207 | pathname = almos_path + '/arch.info' |
---|
| 208 | f = open ( pathname, 'w' ) |
---|
| 209 | f.write( mapping.almos_arch() ) |
---|
[328] | 210 | print '[genmap] %s generated for almos' % pathname |
---|
[319] | 211 | |
---|
| 212 | ###################################################################################### |
---|
| 213 | # Generate map.bin, giet_vsegs.ld, and hard_config.h files if required. |
---|
| 214 | # They are used for GietVM compilation and configuration. |
---|
| 215 | ###################################################################################### |
---|
| 216 | |
---|
| 217 | if ( (giet_path != None) and (arch_path != None) ): |
---|
| 218 | |
---|
| 219 | pathname = giet_path + '/map.bin' |
---|
| 220 | f = open ( pathname, 'w' ) |
---|
| 221 | f.write( str( mapping.cbin( verbose ) ) ) |
---|
[328] | 222 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 223 | |
---|
| 224 | pathname = giet_path + '/hard_config.h' |
---|
| 225 | f = open ( pathname, 'w' ) |
---|
| 226 | f.write( mapping.hard_config() ) |
---|
[328] | 227 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 228 | |
---|
| 229 | pathname = giet_path + '/giet_vsegs.ld' |
---|
| 230 | f = open ( pathname, 'w' ) |
---|
| 231 | f.write( mapping.giet_vsegs() ) |
---|
[328] | 232 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 233 | |
---|
[401] | 234 | ###################################################################################### |
---|
| 235 | # Generate hard_config.h file if required. |
---|
| 236 | ###################################################################################### |
---|
| 237 | |
---|
| 238 | if ( hard_path != None ): |
---|
| 239 | |
---|
| 240 | pathname = hard_path + '/hard_config.h' |
---|
| 241 | f = open ( pathname, 'w' ) |
---|
| 242 | f.write( mapping.hard_config() ) |
---|
| 243 | print '[genmap] %s generated for %s' % (pathname, arch_path) |
---|
| 244 | |
---|