Skip to content

Commit 49c5f14

Browse files
authored
Merge pull request #4608 from oharboe/fakeram-drop-height-floor
FakeRAM2.0: size the macro height from its pins, not a 3.5 um floor
2 parents 43b747f + 208f63b commit 49c5f14

4 files changed

Lines changed: 60 additions & 7 deletions

File tree

‎tools/FakeRAM2.0/test/memory_test.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,53 @@ def test_memory(self):
7777
self.assertEqual(timing_data.cycle_time_ns, 0.1566)
7878
self.assertEqual(timing_data.fo4_ps, 9.0632)
7979

80+
def _create_sp_ram(self, process, width, depth):
81+
mem_config = MemoryConfig.from_json(
82+
{"name": "sample", "width": width, "depth": depth, "banks": 1}
83+
)
84+
return MemoryFactory.create(mem_config, "RAM", "SP", process, TimingData())
85+
86+
def _pin_height(self, process, memory):
87+
return 2 * process.y_offset + memory.get_num_pins() * process.pin_pitch_um
88+
89+
def test_shallow_memory_is_tall_enough_for_its_pins(self):
90+
"""
91+
A 4x25 RAM's bitcells are 1.296 um tall, too short for its 55 pins;
92+
it is made as tall as its pins need, snapped up to 2.8 um
93+
"""
94+
95+
memory = self._create_sp_ram(self._process, 25, 4)
96+
physical = memory.get_physical_data()
97+
self.assertEqual(memory.get_num_pins(), 55)
98+
self.assertGreaterEqual(
99+
physical.get_height(), self._pin_height(self._process, memory)
100+
)
101+
self.assertAlmostEqual(physical.get_height(), 2.8, delta=self._delta)
102+
103+
def test_deep_memory_keeps_bitcell_height(self):
104+
"""A memory whose bitcells already fit its pins is not made taller"""
105+
106+
memory = self._create_sp_ram(self._process, 32, 64)
107+
_, height = self._process.get_macro_dimensions(32, 64, 1, 0)
108+
self.assertGreater(height, self._pin_height(self._process, memory))
109+
self.assertAlmostEqual(
110+
memory.get_physical_data().get_height(), 21.0, delta=self._delta
111+
)
112+
113+
def test_pins_fit_exactly_without_snapping(self):
114+
"""
115+
With a 1 nm snap the height is exactly what the pins need, and
116+
every pin still gets a track
117+
"""
118+
119+
process_data = TestUtils.get_base_process_data().copy()
120+
process_data["snap_height_nm"] = 1
121+
process = Process(process_data)
122+
for width in range(1, 300):
123+
# constructing the memory raises if its pins do not fit
124+
memory = self._create_sp_ram(process, width, 4)
125+
self.assertGreaterEqual(memory.get_physical_data().get_pin_pitch(), 0)
126+
80127

81128
if __name__ == "__main__":
82129
unittest.main()

‎tools/FakeRAM2.0/utils/class_memory.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,18 @@ def __init__(self, mem_config, process, timing_data):
4242
width_um, height_um = self.process.get_macro_dimensions(
4343
self.width_in_bits, self.depth, self.num_banks, self.additional_height
4444
)
45+
# Signal pins are stacked one per track up the left edge, inset
46+
# by y_offset at both ends, so the macro must be at least that
47+
# tall; a shallow memory with many pins is otherwise too short
48+
num_pins = self.get_num_pins()
49+
height_um = max(
50+
height_um,
51+
2 * self.process.y_offset + num_pins * self.process.pin_pitch_um,
52+
)
4553
self.physical.set_extents(width_um, height_um)
4654
self.physical.snap_to_grid(
4755
self.process.snap_width_nm, self.process.snap_height_nm
4856
)
49-
num_pins = self.get_num_pins()
5057
self.physical.set_pin_pitches(
5158
self.get_name(),
5259
num_pins,

‎tools/FakeRAM2.0/utils/class_process.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ def get_macro_dimensions(self, width_in_bits, depth, num_banks, additional_heigh
119119

120120
total_height += additional_height
121121

122-
min_height = max(
123-
3.5, self.snap_height_nm / 1000.0 if self.snap_height_nm else 0
124-
)
125-
total_height = max(total_height, min_height)
126-
127122
return (total_width, total_height)
128123

129124
def get_tech_nm(self):

‎tools/FakeRAM2.0/utils/physical_data.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ def set_pin_pitches(self, name, num_pins, min_pin_pitch, y_offset):
9292
raise Exception(
9393
f"Error: attempting to set pin pitches before height ({name})"
9494
)
95-
number_of_tracks_available = math.floor((h - 2 * y_offset) / min_pin_pitch)
95+
# Rounded before flooring: a height that fits its pins exactly would
96+
# otherwise lose a track to float error (e.g. 46.99999 -> 46)
97+
number_of_tracks_available = math.floor(
98+
round((h - 2 * y_offset) / min_pin_pitch, 6)
99+
)
96100
number_of_spare_tracks = number_of_tracks_available - num_pins
97101

98102
if number_of_spare_tracks < 0:

0 commit comments

Comments
 (0)