Skip to content

Commit

Permalink
Merge pull request #52 from mithro/rr_graph_lib
Browse files Browse the repository at this point in the history
Python library for working with rr_graph files.
  • Loading branch information
mithro committed Apr 12, 2018
2 parents 421f1ba + 2c6a836 commit 8929d23
Show file tree
Hide file tree
Showing 11 changed files with 2,241 additions and 20 deletions.
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,41 @@ architectures, here are some tips;

# Getting Started

FIXME: Add things here.

`apt-get install libxml2-utils`

Run the full suite:

```
# doesn't work yet
# export ARCH=artix7
export ARCH=testarch
make env
make .git/info/exclude
make redir
make
```
Test the rr_graph library:
```
PATH=$PWD/env/conda/bin/:$PATH
PYTHONPATH=$PWD/utils:$PYTHONPATH
python3 -m lib.rr_graph.graph
```

Parse an rr_graph.xml using rr_graph library:

```
cd tests
make wire.rr_graph.xml
stat build/testarch/2x4/wire.rr_graph.xml
# Run test suite
# Dump an rr_graph file
python3 -m lib.rr_graph.graph build/testarch/2x4/wire.rr_graph.xml
```

See some example vpr commands (while still in tests):

```
make V=1
```

# Tools

Expand Down
File renamed without changes.
119 changes: 105 additions & 14 deletions testarch/devices/lutff/arch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,116 @@
<models>
<xi:include href="../../tile/lutff/lutff.model.xml" xpointer="xpointer(models/child::node())" />
</models>

<!-- Layout of the FPGA, we are using 4x4 -->
<layout>
<fixed_layout name="2x4" width="8" height="8">
<fixed_layout name="2x1" width="8" height="3">
<!--
01234567
2 ........
1 .I.XX.O.
0 ........
-->
<col priority="10" startx="0" type="EMPTY"/>
<col priority="10" startx="1" type="BLK_IG-IBUF"/>
<col priority="10" startx="2" type="EMPTY"/>
<col priority="10" startx="3" type="BLK_TI-LUTFF"/>
<col priority="10" startx="4" type="BLK_TI-LUTFF"/>
<col priority="10" startx="5" type="EMPTY"/>
<col priority="10" startx="6" type="BLK_IG-OBUF"/>
<col priority="10" startx="7" type="EMPTY"/>

<col type="EMPTY" startx="0" priority="10" />
<col type="BLK_BB-VPR_PAD" startx="1" priority="10" />
<col type="EMPTY" startx="2" priority="10" />
<row priority="11" starty="2" type="EMPTY"/>
<!-- starty="1" -->
<row priority="11" starty="0" type="EMPTY"/>
</fixed_layout>
<fixed_layout name="1x2" width="3" height="8">
<!--
012
7 ...
6 .I.
5 ...
4 .X.
3 .X.
2 ...
1 .O.
0 ...
-->
<col priority="11" startx="0" type="EMPTY"/>
<!-- startx="1" -->
<col priority="11" startx="2" type="EMPTY"/>

<col type="BLK_TI-LUTFF" startx="3" priority="10" />
<col type="BLK_TI-LUTFF" startx="4" priority="10" />
<row priority="10" starty="7" type="EMPTY"/>
<row priority="10" starty="6" type="BLK_IG-OBUF"/>
<row priority="10" starty="5" type="EMPTY"/>
<row priority="10" starty="4" type="BLK_TI-LUTFF"/>
<row priority="10" starty="3" type="BLK_TI-LUTFF"/>
<row priority="10" starty="2" type="EMPTY"/>
<row priority="10" starty="1" type="BLK_IG-IBUF"/>
<row priority="10" starty="0" type="EMPTY"/>

<col type="EMPTY" startx="5" priority="10" />
<col type="BLK_BB-VPR_PAD" startx="6" priority="10" />
<col type="EMPTY" startx="7" priority="10" />
</fixed_layout>
<fixed_layout name="2x4" width="8" height="6">
<!--
01234567
5 ........
4 .I.XX.O.
3 .I.XX.O.
2 .I.XX.O.
1 .I.XX.O.
0 ........
-->
<col priority="12" startx="0" type="EMPTY"/>
<col priority="10" startx="1" type="BLK_IG-IBUF"/>
<col priority="10" startx="2" type="EMPTY"/>
<col priority="10" startx="3" type="BLK_TI-LUTFF"/>
<col priority="10" startx="4" type="BLK_TI-LUTFF"/>
<col priority="10" startx="5" type="EMPTY"/>
<col priority="10" startx="6" type="BLK_IG-OBUF"/>
<col priority="12" startx="7" type="EMPTY"/>

<row type="EMPTY" starty="0" priority="11" />
<row type="EMPTY" starty="7" priority="11" />
<row priority="11" starty="5" type="EMPTY"/>
<!-- startx="4" -->
<!-- startx="3" -->
<!-- startx="2" -->
<!-- startx="1" -->
<row priority="11" starty="0" type="EMPTY"/>
</fixed_layout>
<fixed_layout name="4x4" width="10" height="10">
<!--
0123456789
9 ..........
8 ...OOOO...
7 ..........
6 .I.XXXX.O.
5 .I.XXXX.O.
4 .I.XXXX.O.
3 .I.XXXX.O.
2 ..........
1 ...IIII...
0 ..........
-->
<col priority="12" startx="0" type="EMPTY"/>
<col priority="10" startx="1" type="BLK_IG-OBUF"/>
<col priority="12" startx="2" type="EMPTY"/>
<col priority="10" startx="3" type="BLK_TI-LUTFF"/>
<col priority="10" startx="4" type="BLK_TI-LUTFF"/>
<col priority="10" startx="5" type="BLK_TI-LUTFF"/>
<col priority="10" startx="6" type="BLK_TI-LUTFF"/>
<col priority="12" startx="7" type="EMPTY"/>
<col priority="10" startx="8" type="BLK_IG-OBUF"/>
<col priority="12" startx="9" type="EMPTY"/>

<row priority="11" starty="9" type="EMPTY"/>
<row priority="11" starty="8" type="BLK_IG-OBUF"/>
<row priority="11" starty="7" type="EMPTY"/>
<!-- starty="6" -->
<!-- starty="5" -->
<!-- starty="4" -->
<!-- starty="3" -->
<row priority="11" starty="2" type="EMPTY"/>
<row priority="11" starty="1" type="BLK_IG-IBUF"/>
<row priority="11" starty="0" type="EMPTY"/>
</fixed_layout>

</layout>

<device>
Expand Down Expand Up @@ -57,7 +147,8 @@
</segment>
</segmentlist>
<complexblocklist>
<xi:include href="../../../vpr/pad/pad.pb_type.xml"/>
<xi:include href="../../../vpr/ibuf/ibuf.pb_type.xml"/>
<xi:include href="../../../vpr/obuf/obuf.pb_type.xml"/>
<xi:include href="../../tile/lutff/lutff.pb_type.xml"/>
</complexblocklist>

Expand Down
7 changes: 5 additions & 2 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $(OUTPUT_DIR)/%.eblif: %.eblif | $(OUTPUT_DIR)

# VPR commands
VPR_ARGS ?=
VPR_CMD = $(VPR) $(VPR_ARGS) $(DEVICE_FILE) --device $(DEVICE)
VPR_CMD = $(VPR) $(VPR_ARGS) $(DEVICE_FILE) --device $(DEVICE) --timing_analysis off
VPR_FULL_CMD = cd $(OUTPUT_DIR); $(VPR_CMD)

ROUTE_CHAN_WIDTH ?= 6
Expand All @@ -80,6 +80,9 @@ $(OUTPUT_DIR)/%.rr_graph.pretty.xml: $(OUTPUT_DIR)/%.rr_graph.xml
%.rr_graph.xml: $(OUTPUT_DIR)/%.rr_graph.xml | $(OUTPUT_DIR)
@true

%.rr_graph.pretty.xml: $(OUTPUT_DIR)/%.rr_graph.pretty.xml | $(OUTPUT_DIR)
@true

.PRECIOUS: $(OUTPUT_DIR)/%.rr_graph.xml
.PRECIOUS: $(OUTPUT_DIR)/%.rr_graph.pretty.xml
# ------------------------------------------------------------------------
Expand All @@ -99,9 +102,9 @@ $(OUTPUT_DIR)/%.rr_graph.pretty.xml: $(OUTPUT_DIR)/%.rr_graph.xml

ALL_OUTPUT = $(patsubst %.v,$(OUTPUT_DIR)/%.rr_graph.xml,$(wildcard *.v)) $(patsubst %.eblif,$(OUTPUT_DIR)/%.rr_graph.xml,$(wildcard *.eblif))

# $(call quiet_cmd,make const.echo,Ran $(GREEN)const$(NC)test)
all:
@echo -e "Running all tests for $(PURPLE)$(DEVICE)$(NC)in $(YELLOW)$(ARCH)$(NC)"
$(call quiet_cmd,make const.echo,Ran $(GREEN)const$(NC)test)
$(call quiet_cmd,make wire.echo,Ran $(GREEN)wire$(NC)test)
$(call quiet_cmd,make ff.echo,Ran $(GREEN)ff$(NC)test)
$(call quiet_cmd,make lut.echo,Ran $(GREEN)lut$(NC)test)
Expand Down
5 changes: 5 additions & 0 deletions utils/lib/asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def assert_type(obj, cls, msg="{obj} ({obj!r}) should be a {cls}, not {objcls}")
if not isinstance(obj, cls):
raise TypeError(msg.format(obj=obj, objcls=type(obj), cls=cls))

def assert_type_or_none(obj, classes):
"""Raise a type error if obj is not an instance of cls or None."""
if obj is not None:
assert_type(obj, classes)

def assert_len_eq(l):
"""Check all lists in a list are equal length"""
# Sanity check
Expand Down
92 changes: 92 additions & 0 deletions utils/lib/rr_graph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from collections import namedtuple

class static_property(object):
"""
Descriptor (non-data) for building an attribute on-demand on first use.
"""
def __init__(self, factory):
"""
<factory> is called such: factory(instance) to build the attribute.
"""
self._attr_name = factory.__name__
self._factory = factory

def __get__(self, instance, owner):
# Build the attribute.
attr = self._factory(instance)

# Cache the value; hide ourselves.
setattr(instance, self._attr_name, attr)

return attr


Position = namedtuple("P", ("x", "y"))
Pos = Position # Shorter Alias
P = Position # Even shorter alias

_Size = namedtuple("Size", ("w", "h"))
class Size(_Size):
"""
>>> s = Size(2, 3)
>>> s
Size(w=2, h=3)
>>> p = Position(4, 5)
>>> s + p
P(x=6, y=8)
>>> s + s
Size(w=4, h=6)
>>> s + 1
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for +: 'Size' and 'int'
"""
def __new__(cls, w, h):
assert w >= 0
assert h >= 0
return _Size.__new__(cls, w, h)

@static_property
def width(self):
return self.w

@static_property
def height(self):
return self.h

@static_property
def x(self):
return self.w

@static_property
def y(self):
return self.h

def walk(self):
for x in range(0, self.x):
for y in range(0, self.y):
yield Position(x, y)

def __add__(self, o):
if isinstance(o, Position):
return o.__class__(o.x+self.x, o.y+self.y)
elif isinstance(o, Size):
return o.__class__(o.x+self.x, o.y+self.y)
return NotImplemented

def __radd__(self, o):
if isinstance(o, Position):
return o.__class__(o.x+self.x, o.y+self.y)
elif isinstance(o, Size):
return o.__class__(o.x+self.x, o.y+self.y)
return NotImplemented


S = Size


class Offset(Size):
pass


O = Offset
5 changes: 5 additions & 0 deletions utils/lib/rr_graph/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .. import rr_graph

if __name__ == "__main__":
import doctest
doctest.testmod(rr_graph)

0 comments on commit 8929d23

Please sign in to comment.