Skip to content

Commit

Permalink
Wip/listfile multipliers (#243)
Browse files Browse the repository at this point in the history
* fabric_gen:utils: Add multiplier support to switch matrix listfile

Add multipliers to switch matrix list files.

{<num>} defines a multipliert, wich adds the expand the port <num> times.

Add docs for multiplier.

Signed-off-by: Jonas K. <[email protected]>

* fabric_gen: Add check if multiplexers in .list files have the same number of inputs and outputs

Signed-off-by: Jonas K. <[email protected]>

---------

Signed-off-by: Jonas K. <[email protected]>
  • Loading branch information
EverythingElseWasAlreadyTaken authored Oct 29, 2024
1 parent dbe4c22 commit 9f0d36a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions FABulous/fabric_generator/file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ def parseList(
rightList = []
expandListPorts(left, leftList)
expandListPorts(right, rightList)
if len(leftList) != len(rightList):
raise ValueError(
f"List file {filePath} does not have the same number of source and sink ports."
)
resultList += list(zip(leftList, rightList))

result = list(dict.fromkeys(resultList))
Expand Down
25 changes: 19 additions & 6 deletions FABulous/fabric_generator/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ def expandListPorts(port, PortList):
Raises
------
ValueError
If the port entry contains "[" without matching "]".
If the port entry contains "[" or "{" without matching closing
bracket "]"/"}".
"""
if port.count("[") != port.count("]") and port.count("{") != port.count("}"):
raise ValueError(f"Invalid port entry: {port}, mismatched brackets")

# a leading '[' tells us that we have to expand the list
if "[" in port:
if "]" not in port:
logger.error("Error in function ExpandListPorts: cannot find closing ]")
raise ValueError
# port.find gives us the first occurrence index in a string
left_index = port.find("[")
right_index = port.find("]")
Expand All @@ -40,8 +41,20 @@ def expandListPorts(port, PortList):
expandListPorts(ExpandListItem, PortList)

else:
# print('DEBUG: else, just:',port)
PortList.append(port)
# Multiply ports by the number of multipliers, given in the curly braces.
# We let all curly braces in the port Expansion to be expanded and
# calculate the total number of ports to be added afterward, based on the number of multipliers.
# Also remove the multipliers from port name, before adding it to the list.
port = port.replace(" ", "") # remove spaces
multipliers = re.findall(r"\{(\d+)\}", port)
portMultiplier = sum([int(m) for m in multipliers])
if portMultiplier != 0:
port = re.sub(r"\{(\d+)\}", "", port)
logger.debug(f"Port {port} has {portMultiplier} multipliers")
for i in range(portMultiplier):
PortList.append(port)
else:
PortList.append(port)


# Default parameters (will be overwritten if defined in fabric between 'ParametersBegin' and 'ParametersEnd'
Expand Down
9 changes: 9 additions & 0 deletions docs/source/fabric_definition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ Configurable connections are defined in either an adjacency list or an adjacency

A switch matrix entry is specified by a line <output_port>,<input_port>.
For convenience, it is possible to specify multiple ports though a list operator [item1|item2|...].
There is also a multiplier {N}, where N is the number of times the port should be repeated.
So a {4}N2BEG0 will be expanded to [N2BEG0|N2BEG0|N2BEG0|N2BEG0]

For instance, the following line in a list file

.. code-block:: python
Expand Down Expand Up @@ -468,7 +471,13 @@ A switch matrix multiplexer is modelled by having multiple connections for the s
# the same in compact form:
N2BEG[0|0|0|0],[N2END3|E2END2|S2END1|LB_O]
# or even more compact:
{4}N2BEG0,[N2END3|E2END2|S2END1|LB_O]
For completion, the following expressions are all equivalent:
.. code-block:: python
N2BEG[0|0|0|0] <=> {4}N2BEG0 <=> N2BEG[{4}0] <=> {2}N2BEG[0|0] <=> {2}N2BEG[{2}0] <=> [N2BEG0|N2BEG0|N2BEG0|N2BEG0]
The ``INCLUDE`` keyword can also be used to include another list file in the current list file. For example:

Expand Down

0 comments on commit 9f0d36a

Please sign in to comment.