Skip to content

Commit 532c23e

Browse files
committed
vtr_flow: added script to add tiles to architecture xml
I have also changes travis.yml to install the lxml python package needed by the script Signed-off-by: Alessandro Comodi <[email protected]>
1 parent ecf64f3 commit 532c23e

File tree

3 files changed

+146
-2
lines changed

3 files changed

+146
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ addons:
3636
- libxml++2.6-dev
3737
- perl
3838
- python
39+
- python-lxml
3940
- texinfo
4041
- time
4142
- valgrind

vtr_flow/scripts/add_tiles.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
This script is intended to modify the architecture description file to be compliant with
5+
the new format.
6+
7+
It moves the top level pb_types attributes and tags to the tiles high-level tag.
8+
9+
BEFORE:
10+
<complexblocklist>
11+
<pb_type name="BRAM" area="2" height="4" width="1" capacity="1">
12+
<input ... />
13+
<input ... />
14+
<input ... />
15+
<output ... />
16+
<output ... />
17+
<output ... />
18+
<interconnect ... />
19+
<fc ... />
20+
<pinlocations ... />
21+
<switchblock_locations ... />
22+
</pb_type>
23+
</complexblocklist>
24+
25+
AFTER:
26+
<tiles>
27+
<tile name="BRAM" area="2" height="4" width="1" capacity="1">
28+
<interconnect ... />
29+
<fc ... />
30+
<pinlocations ... />
31+
<switchblock_locations ... />
32+
</tile>
33+
</tiles>
34+
<complexblocklist
35+
<pb_type name="BRAM">
36+
<input ... />
37+
<input ... />
38+
<input ... />
39+
<output ... />
40+
<output ... />
41+
<output ... />
42+
</pb_type>
43+
</complexblocklist>
44+
"""
45+
46+
"""
47+
This script is intended to modify the architecture description file to be compliant with
48+
the new format.
49+
50+
It moves the top level pb_types attributes and tags to the tiles high-level tag.
51+
52+
BEFORE:
53+
<complexblocklist>
54+
<pb_type name="BRAM" area="2" height="4" width="1" capacity="1">
55+
<input ... />
56+
<input ... />
57+
<input ... />
58+
<output ... />
59+
<output ... />
60+
<output ... />
61+
<interconnect ... />
62+
<fc ... />
63+
<pinlocations ... />
64+
<switchblock_locations ... />
65+
</pb_type>
66+
</complexblocklist>
67+
68+
AFTER:
69+
<tiles>
70+
<tile name="BRAM" area="2" height="4" width="1" capacity="1">
71+
<interconnect ... />
72+
<fc ... />
73+
<pinlocations ... />
74+
<switchblock_locations ... />
75+
</tile>
76+
</tiles>
77+
<complexblocklist
78+
<pb_type name="BRAM">
79+
<input ... />
80+
<input ... />
81+
<input ... />
82+
<output ... />
83+
<output ... />
84+
<output ... />
85+
</pb_type>
86+
</complexblocklist>
87+
"""
88+
89+
from lxml import etree as ET
90+
import argparse
91+
92+
TAGS_TO_SWAP = ['fc', 'pinlocations', 'switchblock_locations']
93+
ATTR_TO_REMOVE = ['area', 'height', 'width', 'capacity']
94+
95+
def swap_tags(tile, pb_type):
96+
# Moving tags from top level pb_type to tile
97+
for child in pb_type:
98+
if child.tag in TAGS_TO_SWAP:
99+
pb_type.remove(child)
100+
tile.append(child)
101+
102+
103+
def main():
104+
parser = argparse.ArgumentParser(
105+
description="Moves top level pb_types to tiles tag."
106+
)
107+
parser.add_argument(
108+
'--arch_xml',
109+
required=True,
110+
help="Input arch.xml that needs to be modified to move the top level pb_types to the `tiles` tag."
111+
)
112+
113+
args = parser.parse_args()
114+
115+
arch_xml = ET.ElementTree()
116+
root_element = arch_xml.parse(args.arch_xml)
117+
118+
tiles = ET.SubElement(root_element, 'tiles')
119+
120+
top_pb_types = []
121+
for pb_type in root_element.iter('pb_type'):
122+
if pb_type.getparent().tag == 'complexblocklist':
123+
top_pb_types.append(pb_type)
124+
125+
for pb_type in top_pb_types:
126+
tile = ET.SubElement(tiles, 'tile')
127+
attrs = pb_type.attrib
128+
129+
for attr in attrs:
130+
tile.set(attr, pb_type.get(attr))
131+
132+
# Remove attributes of top level pb_types only
133+
for attr in ATTR_TO_REMOVE:
134+
pb_type.attrib.pop(attr, None)
135+
136+
swap_tags(tile, pb_type)
137+
138+
print(ET.tostring(arch_xml, pretty_print=True).decode('utf-8'))
139+
140+
141+
if __name__ == '__main__':
142+
main()

vtr_flow/scripts/run_vtr_flow.pl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363

364364
# Read arch XML
365365
my $tpp = XML::TreePP->new();
366-
my $xml_tree = $tpp->parsefile($architecture_file_path);
366+
my $xml_tree = $tpp->parsefile("$architecture_file_path");
367367

368368
# Get lut size if undefined
369369
if (!defined $lut_size) {
@@ -416,7 +416,8 @@
416416
#system "cp $odin2_base_config"
417417

418418
my $architecture_file_path_new = "$temp_dir$architecture_file_name";
419-
copy( $architecture_file_path, $architecture_file_path_new );
419+
my $ret = `$vtr_flow_path/scripts/add_tiles.py --arch_xml $architecture_file_path > $architecture_file_path_new`;
420+
#copy( "$architecture_file_path", $architecture_file_path_new );
420421
$architecture_file_path = $architecture_file_path_new;
421422

422423
my $circuit_file_path_new = "$temp_dir$benchmark_name" . file_ext_for_stage($starting_stage - 1, $circuit_suffix);

0 commit comments

Comments
 (0)