diff --git a/loopy/codegen/__init__.py b/loopy/codegen/__init__.py index df65c43a23a00ae82246bc80655bbd0feb5fd14e..549ddb321cffd71a165b195ccb74a24359402e7c 100644 --- a/loopy/codegen/__init__.py +++ b/loopy/codegen/__init__.py @@ -131,8 +131,7 @@ class CodeGenerationState(object): def fix(self, iname, aff, space): from loopy.isl_helpers import iname_rel_aff - iname_plus_lb_aff = iname_rel_aff( - space, iname, "==", aff) + iname_plus_lb_aff = iname_rel_aff(space, iname, "==", aff) from loopy.symbolic import pw_aff_to_expr cns = isl.Constraint.equality_from_aff(iname_plus_lb_aff) diff --git a/loopy/codegen/instruction.py b/loopy/codegen/instruction.py index fd50850c91215133a517def805765eb6f3698f8f..e67898ebdaad798808d7f722511c77140fe25831 100644 --- a/loopy/codegen/instruction.py +++ b/loopy/codegen/instruction.py @@ -22,18 +22,21 @@ class ILPInstance(Record): ilp_key=ilp_key) def fix(self, iname, aff): - dt, pos = aff.get_space().get_var_dict()[iname] - iname_plus_lb_aff = aff.add_coefficient( - dt, pos, -1) + from loopy.isl_helpers import iname_rel_aff + iname_plus_lb_aff = iname_rel_aff( + self.implemented_domain.get_space(), iname, "==", aff) from loopy.symbolic import pw_aff_to_expr - cns = isl.Constraint.equality_from_aff(iname_plus_lb_aff) expr = pw_aff_to_expr(aff) + cns = isl.Constraint.equality_from_aff(iname_plus_lb_aff) + + new_assignments = self.assignments.copy() + new_assignments[iname] = expr return ILPInstance( implemented_domain=self.implemented_domain.add_constraint(cns), - c_code_mapper=self.c_code_mapper.copy_and_assign(iname, expr), - ilp_key=self.ilp_key | frozenset([(iname, expr)])) + assignments=new_assignments, + ilp_key=self.ilp_key | set([(iname, expr)])) # }}} @@ -55,8 +58,26 @@ def generate_ilp_instances(kernel, insn, codegen_state): if not isinstance(tag, IlpTag): continue - from warnings import warn - warn("implement ILP instance generation") + + bounds = kernel.get_iname_bounds(iname) + + from loopy.isl_helpers import ( + static_max_of_pw_aff, static_value_of_pw_aff) + from loopy.symbolic import pw_aff_to_expr + + length = int(pw_aff_to_expr( + static_max_of_pw_aff(bounds.size, constants_only=True))) + lower_bound_aff = static_value_of_pw_aff( + bounds.lower_bound_pw_aff.coalesce(), + constants_only=False) + + new_result = [] + for ilpi in result: + for i in range(length): + idx_aff = lower_bound_aff + i + new_result.append(ilpi.fix(iname, idx_aff)) + + result = new_result # }}} diff --git a/loopy/codegen/loop.py b/loopy/codegen/loop.py index 3e5d484aeb987b24b5feaf7a51438db0682d8925..f050b4b20002d6232c1791e2fdd8c44ff6b66320 100644 --- a/loopy/codegen/loop.py +++ b/loopy/codegen/loop.py @@ -129,6 +129,7 @@ def generate_unroll_loop(kernel, sched_index, codegen_state): tag = kernel.iname_to_tag.get(iname) bounds = kernel.get_iname_bounds(iname) + from loopy.isl_helpers import ( static_max_of_pw_aff, static_value_of_pw_aff) from loopy.symbolic import pw_aff_to_expr