[319] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | ####################################################################################### |
---|
| 4 | # file : tsarmap |
---|
| 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) |
---|
| 36 | ####################################################################################### |
---|
| 37 | |
---|
| 38 | from optparse import OptionParser |
---|
| 39 | |
---|
| 40 | from mapping import * |
---|
| 41 | |
---|
| 42 | from transpose import * |
---|
| 43 | from sort 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 = 'nprocs', |
---|
| 65 | default = 2, |
---|
| 66 | help = 'define number of processors per cluster' ) |
---|
| 67 | |
---|
| 68 | parser.add_option( '--v', action = 'store_true', dest = 'verbose', |
---|
| 69 | default = False, |
---|
| 70 | help = 'display detailed report on map.bin file generation' ) |
---|
| 71 | |
---|
| 72 | parser.add_option( '--netbsd', type = 'string', dest = 'netbsd_path', |
---|
| 73 | help = 'define pathname for the netbsd.dts file' ) |
---|
| 74 | |
---|
| 75 | parser.add_option( '--almos', type = 'string', dest = 'almos_path', |
---|
| 76 | help = 'define pathname for the arch.bib file' ) |
---|
| 77 | |
---|
| 78 | parser.add_option( '--giet', type = 'string', dest = 'giet_path', |
---|
| 79 | help = 'define pathname for the map.bin & vsegs.ld file ' ) |
---|
| 80 | |
---|
| 81 | parser.add_option( '--xml', type = 'string', dest = 'xml_path', |
---|
| 82 | help = 'define pathname for the map.xml file' ) |
---|
| 83 | |
---|
| 84 | ############ supported applications ############################################### |
---|
| 85 | |
---|
| 86 | parser.add_option( '--transpose', action = 'store_true', dest = 'transpose', |
---|
| 87 | default = False, |
---|
| 88 | help = 'map the "transpose" application for the GIET' ) |
---|
| 89 | |
---|
| 90 | parser.add_option( '--sort', action = 'store_true', dest = 'sort', |
---|
| 91 | default = False, |
---|
| 92 | help = 'map the "sort" application for the GIET' ) |
---|
| 93 | |
---|
| 94 | ###################################################################################### |
---|
| 95 | # Get command line arguments |
---|
| 96 | ###################################################################################### |
---|
| 97 | |
---|
| 98 | (options,args) = parser.parse_args() |
---|
| 99 | |
---|
| 100 | x_size = options.x_size # number of clusters in a row |
---|
| 101 | y_size = options.y_size # number of clusters in a column |
---|
| 102 | nprocs = options.nprocs # number of processors in a cluster |
---|
| 103 | |
---|
| 104 | verbose = options.verbose # report on map.bin generation if True |
---|
| 105 | |
---|
| 106 | netbsd_path = options.netbsd_path # path for netbsd.dts file |
---|
| 107 | almos_path = options.almos_path # path for arch.bib file |
---|
| 108 | giet_path = options.giet_path # path for map.bin & vsegs.ld files |
---|
| 109 | |
---|
| 110 | arch_path = options.arch_path # path to selected architecture |
---|
| 111 | |
---|
| 112 | xml_path = options.xml_path # path for map.xml file |
---|
| 113 | |
---|
| 114 | map_transpose = options.transpose # map "sort" application if True |
---|
| 115 | map_sort = options.sort # map "transpose" application if True |
---|
| 116 | |
---|
| 117 | ###################################################################################### |
---|
| 118 | # build empty platform (no applications yet) |
---|
| 119 | ###################################################################################### |
---|
| 120 | |
---|
| 121 | if ( arch_path == None ): |
---|
| 122 | print 'You must select a generic architecture on the command line' |
---|
| 123 | sys.exit(1) |
---|
| 124 | |
---|
| 125 | # dynamically append the architecture to PYTHON path (directory pathname) |
---|
| 126 | sys.path.append( arch_path ) |
---|
| 127 | |
---|
| 128 | # dynamically import the PYTHON mapping generator module (file name) |
---|
| 129 | select = __import__( 'genmap' ) |
---|
| 130 | |
---|
| 131 | # build mapping calling the function (function name) |
---|
| 132 | mapping = select.genmap( x_size, y_size, nprocs ) |
---|
| 133 | print '[tsarmap] platform %s build' % mapping.name |
---|
| 134 | |
---|
| 135 | # generate the hard_confi.h file for top.cpp compilation |
---|
| 136 | pathname = arch_path + '/hard_config.h' |
---|
| 137 | f = open ( pathname, 'w' ) |
---|
| 138 | f.write( mapping.hard_config() ) |
---|
| 139 | print '[tsarmap] %s generated' % pathname |
---|
| 140 | |
---|
| 141 | ###################################################################################### |
---|
| 142 | # complete mapping with application(s) as required |
---|
| 143 | ###################################################################################### |
---|
| 144 | |
---|
| 145 | if ( map_transpose ): |
---|
| 146 | transpose( mapping ) |
---|
| 147 | print '[tsarmap] application "transpose" loaded' |
---|
| 148 | |
---|
| 149 | if ( map_sort ): |
---|
| 150 | sort( mapping ) |
---|
| 151 | print '[tsarmap] application "sort" loaded' |
---|
| 152 | |
---|
| 153 | ###################################################################################### |
---|
| 154 | # Generate xml file if required. |
---|
| 155 | # It can be used for debug. |
---|
| 156 | ###################################################################################### |
---|
| 157 | |
---|
| 158 | if ( xml_path != None ): |
---|
| 159 | pathname = xml_path + '/map.xml' |
---|
| 160 | f = open ( pathname, 'w' ) |
---|
| 161 | f.write( mapping.xml() ) |
---|
| 162 | print '[tsarmap] %s generated for debug' % pathname |
---|
| 163 | |
---|
| 164 | ###################################################################################### |
---|
| 165 | # Generate netbsd.dts file if required. |
---|
| 166 | # It is used for NetBSD configuration. |
---|
| 167 | ###################################################################################### |
---|
| 168 | |
---|
| 169 | if ( (netbsd_path != None) and (arch_path != None) ): |
---|
| 170 | pathname = netbsd_path + '/netbsd.dts' |
---|
| 171 | f = open ( pathname, 'w' ) |
---|
| 172 | f.write( mapping.netbsd_dts() ) |
---|
| 173 | print '[tsarmap] %s generated for netbsd' % pathname |
---|
| 174 | |
---|
| 175 | ###################################################################################### |
---|
| 176 | # Generate arch.bib file if required. |
---|
| 177 | # It is used for ALMOS configuration. |
---|
| 178 | ###################################################################################### |
---|
| 179 | |
---|
| 180 | if ( (almos_path != None) and (arch_path != None) ): |
---|
| 181 | pathname = almos_path + '/arch.info' |
---|
| 182 | f = open ( pathname, 'w' ) |
---|
| 183 | f.write( mapping.almos_arch() ) |
---|
| 184 | print '[tsarmap] %s generated for almos' % pathname |
---|
| 185 | |
---|
| 186 | ###################################################################################### |
---|
| 187 | # Generate map.bin, giet_vsegs.ld, and hard_config.h files if required. |
---|
| 188 | # They are used for GietVM compilation and configuration. |
---|
| 189 | ###################################################################################### |
---|
| 190 | |
---|
| 191 | if ( (giet_path != None) and (arch_path != None) ): |
---|
| 192 | |
---|
| 193 | pathname = giet_path + '/map.bin' |
---|
| 194 | f = open ( pathname, 'w' ) |
---|
| 195 | f.write( str( mapping.cbin( verbose ) ) ) |
---|
| 196 | print '[tsarmap] %s generated for giet_vm' % pathname |
---|
| 197 | |
---|
| 198 | pathname = giet_path + '/hard_config.h' |
---|
| 199 | f = open ( pathname, 'w' ) |
---|
| 200 | f.write( mapping.hard_config() ) |
---|
| 201 | print '[tsarmap] %s generated for giet_vm' % pathname |
---|
| 202 | |
---|
| 203 | pathname = giet_path + '/giet_vsegs.ld' |
---|
| 204 | f = open ( pathname, 'w' ) |
---|
| 205 | f.write( mapping.giet_vsegs() ) |
---|
| 206 | print '[tsarmap] %s generated for giet_vm' % pathname |
---|
| 207 | |
---|