コード例 #1
0
 def convert_precision_string(self, precision):
     '''
     Convert a precision string (e.g. "ap_fixed<16,6>" to the internal IntegerPrecisionTypes etc)
     '''
     from hls4ml.model.hls_layers import IntegerPrecisionType, FixedPrecisionType
     import re
     if isinstance(precision, IntegerPrecisionType) or isinstance(
             precision, FixedPrecisionType):
         return precision
     bits = re.search('.+<(.+?)>', precision).group(1).split(',')
     sat_mode = None
     round_mode = None
     sat_bits = None
     if 'fixed' in precision:
         W = int(bits[0])
         I = int(bits[1])
         fields = 2
         signed = not ('u' in precision)
     elif 'int' in precision:
         W = int(bits[0])
         I = W
         fields = 1
         signed = not ('u' in precision)
     if len(bits) > fields:
         round_mode = bits[fields]
     if len(bits) > fields + 1:
         sat_mode = bits[fields + 1]
     if len(bits) > fields + 2:
         sat_bits = int(bits[fields + 2])
     if 'fixed' in precision:
         return FixedPrecisionType(W, I, signed, round_mode, sat_mode,
                                   sat_bits)
     elif 'int' in precision:
         return IntegerPrecisionType(W, signed)
コード例 #2
0
 def _next_factor8_type(self, p):
     ''' Return a new type with the width rounded to the next factor of 8 up to p's width
         Args:
             p : IntegerPrecisionType or FixedPrecisionType
         Returns:
             An IntegerPrecisionType or FixedPrecisionType with the width rounder up to the next factor of 8
             of p's width. Other parameters (fractional bits, extra modes) stay the same.
     '''
     W = p.width
     newW = int(np.ceil(W / 8) * 8)
     if isinstance(p, FixedPrecisionType):
         return FixedPrecisionType(newW, p.integer, p.signed, p.rounding_mode, p.saturation_mode,
                                   p.saturation_bits)
     elif isinstance(p, IntegerPrecisionType):
         return IntegerPrecisionType(newW, p.signed)