Skip to content

Commit cb782c1

Browse files
committed
vtr_flow: added script to add tiles to architecture xml
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 3839ce6 commit cb782c1

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

vtr_flow/scripts/add_tiles.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env python3
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+
from lxml import etree as ET
47+
import argparse
48+
49+
TAGS_TO_SWAP = ['fc', 'pinlocations', 'switchblock_locations']
50+
ATTR_TO_REMOVE = ['area', 'height', 'width', 'capacity']
51+
52+
def swap_tags(tile, pb_type):
53+
# Moving tags from top level pb_type to tile
54+
for child in pb_type:
55+
if child.tag in TAGS_TO_SWAP:
56+
pb_type.remove(child)
57+
tile.append(child)
58+
59+
60+
def main():
61+
parser = argparse.ArgumentParser(
62+
description="Moves top level pb_types to tiles tag."
63+
)
64+
parser.add_argument(
65+
'--arch_xml',
66+
required=True,
67+
help="Input arch.xml that needs to be modified to move the top level pb_types to the `tiles` tag."
68+
)
69+
70+
args = parser.parse_args()
71+
72+
arch_xml = ET.ElementTree()
73+
root_element = arch_xml.parse(args.arch_xml)
74+
75+
tiles = ET.SubElement(root_element, 'tiles')
76+
77+
top_pb_types = []
78+
for pb_type in root_element.iter('pb_type'):
79+
if pb_type.getparent().tag == 'complexblocklist':
80+
top_pb_types.append(pb_type)
81+
82+
for pb_type in top_pb_types:
83+
tile = ET.SubElement(tiles, 'tile')
84+
attrs = pb_type.attrib
85+
86+
for attr in attrs:
87+
tile.set(attr, pb_type.get(attr))
88+
89+
# Remove attributes of top level pb_types only
90+
for attr in ATTR_TO_REMOVE:
91+
pb_type.attrib.pop(attr, None)
92+
93+
swap_tags(tile, pb_type)
94+
95+
print(ET.tostring(arch_xml, pretty_print=True).decode('utf-8'))
96+
97+
98+
if __name__ == '__main__':
99+
main()

vtr_flow/scripts/run_vtr_flow.pl

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

367367
# Read arch XML
368368
my $tpp = XML::TreePP->new();
369-
my $xml_tree = $tpp->parsefile($architecture_file_path);
369+
my $xml_tree = $tpp->parsefile("$architecture_file_path");
370370

371371
# Get lut size if undefined
372372
if (!defined $lut_size) {
@@ -419,7 +419,8 @@
419419
#system "cp $odin2_base_config"
420420

421421
my $architecture_file_path_new = "$temp_dir$architecture_file_name";
422-
copy( $architecture_file_path, $architecture_file_path_new );
422+
my $ret = `$vtr_flow_path/scripts/add_tiles.py --arch_xml $architecture_file_path > $architecture_file_path_new`;
423+
#copy( "$architecture_file_path", $architecture_file_path_new );
423424
$architecture_file_path = $architecture_file_path_new;
424425

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

0 commit comments

Comments
 (0)