source: soft/giet_vm/giet_python/genmap @ 406

Last change on this file since 406 was 401, checked in by cfuguet, 10 years ago

genmap: importing dynamically the applications module

  • Adding option in the genmap script to only generate the hard_config.h file.
  • Importing dynamically the applications module to avoid errors when these modules are not needed and then not defined.
  • Property svn:executable set to *
File size: 9.1 KB
RevLine 
[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# 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 "arch.bib" file can be used to configure ALMOS.
16# 5) An optional "map.xml" file can be generated for debug.
17#######################################################################################
18# The hardware parameters  are:
19#  - x_size    : number of clusters in a row
20#  - y_size    : number of clusters in a column
21#  - nprocs    : number of processors per cluster
22#######################################################################################
23# The supported platforms are:
24# - tsar_generic_iob
25# - tsar_generic_leti
26#######################################################################################
27# The supported parallel applications are:
28# - sort (one thread per processor)
29# - transpose (one thread per processor)
[328]30# - convol (one thread per processor)
[319]31#######################################################################################
32
33from optparse import OptionParser
34from mapping import *
35
36import sys
37
38######################################################################################
39#   define command line arguments   
40######################################################################################
41
42parser = OptionParser()
43
44parser.add_option( '--arch', type = 'string', dest = 'arch_path',
45                   help = 'define pathname to architecture' )
46
47parser.add_option( '--x', type = 'int', dest = 'x_size', 
48                   default = 2,
49                   help = 'define number of clusters in a row' )
50
51parser.add_option( '--y', type = 'int', dest = 'y_size', 
52                   default = 2,
53                   help = 'define number of clusters in a column' )
54
55parser.add_option( '--p', type = 'int', dest = 'nprocs', 
56                   default = 2,
57                   help = 'define number of processors per cluster' )
58
59parser.add_option( '--v', action = 'store_true', dest = 'verbose',
60                   default = False,
61                   help = 'display detailed report on map.bin file generation' )
62
63parser.add_option( '--netbsd', type = 'string', dest = 'netbsd_path', 
64                   help = 'define pathname for the netbsd.dts file' )
65
66parser.add_option( '--almos', type = 'string', dest = 'almos_path', 
67                   help = 'define pathname for the arch.bib file' )
68
69parser.add_option( '--giet', type = 'string', dest = 'giet_path', 
70                   help = 'define pathname for the map.bin & vsegs.ld file ' )
71
[401]72parser.add_option( '--hard', type = 'string', dest = 'hard_path',
73                   help = 'define pathname for the hard_config.h file ' )
74
[319]75parser.add_option( '--xml', type = 'string', dest = 'xml_path', 
76                   help = 'define pathname for the map.xml file' )
77
78############  supported applications   ###############################################
79
80parser.add_option( '--transpose', action = 'store_true', dest = 'transpose',
81                   default = False,
[328]82                   help = 'map the "transpose" application for the GietVM' )
[319]83
84parser.add_option( '--sort', action = 'store_true', dest = 'sort',     
85                   default = False,
[328]86                   help = 'map the "sort" application for the GietVM' )
[319]87
[338]88parser.add_option( '--convol', action = 'store_true', dest = 'convol',     
[328]89                   default = False,
90                   help = 'map the "convol" application for the GietVM' )
91
[319]92######################################################################################
93#   Get command line arguments
94######################################################################################
95
96(options,args) = parser.parse_args()
97
98x_size        = options.x_size      # number of clusters in a row
99y_size        = options.y_size      # number of clusters in a column
100nprocs        = options.nprocs      # number of processors in a cluster
101
102verbose       = options.verbose     # report on map.bin generation if True
103
104netbsd_path   = options.netbsd_path # path for netbsd.dts file
105almos_path    = options.almos_path  # path for arch.bib file
106giet_path     = options.giet_path   # path for map.bin & vsegs.ld files
[401]107hard_path     = options.hard_path   # path for the hard_config.h file
[319]108
109arch_path     = options.arch_path   # path to selected architecture
110
111xml_path      = options.xml_path    # path for map.xml file     
112
[328]113map_transpose = options.transpose   # map "transpose" application if True
114map_sort      = options.sort        # map "sort" application if True
[338]115map_convol    = options.convol      # map "convol" application if True
[319]116
117######################################################################################
118#   build empty platform (no applications yet)
119######################################################################################
120
121if   ( 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)
126sys.path.append( arch_path )
127
128# dynamically import the PYTHON mapping generator module (file name)
[338]129select = __import__( 'arch' )
[319]130
131# build mapping calling the function (function name)
[338]132mapping = select.arch( x_size, y_size, nprocs )
[328]133print '[genmap] platform %s build' % mapping.name
[319]134
135######################################################################################
136#   complete mapping with application(s) as required
137######################################################################################
138
[401]139if ( map_transpose ):
140    app = __import__( 'transpose' )
141    app.transpose( mapping )
[328]142    print '[genmap] application "transpose" loaded'
[319]143
144if ( map_sort ):     
[401]145    app = __import__( 'sort' )
146    app.sort( mapping )
[328]147    print '[genmap] application "sort" loaded'
[319]148
[328]149if ( map_convol ):     
[401]150    app = __import__( 'convol' )
151    app.convol( mapping )
[328]152    print '[genmap] application "convol" loaded'
153
[319]154######################################################################################
155#   Generate xml file if required.
156#   It can be used for debug.
157######################################################################################
158
159if ( xml_path != None ):
160    pathname = xml_path + '/map.xml'
161    f = open ( pathname, 'w' )
162    f.write( mapping.xml() )
[328]163    print '[genmap] %s generated for debug' % pathname
[319]164
165######################################################################################
166#   Generate netbsd.dts file if required.
167#   It is used for NetBSD configuration.
168######################################################################################
169
170if ( (netbsd_path != None) and (arch_path != None) ):
171    pathname = netbsd_path + '/netbsd.dts'
172    f = open ( pathname, 'w' )
173    f.write( mapping.netbsd_dts() )
[328]174    print '[genmap] %s generated for netbsd' % pathname
[319]175
176######################################################################################
177#   Generate arch.bib file if required.
178#   It is used for ALMOS configuration.
179######################################################################################
180
181if ( (almos_path != None) and (arch_path != None) ):
182    pathname = almos_path + '/arch.info'
183    f = open ( pathname, 'w' )
184    f.write( mapping.almos_arch() )
[328]185    print '[genmap] %s generated for almos' % pathname
[319]186
187######################################################################################
188#   Generate map.bin, giet_vsegs.ld, and hard_config.h files if required.
189#   They are used for GietVM compilation and configuration.
190######################################################################################
191
192if ( (giet_path != None) and (arch_path != None) ):
193
194    pathname = giet_path + '/map.bin'
195    f = open ( pathname, 'w' )
196    f.write( str( mapping.cbin( verbose ) ) )
[328]197    print '[genmap] %s generated for giet_vm' % pathname
[319]198
199    pathname = giet_path + '/hard_config.h'
200    f = open ( pathname, 'w' )
201    f.write( mapping.hard_config() )
[328]202    print '[genmap] %s generated for giet_vm' % pathname
[319]203
204    pathname = giet_path + '/giet_vsegs.ld'
205    f = open ( pathname, 'w' )
206    f.write( mapping.giet_vsegs() )
[328]207    print '[genmap] %s generated for giet_vm' % pathname
[319]208
[401]209######################################################################################
210#   Generate hard_config.h file if required.
211######################################################################################
212
213if ( hard_path != None ):
214
215    pathname = hard_path + '/hard_config.h'
216    f = open ( pathname, 'w' )
217    f.write( mapping.hard_config() )
218    print '[genmap] %s generated for %s' % (pathname, arch_path)
219
Note: See TracBrowser for help on using the repository browser.