Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.model = model
self.name = name
self.index = model.next_layer()
self.inputs = inputs
self.outputs = outputs
if self.outputs is None:
self.outputs = [self.name]
self.attributes = attributes
self._function_template = get_function_template(self.__class__.__name__)
self._config_template = get_config_template(self.__class__.__name__)
self.weights = OrderedDict()
self.variables = OrderedDict()
self.precision = OrderedDict()
accum_t = HLSType(*reversed(self.model.config.get_precision(self, 'accum')))
self.precision[accum_t.name] = accum_t
self.set_attr('accum_t', accum_t.precision)
self.initialize()
def __init__(self, var_name, type_name, precision, **kwargs):
self.name = var_name.format(**kwargs)
self.type = HLSType(type_name, precision, **kwargs)
self.cppname = re.sub(r'\W|^(?=\d)','_', self.name)
for out in self.outputs:
variables.append(self.output_vars[out])
return variables
def get_layer_output_variable(self, output_name):
return self.output_vars[output_name]
class HLSType(object):
def __init__(self, name, precision, **kwargs):
self.name = name.format(**kwargs)
self.precision = precision
def definition_cpp(self):
return 'typedef {precision} {name};\n'.format(name=self.name, precision=self.precision)
class CompressedType(HLSType):
def __init__(self, name, precision, index_precision, **kwargs):
super(CompressedType, self).__init__('compressed_type{index}', precision, **kwargs)
self.index_precision = index_precision
def definition_cpp(self):
cpp_fmt = ('typedef struct {name} {{ '
'{index} row_index; '
'{index} col_index; '
'{precision} weight; }} {name};\n')
return cpp_fmt.format(name=self.name, index=self.index_precision, precision=self.precision)
class Variable(object):
def __init__(self, var_name, type_name, precision, **kwargs):
self.name = var_name.format(**kwargs)
self.type = HLSType(type_name, precision, **kwargs)
self.cppname = re.sub(r'\W|^(?=\d)','_', self.name)