def emit_tuple_assignment(self, codegen_state, insn): ecm = codegen_state.expression_to_code_mapper from cgen import Assign, block_if_necessary assignments = [] for i, (assignee, parameter) in enumerate( zip(insn.assignees, insn.expression.parameters)): lhs_code = ecm(assignee, prec=PREC_NONE, type_context=None) assignee_var_name = insn.assignee_var_names()[i] lhs_var = codegen_state.kernel.get_var_descriptor( assignee_var_name) lhs_dtype = lhs_var.dtype from loopy.expression import dtype_to_type_context rhs_type_context = dtype_to_type_context( codegen_state.kernel.target, lhs_dtype) rhs_code = ecm(parameter, prec=PREC_NONE, type_context=rhs_type_context, needed_dtype=lhs_dtype) assignments.append(Assign(lhs_code, rhs_code)) return block_if_necessary(assignments)
def end_block(): if current_body: if current_cond is None: else_block[:] = self.map_statement_list(current_body) else: blocks_and_conds.append( (current_cond, cgen.block_if_necessary( self.map_statement_list(current_body)))) del current_body[:]
def emit_tuple_assignment(self, codegen_state, insn): ecm = codegen_state.expression_to_code_mapper from cgen import Assign, block_if_necessary assignments = [] for i, (assignee, parameter) in enumerate( zip(insn.assignees, insn.expression.parameters)): lhs_code = ecm(assignee, prec=PREC_NONE, type_context=None) assignee_var_name = insn.assignee_var_names()[i] lhs_var = codegen_state.kernel.get_var_descriptor(assignee_var_name) lhs_dtype = lhs_var.dtype from loopy.expression import dtype_to_type_context rhs_type_context = dtype_to_type_context( codegen_state.kernel.target, lhs_dtype) rhs_code = ecm(parameter, prec=PREC_NONE, type_context=rhs_type_context, needed_dtype=lhs_dtype) assignments.append(Assign(lhs_code, rhs_code)) return block_if_necessary(assignments)
def map_Do(self, node): scope = self.scope_stack[-1] body = self.map_statement_list(node.content) if node.loopcontrol: loop_var, loop_bounds = node.loopcontrol.split("=") loop_var = loop_var.strip() scope.use_name(loop_var) loop_bounds = [self.parse_expr(s) for s in loop_bounds.split(",")] if len(loop_bounds) == 2: start, stop = loop_bounds step = 1 elif len(loop_bounds) == 3: start, stop, step = loop_bounds else: raise RuntimeError("loop bounds not understood: %s" % node.loopcontrol) if not isinstance(step, int): print type(step) raise TranslationError( "non-constant steps not yet supported: %s" % step) if step < 0: comp_op = ">=" else: comp_op = "<=" return cgen.For( "%s = %s" % (loop_var, self.gen_expr(start)), "%s %s %s" % (loop_var, comp_op, self.gen_expr(stop)), "%s += %s" % (loop_var, self.gen_expr(step)), cgen.block_if_necessary(body)) else: raise NotImplementedError("unbounded do loop")
def block_or_none(body): if not body: return None else: return cgen.block_if_necessary(body)
'Calculate size of each step for dimension and time.'), c.Assign('dx', '(double)xSize / (double)xIntervals'), c.Assign('dy', '(double)ySize / (double)yIntervals'), c.Assign('dt', '(double)tTotal / (double)tIntervals'), c.Line(), c.Statement('printf("dx=%lf | dy=%lf | dt=%lf\\n", dx, dy, dt)'), c.Statement( 'printf("nx=%d | ny=%d | nT=%d | borders=%d\\n", xIntervals, yIntervals, tIntervals, BORDER_SIZE)' ), c.Line(), c.LineComment('Check CFL convergency conditions.'), c.If( 'dt / dx > 1 && dt / dy > 1', c.block_if_necessary([ c.Statement( 'cout << "Does not comply with CFL conditions." << endl' ), c.Statement('return -1') ])), c.Line(), c.Statement('ops_decl_const2("dx", 1, "double", &dx)'), c.Statement('ops_decl_const2("dy", 1, "double", &dy)'), c.Statement('ops_decl_const2("dt", 1, "double", &dt)'), c.Statement('ops_decl_const2("nx", 1, "double", &nx)'), c.Statement('ops_decl_const2("ny", 1, "double", &ny)'), c.Line(), c.Initializer( c.Value('int', 'range_CPML[]'), '{1 - BORDER_SIZE, xIntervals + BORDER_SIZE - 1, 1 - BORDER_SIZE, yIntervals + BORDER_SIZE - 1}' ), c.Initializer( c.Value('int', 'range_CPML_aux_1D_X_init[]'),