示例#1
0
 def test_haoda_type_of_input_stmts_different_with_output(self):
   args = {**self.blur.__dict__, **{'replication_factor': 1}}
   input_stmt = copy.copy(self.input_stmt)
   input_stmt.haoda_type = ir.Type('half')
   args['input_stmts'] = [input_stmt]
   with self.assertRaises(util.SemanticError) as context:
     core.Stencil(**args)
   self.assertEqual(str(context.exception),
     'input must have the same type(s) as output if iterate > 1 times, '
     'current input has type [half] but output has type [uint16]')
示例#2
0
文件: core.py 项目: Ruola/haoda
 def haoda_type(self, val: Union[None, str, ir.Type]) -> None:
     if val is None:
         self._haoda_type = None
     elif isinstance(val, str):
         self._haoda_type = ir.Type(val)
     elif isinstance(val, ir.Type):
         self._haoda_type = val
     else:
         raise ValueError(
             'haoda_type must be set from an instance of NoneType, str, '
             'or haoda.ir.Type, got %s' % type(val))
示例#3
0
 def setUp(self):
   self.ref = ir.Ref(name='foo', idx=(0, 23), lat=None)
   self.expr_ref = ir.Ref(name='bar', idx=(233, 42), lat=None)
   self.int8 = ir.Type('int8')
   self.expr_ref.haoda_type = self.int8
   self.expr = ir.Expr(operand=(self.expr_ref,), operator=())
   self.let_ref = ir.Ref(name='bar_l', idx=(42, 2333), lat=None)
   self.let_expr = ir.Expr(operand=(self.let_ref,), operator=())
   self.let = ir.Let(haoda_type=self.int8, name='foo_l', expr=self.let_expr)
   self.let_ref2 = ir.Ref(name='bar_l2', idx=(0, 42), lat=None)
   self.let_expr2 = ir.Expr(operand=(self.let_ref2,), operator=())
   self.let2 = ir.Let(haoda_type=self.int8, name='foo_l2', expr=self.let_expr2)
示例#4
0
  def setUp(self):
    self.tile_size = [233, 0]
    self.haoda_type = ir.Type('uint16')
    self.unroll_factor = 1
    self.expr_ref = ir.Ref(name='foo', idx=(233, 42), lat=None)
    self.expr = ir.Expr(operand=(self.expr_ref,), operator=())
    self.input_stmt = grammar.InputStmt(
        haoda_type=self.haoda_type, name='foo_i', tile_size=self.tile_size,
        dram=())
    self.param_stmt = grammar.ParamStmt(
        haoda_type=self.haoda_type, name='foo_p', attr=(), size=(), dram=())
    self.local_ref = ir.Ref(name='foo_l', idx=(0, 0), lat=None)
    self.local_stmt = grammar.LocalStmt(
      haoda_type=self.haoda_type, let=(), ref=self.local_ref, expr=self.expr)
    self.output_ref = ir.Ref(name='foo_o', idx=(0, 0), lat=None)
    self.output_stmt = grammar.OutputStmt(
      haoda_type=self.haoda_type, let=(), ref=self.output_ref, expr=self.expr,
      dram=())
    self.args = {
      'burst_width': 512,
      'border': 'ignore',
      'iterate': 2,
      'cluster': 'none',
      'app_name': 'foo_bar',
      'input_stmts': [self.input_stmt],
      'param_stmts': [self.param_stmt],
      'local_stmts': [self.local_stmt],
      'output_stmts': [self.output_stmt],
      'dim': len(self.tile_size),
      'tile_size': self.tile_size,
      'unroll_factor': self.unroll_factor,
      'replication_factor': self.unroll_factor}
    self.soda_mm = textx.metamodel_from_str(
      grammar.GRAMMAR, classes=grammar.CLASSES)
    self.blur = self.soda_mm.model_from_str(
r'''
kernel: blur
burst width: 512
unroll factor: 16
input uint16: input(2000, *)
local uint16: tmp(0,0)=(input(-1,0)+input(0,0)+input(1,0))/3
output uint16: output(0,0)=(tmp(0,-1)+tmp(0,0)+tmp(0,1))/3
iterate: 2
border: preserve
cluster: none
''')
    args = {**self.blur.__dict__, **{'replication_factor': 1}}
    self.stencil = core.Stencil(**args)
示例#5
0
文件: core.py 项目: Ruola/haoda
 def _get_haoda_type(self):
     for attr in self.ATTRS:
         val = getattr(self, attr)
         if val is not None:
             if hasattr(val, 'haoda_type'):
                 return ir.Type(val.haoda_type)
             if attr == 'num':
                 if 'u' in val.lower():
                     if 'll' in val.lower():
                         return ir.Type('uint64')
                     return ir.Type('uint32')
                 if 'll' in val.lower():
                     return ir.Type('int64')
                 if 'fl' in val.lower():
                     return ir.Type('double')
                 if 'f' in val.lower() or 'e' in val.lower():
                     return ir.Type('float')
                 if '.' in val:
                     return ir.Type('double')
                 return ir.Type('int32')
             return None
     raise util.InternalError('undefined Operand')
示例#6
0
文件: core.py 项目: Ruola/haoda
 def ptr_type(self):
     return ir.Type('uint%d' % int(math.log2(self.delay) + 1))
示例#7
0
    stencil.__dict__.pop('symbol_table', None)
    stencil.__dict__.pop('local_names', None)
    stencil.__dict__.pop('local_types', None)

    for stmt in itertools.chain(stencil.local_stmts, stencil.output_stmts):
        _logger.debug('simplify  : %s', stmt)
        stmt.expr = arithmetic.simplify(
            arithmetic.base.reverse_distribute(stmt.expr))
        stmt.let = arithmetic.simplify(
            tuple(map(arithmetic.base.reverse_distribute, stmt.let)))
        _logger.debug('simplified:  %s', stmt)
    return inline2(stencil)


REBALANCE_THRESHOLDS = {
    ir.Type('float'): 32,
}


def rebalance(stencil):
    """Rebalance the generated code to improve codegen speed.

  This function modifies stencil in-place. Long reduction expressions will be
  divided into groups based on the number of operations. The thresholds are
  defined in REBALANCE_THRESHOLDS.

  Arg:
    stencil: The Stencil object to modify.
  Returns:
    The modified Stencil object.
  """