Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start converting LoopIR_scheduling to cursors architecture #311

Merged
merged 5 commits into from
Jan 31, 2023

Conversation

alexreinking
Copy link
Contributor

Converts the _DoFuseLoop Cursor_Rewrite class into a true cursor-based implementation. The diff is hard to read, so I'll paste the final code here:

def DoFuseLoop(proc_cursor, f_cursor, s_cursor):
    proc = proc_cursor._node()
    loop1 = f_cursor._node()
    loop2 = s_cursor._node()

    if f_cursor.next() != s_cursor:
        raise SchedulingError(
            "expected the two loops to be fused to come one right after the other"
        )

    # check if the loop bounds are equivalent
    Check_ExprEqvInContext(proc, loop1.hi, [loop1], loop2.hi, [loop2])

    x = LoopIR.Read(loop1.iter, [], T.index, loop1.srcinfo)
    y = loop2.iter
    body1 = loop1.body
    body2 = SubstArgs(loop2.body, {y: x}).result()

    proc, fwd1 = f_cursor.body()[-1].after()._insert(body2)
    proc, fwd2 = fwd1(s_cursor)._delete()
    loop = fwd2(fwd1(f_cursor))._node()

    Check_FissionLoop(proc._loopir_proc, loop, body1, body2)
    proc = InferEffects(proc._loopir_proc).result()
    return api.Procedure(proc, _provenance_eq_Procedure=proc_cursor.proc())

Note the important bit that models this edit as inserting the (substituted) body of the second loop to the end of the first loop, and then deletes the second loop altogether. This could perhaps be improved by using the following strategy:

  1. Move the body of the second loop to the end of the first loop
  2. Go through those nodes and replace the argument names where necessary

(2) can be accomplished by making SubstArgs cursor-y.

Still TODO:

  • Add forwarding information to the final Procedures.

There's a bit of code clean-up here, too, to make this whole process saner:

  1. LoopIR_Rewrite no longer has an __init__ function or remembers the proc it was called on. This should really just be a visitor class and allow us to rewrite expressions or statements without the full context of a proc.
  2. Where possible, the pattern of SomeClass(...).result() should be replaced by SomeFunction(...) when there is no reason to separate setting up the task from running it.
  3. Use the normal Python __all__ export mechanism in place of the Schedules class.

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2023

Codecov Report

Merging #311 (82133a9) into master (6cc4596) will decrease coverage by 0.04%.
The diff coverage is 96.50%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master     #311      +/-   ##
==========================================
- Coverage   86.20%   86.17%   -0.04%     
==========================================
  Files          73       73              
  Lines       16677    16625      -52     
==========================================
- Hits        14377    14327      -50     
+ Misses       2300     2298       -2     
Impacted Files Coverage Δ
src/exo/LoopIR.py 93.72% <0.00%> (-0.05%) ⬇️
src/exo/win_analysis.py 96.66% <0.00%> (+2.38%) ⬆️
src/exo/API_scheduling.py 86.38% <95.65%> (+0.01%) ⬆️
src/exo/LoopIR_scheduling.py 89.82% <98.55%> (-0.20%) ⬇️
src/exo/API.py 74.89% <100.00%> (+0.10%) ⬆️
src/exo/LoopIR_compiler.py 94.92% <100.00%> (+0.54%) ⬆️
src/exo/LoopIR_unification.py 81.38% <100.00%> (+0.05%) ⬆️
src/exo/internal_cursors.py 94.97% <100.00%> (+0.02%) ⬆️
src/exo/mem_analysis.py 95.31% <100.00%> (+0.03%) ⬆️
src/exo/prec_analysis.py 77.55% <100.00%> (+0.46%) ⬆️
... and 3 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

# Conflicts:
#	src/exo/API_scheduling.py
#	src/exo/LoopIR_scheduling.py
#	src/exo/LoopIR_unification.py
@alexreinking alexreinking enabled auto-merge (squash) January 31, 2023 23:02
@alexreinking alexreinking merged commit 6972f84 into master Jan 31, 2023
@alexreinking alexreinking deleted the cursor/directives branch January 31, 2023 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants