-
Notifications
You must be signed in to change notification settings - Fork 1
/
device.py
94 lines (76 loc) · 3.23 KB
/
device.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""The FPGA device class."""
__copyright__ = """
Copyright (c) 2024 RapidStream Design Automation, Inc. and contributors.
All rights reserved. The contributor(s) of this file has/have agreed to the
RapidStream Contributor License Agreement.
"""
from typing import Any
from pydantic import BaseModel
from noc_graph import NocGraph
class Device(BaseModel):
"""Represents an FPGA device with its attributes."""
part_num: str
board_part: str
# user's partition choice: slot_width x slot_height (slots)
slot_width: int
slot_height: int
cr_mapping: list[list[str]]
# NoC graph
noc_graph: NocGraph
# generated
nmu_per_slot: list[list[int]]
nsu_per_slot: list[list[int]]
def __init__(self, **data: Any) -> None:
"""Initialize class and generates per slot attributes."""
super().__init__(**data)
assert (
self.noc_graph.num_slr == self.slot_height
), "Assumes slot_height equals number of SLRs."
assert len(self.cr_mapping) <= self.slot_width
if len(self.cr_mapping) > 0:
assert len(self.cr_mapping[0]) <= self.slot_height
# generate per slot data structure
self.nmu_per_slot = [
[0 for _ in range(self.slot_height)] for _ in range(self.slot_width)
]
self.nsu_per_slot = [
[0 for _ in range(self.slot_height)] for _ in range(self.slot_width)
]
for j in range(self.slot_height):
nodes_per_slr = self.noc_graph.rows_per_slr[j] * self.noc_graph.num_col
for i in range(self.slot_width):
self.nmu_per_slot[i][j] = nodes_per_slr // self.slot_width
self.nsu_per_slot[i][j] = nodes_per_slr // self.slot_width
print("nmu per slot", self.nmu_per_slot)
def get_num_nmu_in_slot(self, x: int, y: int) -> int:
"""Returns the number of NMU nodes in a slot."""
assert x < self.slot_width, "Slot X coordinate out of range!"
assert y < self.slot_height, "Slot Y coordinate out of range!"
return self.nmu_per_slot[x][y]
def get_num_nsu_in_slot(self, x: int, y: int) -> int:
"""Returns the number of NSU nodes in a slot."""
assert x < self.slot_width, "Slot X coordinate out of range!"
assert y < self.slot_height, "Slot Y coordinate out of range!"
return self.nsu_per_slot[x][y]
def get_nmu_or_nsu_names_in_slot(self, node_type: str, x: int, y: int) -> list[str]:
"""Gets all NMU or NSU node names in a given slot.
node: either "nmu" or "nsu".
Returns a list of strings.
"""
assert x < self.slot_width
assert y < self.slot_height
cols_per_slot = self.noc_graph.num_col // self.slot_width
col_start = cols_per_slot * x
col_end = col_start + cols_per_slot
row_start = sum(self.noc_graph.rows_per_slr[:y]) if y > 0 else 0
row_end = row_start + self.noc_graph.rows_per_slr[y]
return [
f"{node_type}_x{x}y{y}"
for x in range(col_start, col_end)
for y in range(row_start, row_end)
]
def get_slot_cr(self, x: int, y: int) -> str:
"""Gets all Clock Regions of a slot.
Returns a string
"""
return self.cr_mapping[x][y]