Skip to content

Commit

Permalink
Begin tackling the warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjward committed Nov 28, 2024
1 parent 86c4c44 commit 6d6a671
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
--install defcon \
--install gadopt \
--install asQ \
--package-branch loopy connorjward/merge-upstream \
|| (cat firedrake-install.log && /bin/false)
- name: Install test dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion pyop2/codegen/loopycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def map_subscript(self, expr):
flattened_index -= (int(stride) * ind)
new_indices.append(simplify_via_aff(ind))

return expr.aggregate.index(tuple(new_indices))
return expr.aggregate[tuple(new_indices)]


def _match_caller_callee_argument_dimension_for_single_kernel(
Expand Down
31 changes: 17 additions & 14 deletions pyop2/codegen/rep2loopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def runtime_indices(expressions):
for node in traversal(expressions):
if isinstance(node, RuntimeIndex):
indices.append(node.name)

return frozenset(indices)
# use a dict as an ordered set
return {i: None for i in indices}


def imperatives(exprs):
Expand Down Expand Up @@ -325,7 +325,7 @@ def loop_nesting(instructions, deps, outer_inames, kernel_name):

# boost inames, if one instruction is inside inner inames (free indices),
# it should be inside the outer inames as dictated by other instructions.
index_nesting = defaultdict(frozenset) # free index -> {runtime indices}
index_nesting = defaultdict(dict) # free index -> {runtime indices}
for insn in instructions:
if isinstance(insn, When):
key = insn.children[1]
Expand All @@ -338,7 +338,7 @@ def loop_nesting(instructions, deps, outer_inames, kernel_name):
for insn in imperatives(instructions):
outer = reduce(operator.or_,
iter(index_nesting[fi] for fi in traversal([insn]) if isinstance(fi, Index)),
frozenset())
{})
nesting[insn] = nesting[insn] | outer

return nesting
Expand Down Expand Up @@ -407,11 +407,10 @@ def generate(builder, wrapper_name=None):
Materialise._count = itertools.count()
RuntimeIndex._count = itertools.count()

# use a dict as an ordered set
outer_inames = {builder._loop_index.name: None}
if builder.layer_index is not None:
outer_inames = frozenset([builder._loop_index.name,
builder.layer_index.name])
else:
outer_inames = frozenset([builder._loop_index.name])
outer_inames |= {builder.layer_index.name: None}

instructions = list(builder.emit_instructions())

Expand Down Expand Up @@ -476,10 +475,17 @@ def renamer(expr):
deps = instruction_dependencies(instructions, mapper.initialisers)
within_inames = loop_nesting(instructions, deps, outer_inames, parameters.kernel_name)

# used to avoid disadvantageous loop interchanges
loop_priorities = set()
for iname_nest in within_inames.values():
if len(iname_nest) > 1:
loop_priorities.add(tuple(iname_nest.keys()))
loop_priorities = frozenset(loop_priorities)

# generate loopy
context = Bag()
context.parameters = parameters
context.within_inames = within_inames
context.within_inames = {k: frozenset(v.keys()) for k, v in within_inames.items()}
context.conditions = []
context.index_ordering = []
context.instruction_dependencies = deps
Expand Down Expand Up @@ -544,11 +550,8 @@ def renamer(expr):
options=options,
assumptions=assumptions,
lang_version=(2018, 2),
name=wrapper_name)

# prioritize loops
for indices in context.index_ordering:
wrapper = loopy.prioritize_loops(wrapper, indices)
name=wrapper_name,
loop_priority=loop_priorities)

# register kernel
kernel = builder.kernel
Expand Down

0 comments on commit 6d6a671

Please sign in to comment.