Skip to content

Commit 1413a95

Browse files
Latency modeling
1 parent 81a89b7 commit 1413a95

14 files changed

Lines changed: 615 additions & 605 deletions

File tree

hwcomponents_library/_version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
commit_id: COMMIT_ID
2929
__commit_id__: COMMIT_ID
3030

31-
__version__ = version = '1.0.29'
32-
__version_tuple__ = version_tuple = (1, 0, 29)
31+
__version__ = version = "1.0.35"
32+
__version_tuple__ = version_tuple = (1, 0, 35)
3333

34-
__commit_id__ = commit_id = 'gbe4a7373c'
34+
__commit_id__ = commit_id = "g81a89b711"

hwcomponents_library/base.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
from hwcomponents import EnergyAreaModel, actionDynamicEnergy
1+
from hwcomponents import ComponentModel, action
22
from hwcomponents.scaling import *
33

44

5-
class LibraryEstimatorClassBase(EnergyAreaModel):
5+
class LibraryEstimatorClassBase(ComponentModel):
66
priority: float = 0.8
77

8-
@actionDynamicEnergy
9-
def write(self) -> float:
10-
return 0
8+
@action
9+
def write(self) -> tuple[float, float]:
10+
"""Default write returns zero energy and latency."""
11+
return 0.0, 0.0
1112

12-
@actionDynamicEnergy
13-
def read(self) -> float:
14-
return 0
13+
@action
14+
def read(self) -> tuple[float, float]:
15+
"""Default read returns zero energy and latency."""
16+
return 0.0, 0.0

hwcomponents_library/library/aladdin.py

Lines changed: 94 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from hwcomponents_library.base import LibraryEstimatorClassBase
1414
from hwcomponents.scaling import *
15-
from hwcomponents import actionDynamicEnergy
15+
from hwcomponents import action
1616

1717

1818
# Original CSV contents:
@@ -48,35 +48,36 @@ def __init__(self, tech_node: float, width: int = 32):
4848
"tech_node",
4949
tech_node,
5050
40e-9,
51-
tech_node_energy,
5251
tech_node_area,
52+
tech_node_energy,
53+
noscale,
5354
tech_node_leak,
5455
)
55-
self.width: int = self.scale("width", width, 32, linear, linear, linear)
56+
self.width: int = self.scale(
57+
"width", width, 32, linear, linear, noscale, linear
58+
)
5659

57-
@actionDynamicEnergy
58-
def add(self) -> float:
60+
@action
61+
def add(self) -> tuple[float, float]:
5962
"""
60-
Returns the energy for one addition operation in Joules.
63+
Returns the energy and latency for one addition operation.
6164
6265
Returns
6366
-------
64-
float
65-
The energy for one addition operation in Joules.
67+
(energy, latency): Tuple in (Joules, seconds).
6668
"""
67-
return 0.21e-12
69+
return 0.21e-12, 0.0
6870

69-
@actionDynamicEnergy
70-
def read(self) -> float:
71+
@action
72+
def read(self) -> tuple[float, float]:
7173
"""
72-
Returns the energy for one addition operation in Joules.
74+
Returns the energy and latency for one addition operation.
7375
7476
Returns
7577
-------
76-
float
77-
The energy for one addition operation in Joules.
78+
(energy, latency): Tuple in (Joules, seconds).
7879
"""
79-
return 0.21e-12
80+
return 0.21e-12, 0.0
8081

8182

8283
# Original CSV contents:
@@ -111,19 +112,20 @@ def __init__(
111112
"tech_node",
112113
tech_node,
113114
40e-9,
114-
tech_node_energy,
115115
tech_node_area,
116+
tech_node_energy,
117+
noscale,
116118
tech_node_leak,
117119
)
118-
self.width: int = self.scale("width", width, 1, linear, linear, linear)
120+
self.width: int = self.scale("width", width, 1, linear, linear, noscale, linear)
119121
self.dynamic_energy: int = self.scale(
120-
"dynamic_energy", dynamic_energy, 1, linear, linear, linear
122+
"dynamic_energy", dynamic_energy, 1, linear, linear, noscale, linear
121123
)
122124

123-
@actionDynamicEnergy(bits_per_action="width")
124-
def read(self) -> float:
125+
@action(bits_per_action="width")
126+
def read(self) -> tuple[float, float]:
125127
"""
126-
Returns the energy for one read operation in Joules.
128+
Returns the energy and latency for one read operation.
127129
128130
Parameters
129131
----------
@@ -132,15 +134,14 @@ def read(self) -> float:
132134
133135
Returns
134136
-------
135-
float
136-
The energy for one read operation in Joules.
137+
(energy, latency): Tuple in (Joules, seconds).
137138
"""
138-
return 0.009e-12
139+
return 0.009e-12, 0.0
139140

140-
@actionDynamicEnergy(bits_per_action="width")
141-
def write(self) -> float:
141+
@action(bits_per_action="width")
142+
def write(self) -> tuple[float, float]:
142143
"""
143-
Returns the energy for one write operation in Joules.
144+
Returns the energy and latency for one write operation.
144145
145146
Parameters
146147
----------
@@ -149,10 +150,9 @@ def write(self) -> float:
149150
150151
Returns
151152
-------
152-
float
153-
The energy for one write operation in Joules.
153+
(energy, latency): Tuple in (Joules, seconds).
154154
"""
155-
return 0.009e-12
155+
return 0.009e-12, 0.0
156156

157157

158158
# Original CSV contents:
@@ -182,35 +182,36 @@ def __init__(self, tech_node: float, width: int = 32):
182182
"tech_node",
183183
tech_node,
184184
40e-9,
185-
tech_node_energy,
186185
tech_node_area,
186+
tech_node_energy,
187+
noscale,
187188
tech_node_leak,
188189
)
189-
self.width: int = self.scale("width", width, 32, linear, linear, linear)
190+
self.width: int = self.scale(
191+
"width", width, 32, linear, linear, noscale, linear
192+
)
190193

191-
@actionDynamicEnergy
192-
def compare(self) -> float:
194+
@action
195+
def compare(self) -> tuple[float, float]:
193196
"""
194-
Returns the energy for one comparison operation in Joules.
197+
Returns the energy and latency for one comparison operation.
195198
196199
Returns
197200
-------
198-
float
199-
The energy for one comparison operation in Joules.
201+
(energy, latency): Tuple in (Joules, seconds).
200202
"""
201-
return 0.02947e-12
203+
return 0.02947e-12, 0.0
202204

203-
@actionDynamicEnergy
204-
def read(self) -> float:
205+
@action
206+
def read(self) -> tuple[float, float]:
205207
"""
206-
Returns the energy for one comparison operation in Joules.
208+
Returns the energy and latency for one comparison operation.
207209
208210
Returns
209211
-------
210-
float
211-
The energy for one comparison operation in Joules.
212+
(energy, latency): Tuple in (Joules, seconds).
212213
"""
213-
return 0.02947e-12
214+
return 0.02947e-12, 0.0
214215

215216

216217
# Original CSV contents:
@@ -252,8 +253,9 @@ def __init__(
252253
"tech_node",
253254
tech_node,
254255
40e-9,
255-
tech_node_energy,
256256
tech_node_area,
257+
tech_node_energy,
258+
noscale,
257259
tech_node_leak,
258260
)
259261
if width_a != 32 and width != 32:
@@ -267,34 +269,36 @@ def __init__(
267269
"or width_a and width_b separately."
268270
)
269271
self.width: int = self.scale(
270-
"width", width, 32, quadratic, quadratic, quadratic
272+
"width", width, 32, quadratic, noscale, quadratic, quadratic
273+
)
274+
self.width_a: int = self.scale(
275+
"width_a", width_a, 32, linear, linear, noscale, linear
276+
)
277+
self.width_b: int = self.scale(
278+
"width_b", width_b, 32, linear, linear, noscale, linear
271279
)
272-
self.width_a: int = self.scale("width_a", width_a, 32, linear, linear, linear)
273-
self.width_b: int = self.scale("width_b", width_b, 32, linear, linear, linear)
274280

275-
@actionDynamicEnergy
276-
def multiply(self) -> float:
281+
@action
282+
def multiply(self) -> tuple[float, float]:
277283
"""
278-
Returns the energy for one multiplication operation in Joules.
284+
Returns the energy and latency for one multiplication operation.
279285
280286
Returns
281287
-------
282-
float
283-
The energy for one multiplication operation in Joules.
288+
(energy, latency): Tuple in (Joules, seconds).
284289
"""
285-
return 12.68e-12
290+
return 12.68e-12, 0.0
286291

287-
@actionDynamicEnergy
288-
def read(self) -> float:
292+
@action
293+
def read(self) -> tuple[float, float]:
289294
"""
290-
Returns the energy for one read operation in Joules.
295+
Returns the energy and latency for one read operation.
291296
292297
Returns
293298
-------
294-
float
295-
The energy for one read operation in Joules.
299+
(energy, latency): Tuple in (Joules, seconds).
296300
"""
297-
return 12.68e-12
301+
return 12.68e-12, 0.0
298302

299303

300304
# Original CSV contents:
@@ -323,35 +327,36 @@ def __init__(self, tech_node: float, width: int = 32):
323327
"tech_node",
324328
tech_node,
325329
40e-9,
326-
tech_node_energy,
327330
tech_node_area,
331+
tech_node_energy,
332+
noscale,
328333
tech_node_leak,
329334
)
330-
self.width: int = self.scale("width", width, 32, linear, linear, linear)
335+
self.width: int = self.scale(
336+
"width", width, 32, linear, linear, noscale, linear
337+
)
331338

332-
@actionDynamicEnergy
333-
def count(self) -> float:
339+
@action
340+
def count(self) -> tuple[float, float]:
334341
"""
335-
Returns the energy for one increment operation in Joules.
342+
Returns the energy and latency for one increment operation.
336343
337344
Returns
338345
-------
339-
float
340-
The energy for one increment operation in Joules.
346+
(energy, latency): Tuple in (Joules, seconds).
341347
"""
342-
return 0.25074e-12
348+
return 0.25074e-12, 0.0
343349

344-
@actionDynamicEnergy
345-
def read(self) -> float:
350+
@action
351+
def read(self) -> tuple[float, float]:
346352
"""
347-
Returns the energy for one increment operation in Joules.
353+
Returns the energy and latency for one increment operation.
348354
349355
Returns
350356
-------
351-
float
352-
The energy for one increment operation in Joules.
357+
(energy, latency): Tuple in (Joules, seconds).
353358
"""
354-
return 0.25074e-12
359+
return 0.25074e-12, 0.0
355360

356361

357362
class AladdinIntMAC(LibraryEstimatorClassBase):
@@ -382,38 +387,37 @@ def __init__(
382387
leak_power=self.adder.leak_power + self.multiplier.leak_power,
383388
)
384389

385-
@actionDynamicEnergy
386-
def mac(self) -> float:
390+
@action
391+
def mac(self) -> tuple[float, float]:
387392
"""
388-
Returns the energy for one multiply-accumulate operation in Joules.
393+
Returns the energy and latency for one multiply-accumulate operation.
389394
390395
Returns
391396
-------
392-
float
393-
The energy for one multiply-accumulate operation in Joules.
397+
(energy, latency): Tuple in (Joules, seconds).
394398
"""
395-
return self.adder.add() + self.multiplier.multiply()
399+
ae, al = self.adder.add()
400+
me, ml = self.multiplier.multiply()
401+
return ae + me, max(al, ml)
396402

397-
@actionDynamicEnergy
398-
def read(self) -> float:
403+
@action
404+
def read(self) -> tuple[float, float]:
399405
"""
400-
Returns the energy for one multiply-accumulate operation in Joules.
406+
Returns the energy and latency for one multiply-accumulate operation.
401407
402408
Returns
403409
-------
404-
float
405-
The energy for one multiply-accumulate operation in Joules.
410+
(energy, latency): Tuple in (Joules, seconds).
406411
"""
407412
return self.mac()
408413

409-
@actionDynamicEnergy
410-
def compute(self) -> float:
414+
@action
415+
def compute(self) -> tuple[float, float]:
411416
"""
412-
Returns the energy for one multiply-accumulate operation in Joules.
417+
Returns the energy and latency for one multiply-accumulate operation.
413418
414419
Returns
415420
-------
416-
float
417-
The energy for one multiply-accumulate operation in Joules.
421+
(energy, latency): Tuple in (Joules, seconds).
418422
"""
419423
return self.mac()

0 commit comments

Comments
 (0)