Skip to content

Commit 913c146

Browse files
committed
Set accum_t to input tensor precision if not set
1 parent 8433695 commit 913c146

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

hls4ml/model/hls_layers.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,24 @@ def __init__(self, model, name, attributes, inputs, outputs=None):
360360
self.weights = OrderedDict()
361361
self.variables = OrderedDict()
362362
self.precision = OrderedDict()
363-
accum_t = HLSType(*reversed(self.model.config.get_precision(self, 'accum')))
363+
364+
# We set 'accum' precision to match input tensor's precision if 'accum' was not explicitly set
365+
def_type_obj, _ = self.model.config.get_precision(self, 'default')
366+
acc_type_obj, acc_type_name = self.model.config.get_precision(self, 'accum')
367+
368+
inp = self.get_input_variable()
369+
if inp is not None:
370+
inp_type_obj = inp.type.precision
371+
else:
372+
inp_type_obj = def_type_obj
373+
374+
if acc_type_obj == def_type_obj: # 'accum' precision not defined in config
375+
acc_type_obj = inp_type_obj # use input tensor's precision for 'accum'
376+
377+
accum_t = HLSType(acc_type_name, acc_type_obj)
364378
self.precision[accum_t.name] = accum_t
365379
self.set_attr('accum_t', accum_t.precision)
380+
366381
self.reuse_factor = self.model.config.get_reuse_factor(self)
367382

368383
layer_config = self.model.config.get_layer_config(self)

hls4ml/model/hls_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def get_output_variables(self):
439439
return variables
440440

441441
def get_layer_output_variable(self, output_name):
442-
return self.output_vars[output_name]
442+
return self.output_vars.get(output_name, None)
443443

444444
def write(self):
445445
def make_stamp():

0 commit comments

Comments
 (0)