Skip to content
Snippets Groups Projects
Commit 75b414b0 authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[Util] introduce calculate_matvec_accumulator_range

parent 5f1c3a31
No related branches found
No related tags found
No related merge requests found
......@@ -259,6 +259,33 @@ def pad_tensor_to_multiple_of(ndarray, pad_to_dims, val=0, distr_pad=False):
return ret
def calculate_matvec_accumulator_range(matrix, vec_dt):
"""Calculate the minimum and maximum possible result (accumulator) values
for a dot product x * A, given matrix A of dims (MW, MH), and vector (1, MW)
with datatype vec_dt. Returns (acc_min, acc_max).
"""
min_weight = matrix.min()
max_weight = matrix.max()
perceptive_field_elems = matrix.shape[0]
min_input = vec_dt.min()
max_input = vec_dt.max()
# calculate minimum and maximum values of accumulator
# assume inputs span the whole range of the input datatype
acc_min = perceptive_field_elems * min(
min_weight * max_input,
min_weight * min_input,
max_weight * max_input,
max_weight * min_input,
)
acc_max = perceptive_field_elems * max(
min_weight * max_input,
min_weight * min_input,
max_weight * max_input,
max_weight * min_input,
)
return (acc_min, acc_max)
def gen_finn_dt_tensor(finn_dt, tensor_shape):
"""Generates random tensor in given shape and with given FINN DataType."""
if type(tensor_shape) == list:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment