11from dataclasses import dataclass
2- from itertools import chain
32from typing import Generic , Sequence
43
54import numpy as np
6- import rustworkx as nx
75
8- from .block import Block , SiteType
6+ from .word import SiteType , Word
97
108
119@dataclass (frozen = True )
12- class Lane :
10+ class Bus :
1311 """A group of inter-lanes that can be executed in parallel.
1412
15- For inter-lanes, src and dst are the block indices involved in the inter-lane.
13+ For inter-lanes, src and dst are the word indices involved in the inter-lane.
1614 For intra-lanes, src are the source site indices and dst are the destination site indices.
1715
1816 """
@@ -23,55 +21,23 @@ class Lane:
2321
2422@dataclass (frozen = True )
2523class ArchSpec (Generic [SiteType ]):
26- blocks : tuple [Block [SiteType ], ...]
27- """List of all blocks in the architecture."""
28- has_intra_lanes : frozenset [int ]
29- """Set of blocks that have intra-lane moves."""
30- has_inter_lanes : frozenset [int ] # set of sites in block that have inter-lanes moves
31- """Set of sites (by index) that have inter-lane moves. These sites are the same across all blocks."""
32- intra_lanes : tuple [Lane , ...]
33- """List of all intra-lanes in the architecture by site index."""
34- inter_lanes : tuple [Lane , ...]
35- """List of all inter-lanes in the architecture by block index."""
36-
37- def get_graphs (self ):
38-
39- block_intra_graph = nx .PyDiGraph ()
40- intra_move_compat = nx .PyGraph ()
41-
42- all_moves = list (
43- chain .from_iterable (
44- (list (zip (lane .src , lane .dst )) for lane in self .intra_lanes )
45- )
46- )
47-
48- move_map = {move : i for i , move in enumerate (all_moves )}
49-
50- for lane in self .intra_lanes :
51- moves = list (zip (lane .src , lane .dst ))
52- for src , dst in moves :
53- block_intra_graph .add_edge (src , dst , None )
54-
55- for i , move_i in enumerate (moves ):
56- for j , move_j in enumerate (moves [i + 1 :], i + 1 ):
57- intra_move_compat .add_edge (move_map [move_i ], move_map [move_j ], None )
58-
59- inter_block_graph = nx .PyDiGraph ()
60- inter_move_compat = nx .PyGraph ()
61-
62- for lane in self .inter_lanes :
63- moves = list (zip (lane .src , lane .dst ))
64- for src , dst in moves :
65- inter_block_graph .add_edge (src , dst , None )
66-
67- for i , move_i in enumerate (moves ):
68- for j , move_j in enumerate (moves [i + 1 :], i + 1 ):
69- inter_move_compat .add_edge (i , j , None )
24+ words : tuple [Word [SiteType ], ...]
25+ """tuple of all words in the architecture. words[i] gives the word at word address i."""
26+ has_site_buses : frozenset [int ]
27+ """Set of words that have site-lane moves."""
28+ has_word_buses : frozenset [int ] # set of sites in word that have inter-lanes moves
29+ """Set of sites (by index) that have word-lane moves. These sites are the same across all words."""
30+ site_buses : tuple [Bus , ...]
31+ """List of all site buses in the architecture by site address."""
32+ word_buses : tuple [Bus , ...]
33+ """List of all word buses in the architecture by word address."""
34+ site_bus_compatibility : tuple [frozenset [int ], ...]
35+ """Mapping from word id indicating which other word ids can execute site-buses in parallel."""
7036
7137 def plot (
7238 self ,
7339 ax = None ,
74- show_blocks : Sequence [int ] = (),
40+ show_words : Sequence [int ] = (),
7541 show_intra : Sequence [int ] = (),
7642 show_inter : Sequence [int ] = (),
7743 ** scatter_kwargs ,
@@ -82,9 +48,9 @@ def plot(
8248 if ax is None :
8349 ax = plt .gca ()
8450
85- for block_id in show_blocks :
86- block = self .blocks [ block_id ]
87- block .plot (ax )
51+ for word_id in show_words :
52+ word = self .words [ word_id ]
53+ word .plot (ax )
8854
8955 x_min , x_max = ax .get_xlim ()
9056 y_min , y_max = ax .get_ylim ()
@@ -93,14 +59,14 @@ def plot(
9359 bow_x = (x_max - x_min ) * 0.025
9460
9561 colors = {}
96- for block_id in show_blocks :
97- block = self .blocks [ block_id ]
62+ for word_id in show_words :
63+ word = self .words [ word_id ]
9864 for lane_id in show_intra :
99- lane = self .intra_lanes [lane_id ]
65+ lane = self .site_buses [lane_id ]
10066
10167 for start , end in zip (lane .src , lane .dst ):
102- start = block [start ]
103- end = block [end ]
68+ start = word [start ]
69+ end = word [end ]
10470
10571 for (x_start , y_start ), (x_end , y_end ) in zip (
10672 start .positions (), end .positions ()
@@ -127,14 +93,14 @@ def plot(
12793 colors [lane ] = ln .get_color ()
12894
12995 for lane in show_inter :
130- lane = self .inter_lanes [lane ]
131- for start_block_id , end_block_id in zip (lane .src , lane .dst ):
132- start_block = self .blocks [ start_block_id ]
133- end_block = self .blocks [ end_block_id ]
134-
135- for site in self .has_inter_lanes :
136- start = start_block [site ]
137- end = end_block [site ]
96+ lane = self .word_buses [lane ]
97+ for start_word_id , end_word_id in zip (lane .src , lane .dst ):
98+ start_word = self .words [ start_word_id ]
99+ end_word = self .words [ end_word_id ]
100+
101+ for site in self .has_word_buses :
102+ start = start_word [site ]
103+ end = end_word [site ]
138104 for (x_start , y_start ), (x_end , y_end ) in zip (
139105 start .positions (), end .positions ()
140106 ):
@@ -164,7 +130,7 @@ def plot(
164130 def show (
165131 self ,
166132 ax = None ,
167- show_blocks : Sequence [int ] = (),
133+ show_words : Sequence [int ] = (),
168134 show_intra : Sequence [int ] = (),
169135 show_inter : Sequence [int ] = (),
170136 ** scatter_kwargs ,
@@ -173,7 +139,7 @@ def show(
173139
174140 self .plot (
175141 ax ,
176- show_blocks = show_blocks ,
142+ show_words = show_words ,
177143 show_intra = show_intra ,
178144 show_inter = show_inter ,
179145 ** scatter_kwargs ,
0 commit comments