source: soft/giet_vm/giet_python/genmap @ 332

Last change on this file since 332 was 328, checked in by alain, 10 years ago

Introduce genmap tool in giet_python

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