def to_codegen_result( codegen_state, insn_id, domain, check_inames, required_preds, ast): from loopy.codegen.bounds import get_bounds_checks from loopy.symbolic import constraint_to_expr bounds_checks = get_bounds_checks( domain, check_inames, codegen_state.implemented_domain, overapproximate=False) bounds_check_set = isl.Set.universe(domain.get_space()) \ .add_constraints(bounds_checks) bounds_check_set, new_implemented_domain = isl.align_two( bounds_check_set, codegen_state.implemented_domain) new_implemented_domain = new_implemented_domain & bounds_check_set if bounds_check_set.is_empty(): return None condition_exprs = [ constraint_to_expr(cns) for cns in bounds_checks] condition_exprs.extend( required_preds - codegen_state.implemented_predicates) if condition_exprs: from pymbolic.primitives import LogicalAnd from pymbolic.mapper.stringifier import PREC_NONE ast = codegen_state.ast_builder.emit_if( codegen_state.expression_to_code_mapper( LogicalAnd(tuple(condition_exprs)), PREC_NONE), ast) return CodeGenerationResult.new( codegen_state, insn_id, ast, new_implemented_domain)
def to_codegen_result(codegen_state, insn_id, domain, check_inames, required_preds, ast): from loopy.codegen.bounds import get_bounds_checks from loopy.symbolic import constraint_to_expr bounds_checks = get_bounds_checks(domain, check_inames, codegen_state.implemented_domain, overapproximate=False) bounds_check_set = isl.Set.universe(domain.get_space()) \ .add_constraints(bounds_checks) bounds_check_set, new_implemented_domain = isl.align_two( bounds_check_set, codegen_state.implemented_domain) new_implemented_domain = new_implemented_domain & bounds_check_set if bounds_check_set.is_empty(): return None condition_exprs = [constraint_to_expr(cns) for cns in bounds_checks] condition_exprs.extend(required_preds - codegen_state.implemented_predicates) if condition_exprs: from pymbolic.primitives import LogicalAnd from pymbolic.mapper.stringifier import PREC_NONE ast = codegen_state.ast_builder.emit_if( codegen_state.expression_to_code_mapper( LogicalAnd(tuple(condition_exprs)), PREC_NONE), ast) return CodeGenerationResult.new(codegen_state, insn_id, ast, new_implemented_domain)
def wrap_in_conditionals(codegen_state, domain, check_inames, required_preds, stmt): from loopy.codegen.bounds import get_bounds_checks, constraint_to_code bounds_checks = get_bounds_checks( domain, check_inames, codegen_state.implemented_domain, overapproximate=False) bounds_check_set = isl.Set.universe(domain.get_space()) \ .add_constraints(bounds_checks) bounds_check_set, new_implemented_domain = isl.align_two( bounds_check_set, codegen_state.implemented_domain) new_implemented_domain = new_implemented_domain & bounds_check_set if bounds_check_set.is_empty(): return None, None condition_codelets = [ constraint_to_code( codegen_state.expression_to_code_mapper, cns) for cns in bounds_checks] condition_codelets.extend( required_preds - codegen_state.implemented_predicates) if condition_codelets: from cgen import If stmt = If("\n&& ".join(condition_codelets), stmt) return stmt, new_implemented_domain
def __call__(self, check_inames): if not check_inames: return [] domain = isl.align_spaces( self.kernel.get_inames_domain(check_inames), self.impl_domain, obj_bigger_ok=True) from loopy.codegen.bounds import get_bounds_checks return get_bounds_checks(domain, check_inames, self.impl_domain, # Each instruction individually gets its bounds checks, # so we can safely overapproximate here. overapproximate=True)
def __call__(self, check_inames): if not check_inames: return [] domain = isl.align_spaces( self.kernel.get_inames_domain(check_inames), self.impl_domain, obj_bigger_ok=True) from loopy.codegen.bounds import get_bounds_checks return get_bounds_checks( domain, check_inames, self.impl_domain, # Each instruction individually gets its bounds checks, # so we can safely overapproximate here. overapproximate=True)