switch_matrix¶
Switch matrix construct for the FABulous fabric model.
A tile’s switch matrix is the programmable interconnect: which sources may drive
each destination inside the tile. The connectivity is declared in the tile’s
matrix file (a .csv adjacency matrix or a .list of pairs) and read once
into this dataclass in canonical port/BEL order. RTL generation
lives in fabulous.fabric_generator.gen_fabric.gen_switchmatrix.
Classes¶
Encapsulates a tile's switch matrix: source file and connectivity. |
Functions¶
|
Return the canonical (sources, dests) signal order for a switch matrix. |
Module Contents¶
SwitchMatrix¶
- class SwitchMatrix[source]¶
Encapsulates a tile’s switch matrix: source file and connectivity.
Read once and immutable: the connectivity is fixed at construction, so the same object can be safely shared or deep-copied across fabric-grid placements.
- Variables:
matrix_file (Path) – Source file for the switch matrix (
.csv,.list, or hand-written HDL).connections (dict[str, list[str]]) – Mux output port -> list of mux input signals. Empty for hand-written HDL.
preserve_list_order (bool) – Whether the mux-input order is significant (MSB-first
.listorder) rather than the canonical dest-column order. Recorded once at read time and reused when exporting so a round trip is faithful. Default False.hdl_config_bits (int | None) – Config-bit count declared by a hand-written HDL matrix. None for parsed matrices, whose
no_config_bitsis derived fromconnectionsinstead.
Properties¶
Methods¶
- classmethod from_file(path, tile_name, ports=None, bels=None, preserve_list_order=False) SwitchMatrix[source]¶
Construct a SwitchMatrix by parsing the given source file.
The matrix is read once into its canonical form. A
.csvis already canonical (its authored row/column order is kept). A.listis read into the canonical port/BEL signal order whenportsis supplied, matching what the old bootstrap-CSV pipeline produced; withoutportsit falls back to raw.listorder (connectivity only, order not canonical). Whenportsis supplied every connection is validated against the tile’s signals (both.csvand.list); without it no validation is possible. Hand-written HDL (.v/.sv/.vhdl/.vhd) is an escape hatch: only itsNumberOfConfigBitsis read and connectivity is left empty.- Parameters:
path (Path) – Path to the switch matrix file. Supported extensions:
.csv,.list,.v,.sv,.vhdl,.vhd.tile_name (str) – Tile name, used only in the hand-written-HDL warning message.
ports (list[Port] | None, optional) – Tile ports, required to canonicalise a
.listmatrix.bels (list[Bel] | None, optional) – Tile BELs, used to canonicalise a
.listmatrix.preserve_list_order (bool, optional) – When True, a
.list’s mux inputs keep the file order (reversed, MSB-first) instead of the canonical dest-column order. Defaults to False.
- Returns:
Fully initialised switch matrix instance.
- Raises:
InvalidFileType – If the file extension is not recognised.
- to_csv_file(path, tile_name) None[source]¶
Write the switch matrix connections to a
.csvfile.The file is written in the format consumed by
parseMatrix: the header row contains mux-input signal names (column headers), each data row ismux_output_port, v0, v1, ..., and comment annotations (#,count) are appended for human readability. Each mux input is encoded with a 1-based descending index (not a bare1) soparseMatrixrecovers the exact per-mux order regardless of the column arrangement, making a.list->.csv->.listround trip order-faithful.- Parameters:
path (Path) – Destination
.csvfile. Created (or overwritten) by this call.tile_name (str) – Tile name written to the top-left cell of the CSV header.
- to_list_file(path) None[source]¶
Write the switch matrix connections to a
.listfile.One line per mux output in the compact form
{N}mux_output,[input0|input1|...]whereNis the number of mux inputs. The{N}multiplier repeats the output soparseListpairs it with each bracketed input. Outputs with no inputs are omitted.The inputs are always written reversed (MSB-first), independent of
preserve_list_order- the file always encodes the full order, and the reader decides how to interpret it: apreserve_list_orderread recovers this exact order, while a plain read re-derives it from the tile’s ports.- Parameters:
path (Path) – Destination
.listfile. Created (or overwritten) by this call.
- switch_matrix_signal_order(ports, bels) tuple[list[str], list[str]][source]¶
Return the canonical
(sources, dests)signal order for a switch matrix.This is the ordering the switch matrix uses for its mux outputs (sources) and mux inputs (dests): non-JUMP wire signals first (in tile port order), then BEL signals, then JUMP wire signals, each de-duplicated first-seen. It depends only on the tile’s ports and BELs, so a
.listmatrix can be read straight into this canonical order without a CSV round trip.