[319] | 1 | #!/usr/bin/env python |
---|
| 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 | # |
---|
| 11 | # It generates the files required for hardware and software compilation: |
---|
| 12 | # |
---|
| 13 | # 1) The "hard_config.h" file is used to generate the top.cppnetbsd file (hardware), |
---|
| 14 | # and to compile the tsar_preloader.elf, the GietVM boot.elf and kernel.elf files. |
---|
| 15 | # |
---|
| 16 | # 2) The optionals "map.bin" and vsegs.ld" files are used to configure the GietVM. |
---|
| 17 | # |
---|
| 18 | # 3) The optional "netbsd.dts" file can be used to configure NetBSD. |
---|
| 19 | # |
---|
| 20 | # 4) The optional "arch.bib" file can be used to configure ALMOS. |
---|
| 21 | # |
---|
| 22 | # 5) An optional "map.xml" file can be generated for debug. |
---|
| 23 | ####################################################################################### |
---|
| 24 | # The hardware parameters are: |
---|
| 25 | # - x_size : number of clusters in a row |
---|
| 26 | # - y_size : number of clusters in a column |
---|
| 27 | # - nprocs : number of processors per cluster |
---|
| 28 | ####################################################################################### |
---|
| 29 | # The supported platforms are: |
---|
| 30 | # - tsar_generic_iob |
---|
| 31 | # - tsar_generic_leti |
---|
| 32 | ####################################################################################### |
---|
| 33 | # The supported parallel applications are: |
---|
| 34 | # - sort (one thread per processor) |
---|
| 35 | # - transpose (one thread per processor) |
---|
[328] | 36 | # - convol (one thread per processor) |
---|
[319] | 37 | ####################################################################################### |
---|
| 38 | |
---|
| 39 | from optparse import OptionParser |
---|
| 40 | |
---|
| 41 | from mapping import * |
---|
| 42 | |
---|
| 43 | from transpose import * |
---|
| 44 | from sort import * |
---|
[328] | 45 | from convol import * |
---|
[319] | 46 | |
---|
| 47 | import sys |
---|
| 48 | |
---|
| 49 | ###################################################################################### |
---|
| 50 | # define command line arguments |
---|
| 51 | ###################################################################################### |
---|
| 52 | |
---|
| 53 | parser = OptionParser() |
---|
| 54 | |
---|
| 55 | parser.add_option( '--arch', type = 'string', dest = 'arch_path', |
---|
| 56 | help = 'define pathname to architecture' ) |
---|
| 57 | |
---|
| 58 | parser.add_option( '--x', type = 'int', dest = 'x_size', |
---|
| 59 | default = 2, |
---|
| 60 | help = 'define number of clusters in a row' ) |
---|
| 61 | |
---|
| 62 | parser.add_option( '--y', type = 'int', dest = 'y_size', |
---|
| 63 | default = 2, |
---|
| 64 | help = 'define number of clusters in a column' ) |
---|
| 65 | |
---|
| 66 | parser.add_option( '--p', type = 'int', dest = 'nprocs', |
---|
| 67 | default = 2, |
---|
| 68 | help = 'define number of processors per cluster' ) |
---|
| 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( '--almos', type = 'string', dest = 'almos_path', |
---|
| 78 | help = 'define pathname for the arch.bib file' ) |
---|
| 79 | |
---|
| 80 | parser.add_option( '--giet', type = 'string', dest = 'giet_path', |
---|
| 81 | help = 'define pathname for the map.bin & vsegs.ld file ' ) |
---|
| 82 | |
---|
| 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 | |
---|
[328] | 96 | parser.add_option( '--convol', action = 'store_true', dest = 'filt', |
---|
| 97 | default = False, |
---|
| 98 | help = 'map the "convol" application for the GietVM' ) |
---|
| 99 | |
---|
[319] | 100 | ###################################################################################### |
---|
| 101 | # Get command line arguments |
---|
| 102 | ###################################################################################### |
---|
| 103 | |
---|
| 104 | (options,args) = parser.parse_args() |
---|
| 105 | |
---|
| 106 | x_size = options.x_size # number of clusters in a row |
---|
| 107 | y_size = options.y_size # number of clusters in a column |
---|
| 108 | nprocs = options.nprocs # number of processors in a cluster |
---|
| 109 | |
---|
| 110 | verbose = options.verbose # report on map.bin generation if True |
---|
| 111 | |
---|
| 112 | netbsd_path = options.netbsd_path # path for netbsd.dts file |
---|
| 113 | almos_path = options.almos_path # path for arch.bib file |
---|
| 114 | giet_path = options.giet_path # path for map.bin & vsegs.ld files |
---|
| 115 | |
---|
| 116 | arch_path = options.arch_path # path to selected architecture |
---|
| 117 | |
---|
| 118 | xml_path = options.xml_path # path for map.xml file |
---|
| 119 | |
---|
[328] | 120 | map_transpose = options.transpose # map "transpose" application if True |
---|
| 121 | map_sort = options.sort # map "sort" application if True |
---|
| 122 | map_convol = options.filt # map "convol" application if True |
---|
[319] | 123 | |
---|
| 124 | ###################################################################################### |
---|
| 125 | # build empty platform (no applications yet) |
---|
| 126 | ###################################################################################### |
---|
| 127 | |
---|
| 128 | if ( arch_path == None ): |
---|
| 129 | print 'You must select a generic architecture on the command line' |
---|
| 130 | sys.exit(1) |
---|
| 131 | |
---|
| 132 | # dynamically append the architecture to PYTHON path (directory pathname) |
---|
| 133 | sys.path.append( arch_path ) |
---|
| 134 | |
---|
| 135 | # dynamically import the PYTHON mapping generator module (file name) |
---|
| 136 | select = __import__( 'genmap' ) |
---|
| 137 | |
---|
| 138 | # build mapping calling the function (function name) |
---|
| 139 | mapping = select.genmap( x_size, y_size, nprocs ) |
---|
[328] | 140 | print '[genmap] platform %s build' % mapping.name |
---|
[319] | 141 | |
---|
| 142 | # generate the hard_confi.h file for top.cpp compilation |
---|
| 143 | pathname = arch_path + '/hard_config.h' |
---|
| 144 | f = open ( pathname, 'w' ) |
---|
| 145 | f.write( mapping.hard_config() ) |
---|
[328] | 146 | print '[genmap] %s generated' % pathname |
---|
[319] | 147 | |
---|
| 148 | ###################################################################################### |
---|
| 149 | # complete mapping with application(s) as required |
---|
| 150 | ###################################################################################### |
---|
| 151 | |
---|
| 152 | if ( map_transpose ): |
---|
| 153 | transpose( mapping ) |
---|
[328] | 154 | print '[genmap] application "transpose" loaded' |
---|
[319] | 155 | |
---|
| 156 | if ( map_sort ): |
---|
| 157 | sort( mapping ) |
---|
[328] | 158 | print '[genmap] application "sort" loaded' |
---|
[319] | 159 | |
---|
[328] | 160 | if ( map_convol ): |
---|
| 161 | convol( mapping ) |
---|
| 162 | print '[genmap] application "convol" loaded' |
---|
| 163 | |
---|
[319] | 164 | ###################################################################################### |
---|
| 165 | # Generate xml file if required. |
---|
| 166 | # It can be used for debug. |
---|
| 167 | ###################################################################################### |
---|
| 168 | |
---|
| 169 | if ( xml_path != None ): |
---|
| 170 | pathname = xml_path + '/map.xml' |
---|
| 171 | f = open ( pathname, 'w' ) |
---|
| 172 | f.write( mapping.xml() ) |
---|
[328] | 173 | print '[genmap] %s generated for debug' % pathname |
---|
[319] | 174 | |
---|
| 175 | ###################################################################################### |
---|
| 176 | # Generate netbsd.dts file if required. |
---|
| 177 | # It is used for NetBSD configuration. |
---|
| 178 | ###################################################################################### |
---|
| 179 | |
---|
| 180 | if ( (netbsd_path != None) and (arch_path != None) ): |
---|
| 181 | pathname = netbsd_path + '/netbsd.dts' |
---|
| 182 | f = open ( pathname, 'w' ) |
---|
| 183 | f.write( mapping.netbsd_dts() ) |
---|
[328] | 184 | print '[genmap] %s generated for netbsd' % pathname |
---|
[319] | 185 | |
---|
| 186 | ###################################################################################### |
---|
| 187 | # Generate arch.bib file if required. |
---|
| 188 | # It is used for ALMOS configuration. |
---|
| 189 | ###################################################################################### |
---|
| 190 | |
---|
| 191 | if ( (almos_path != None) and (arch_path != None) ): |
---|
| 192 | pathname = almos_path + '/arch.info' |
---|
| 193 | f = open ( pathname, 'w' ) |
---|
| 194 | f.write( mapping.almos_arch() ) |
---|
[328] | 195 | print '[genmap] %s generated for almos' % pathname |
---|
[319] | 196 | |
---|
| 197 | ###################################################################################### |
---|
| 198 | # Generate map.bin, giet_vsegs.ld, and hard_config.h files if required. |
---|
| 199 | # They are used for GietVM compilation and configuration. |
---|
| 200 | ###################################################################################### |
---|
| 201 | |
---|
| 202 | if ( (giet_path != None) and (arch_path != None) ): |
---|
| 203 | |
---|
| 204 | pathname = giet_path + '/map.bin' |
---|
| 205 | f = open ( pathname, 'w' ) |
---|
| 206 | f.write( str( mapping.cbin( verbose ) ) ) |
---|
[328] | 207 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 208 | |
---|
| 209 | pathname = giet_path + '/hard_config.h' |
---|
| 210 | f = open ( pathname, 'w' ) |
---|
| 211 | f.write( mapping.hard_config() ) |
---|
[328] | 212 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 213 | |
---|
| 214 | pathname = giet_path + '/giet_vsegs.ld' |
---|
| 215 | f = open ( pathname, 'w' ) |
---|
| 216 | f.write( mapping.giet_vsegs() ) |
---|
[328] | 217 | print '[genmap] %s generated for giet_vm' % pathname |
---|
[319] | 218 | |
---|