|
1 | 1 | from ..common import PORT_DIRECTION_COUNTS |
| 2 | + |
| 3 | + |
| 4 | + |
2 | 5 | class Tile: |
3 | | - def __init__(s, dimX, dimY, num_registers, operations): |
4 | | - s.disabled = False |
5 | | - s.dimX = dimX |
6 | | - s.dimY = dimY |
7 | | - s.num_registers = num_registers |
8 | | - s.operations = operations |
9 | | - s.isDefaultFus_ = True |
10 | | - s.toMem = False |
11 | | - s.fromMem = False |
12 | | - s.invalidOutPorts = set() |
13 | | - s.invalidInPorts = set() |
14 | | - for i in range(PORT_DIRECTION_COUNTS): |
15 | | - s.invalidOutPorts.add(i) |
16 | | - s.invalidInPorts.add(i) |
17 | | - |
18 | | - def getInvalidInPorts(s): |
19 | | - return s.invalidInPorts |
20 | | - |
21 | | - def getInvalidOutPorts(s): |
22 | | - return s.invalidOutPorts |
23 | | - |
24 | | - def hasToMem(s): |
25 | | - return s.toMem |
26 | | - |
27 | | - def hasFromMem(s): |
28 | | - return s.fromMem |
29 | | - |
30 | | - def getIndex(s, TileList): |
31 | | - if s.disabled: |
32 | | - return -1 |
33 | | - index = 0 |
34 | | - for tile in TileList: |
35 | | - if tile.dimY < s.dimY and not tile.disabled: |
36 | | - index += 1 |
37 | | - elif tile.dimY == s.dimY and tile.dimX < s.dimX and not tile.disabled: |
38 | | - index += 1 |
39 | | - return index |
40 | | - |
41 | | - def isDefaultFus(s): |
42 | | - return s.isDefaultFus_ |
43 | | - |
44 | | - def getAllValidFuTypes(s): |
45 | | - return s.operations |
46 | | - |
47 | | - def override(s): |
48 | | - # TODO @benkangpeng |
49 | | - raise NotImplementedError |
| 6 | + """ |
| 7 | + Represents a single tile in the CGRA array configuration. |
| 8 | + This class holds the static configuration parameters for a tile, including its location, |
| 9 | + functional units, and connectivity status (memory access, valid ports). |
| 10 | + It is used during the parameterization phase to configure the RTL generation. |
| 11 | + """ |
| 12 | + |
| 13 | + def __init__(self, dimX, dimY, num_registers, fu_types): |
| 14 | + self.disabled = False |
| 15 | + self.dimX = dimX # Column index (X coordinate) in the CGRA mesh |
| 16 | + self.dimY = dimY # Row index (Y coordinate) in the CGRA mesh |
| 17 | + # Number of registers in the tile's register file |
| 18 | + self.num_registers = num_registers |
| 19 | + self.fu_types = fu_types |
| 20 | + self.isDefaultFus_ = True # Flag indicating if the tile uses the default set of FUs |
| 21 | + |
| 22 | + # toMem: Indicates if this tile has a dedicated link TO the data memory (for Store operations). |
| 23 | + self.toMem = False |
| 24 | + |
| 25 | + # fromMem: Indicates if this tile has a dedicated link FROM the data memory (for Load operations). |
| 26 | + self.fromMem = False |
| 27 | + |
| 28 | + # invalidOutPorts: A set containing port indices (e.g., PORT_NORTH, PORT_EAST) that are NOT used |
| 29 | + # as output ports. Initialized to contain ALL ports. When a link is created originating from this |
| 30 | + # tile, the corresponding port is removed from this set. |
| 31 | + # Used in RTL generation to ground/disable unused output ports. |
| 32 | + self.invalidOutPorts = set() |
| 33 | + |
| 34 | + # invalidInPorts: A set containing port indices that are NOT used as input ports. |
| 35 | + # Initialized to contain ALL ports. When a link is created terminating at this tile, |
| 36 | + # the corresponding port is removed from this set. |
| 37 | + # Used in RTL generation to ground/disable unused input ports. |
| 38 | + self.invalidInPorts = set() |
| 39 | + |
| 40 | + for i in range(PORT_DIRECTION_COUNTS): |
| 41 | + self.invalidOutPorts.add(i) |
| 42 | + self.invalidInPorts.add(i) |
| 43 | + |
| 44 | + def getInvalidInPorts(self): |
| 45 | + """Returns the set of unused input ports.""" |
| 46 | + return self.invalidInPorts |
| 47 | + |
| 48 | + def getInvalidOutPorts(self): |
| 49 | + """Returns the set of unused output ports.""" |
| 50 | + return self.invalidOutPorts |
| 51 | + |
| 52 | + def hasToMem(self): |
| 53 | + """Returns True if the tile connects to memory (write/store).""" |
| 54 | + return self.toMem |
| 55 | + |
| 56 | + def hasFromMem(self): |
| 57 | + """Returns True if the tile receives from memory (read/load).""" |
| 58 | + return self.fromMem |
| 59 | + |
| 60 | + def getIndex(self, TileList): |
| 61 | + """ |
| 62 | + Calculates the flattened index of this tile within a given list of tiles. |
| 63 | + This is used to map the logical Tile object to the physical TileRTL instance index |
| 64 | + in the top-level CGRA component. |
| 65 | +
|
| 66 | + Args: |
| 67 | + TileList: A list of all Tile objects in the CGRA. |
| 68 | +
|
| 69 | + Returns: |
| 70 | + int: The 0-based index of this tile, skipping disabled tiles. |
| 71 | + Returns -1 if this tile is disabled. |
| 72 | + """ |
| 73 | + if self.disabled: |
| 74 | + return -1 |
| 75 | + index = 0 |
| 76 | + for tile in TileList: |
| 77 | + # Counts valid tiles that appear before 's' in row-major order (Row Y, then Col X) |
| 78 | + if tile.dimY < self.dimY and not tile.disabled: |
| 79 | + index += 1 |
| 80 | + elif tile.dimY == self.dimY and tile.dimX < self.dimX and not tile.disabled: |
| 81 | + index += 1 |
| 82 | + return index |
| 83 | + |
| 84 | + def isDefaultFus(self): |
| 85 | + return self.isDefaultFus_ |
| 86 | + |
| 87 | + def getAllValidFuTypes(self): |
| 88 | + return self.fu_types |
| 89 | + |
| 90 | + def override(self, fu_types, existence): |
| 91 | + """ |
| 92 | + Overrides the default configuration for this tile. |
| 93 | +
|
| 94 | + Args: |
| 95 | + fu_types: New list of supported fu_types. |
| 96 | + existence: Boolean, if False, marks the tile as disabled (not physically present/active). |
| 97 | + """ |
| 98 | + self.fu_types = fu_types |
| 99 | + self.disabled = not existence |
| 100 | + self.isDefaultFus_ = False |
0 commit comments