Skip to content

Commit 6fcea3a

Browse files
committed
util/sim: Add TCDM validation function to data_utils.py
1 parent ee591d7 commit 6fcea3a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

util/sim/data_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import torch
1515
import numpy as np
1616
import pyflexfloat as ff
17+
import humanize
18+
19+
# Maximum available size in TCDM (in bytes)
20+
TCDM_HEAP_SIZE = 112 * 1024
1721

1822

1923
def emit_license():
@@ -295,3 +299,20 @@ def main(self):
295299
# Emit header file
296300
with open(args.output, 'w') as f:
297301
f.write(self.emit_header(**param))
302+
303+
304+
def validate_tcdm_footprint(size, silent=False):
305+
"""Check whether data of specified size fits in TCDM.
306+
307+
Throws an assertion error if the specified size exceeds the space
308+
available for the heap in TCDM.
309+
310+
Args:
311+
size: The size of the data in bytes.
312+
silent: If True, will not print the size to stdout.
313+
"""
314+
assert size < TCDM_HEAP_SIZE, \
315+
f'Total heap space required {humanize.naturalsize(size, binary=True)} exceeds ' \
316+
f'limit of {humanize.naturalsize(L1_HEAP_SIZE, binary=True)}'
317+
if not silent:
318+
print(f'Total heap space required {humanize.naturalsize(size, binary=True)}')

0 commit comments

Comments
 (0)