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

transformations: New test-add-timers-to-top-level-funcs pass #3407

Merged
merged 7 commits into from
Nov 8, 2024

Conversation

n-io
Copy link
Collaborator

@n-io n-io commented Nov 7, 2024

Adds timer_start() and timer_end() calls at the beginning and end of top-level functions, intended for testing and benchmarking purposes.

@n-io n-io added the transformations Changes or adds a transformatio label Nov 7, 2024
@n-io n-io self-assigned this Nov 7, 2024
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.16%. Comparing base (a731a28) to head (cc38fb8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3407   +/-   ##
=======================================
  Coverage   90.15%   90.16%           
=======================================
  Files         455      455           
  Lines       57429    57467   +38     
  Branches     5530     5532    +2     
=======================================
+ Hits        51775    51815   +40     
  Misses       4195     4195           
+ Partials     1459     1457    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

assert res == expected_res
for e in expected_res:
assert e in res
assert len(res) < len(all_passes)
Copy link
Collaborator Author

@n-io n-io Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has a dependency on get_all_passes(), calling get_available_pass_list() on its output, which may cause breaks when new passes are added. A better fix than the above would be to test get_all_passes separately, and to call get_available_pass_list() with a fixed list of passes, as it compares the result to a fixed list of expected available passes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with your change, and agree with your sentiment, if you have the bandwidth to fix this test then it would be welcome. In the meantime, could you please update the expected pass list instead?

Copy link
Collaborator Author

@n-io n-io Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with the method of testing this and the suggested temporary fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just fix the test today, it's been made much easier recently since Alex fixed the underlying infrastructure, thanks for providing a good reason to do it now rather than later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@n-io n-io Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks, I'm rolling back changes to this file in this PR.

assert res == expected_res
for e in expected_res:
assert e in res
assert len(res) < len(all_passes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with your change, and agree with your sentiment, if you have the bandwidth to fix this test then it would be welcome. In the meantime, could you please update the expected pass list instead?

@n-io n-io requested a review from superlopuh November 8, 2024 09:52
Comment on lines 88 to 104
all_funcs = [f for f in op.body.block.ops if isinstance(f, func.FuncOp)]
func_names = [f.sym_name.data for f in all_funcs]
if TIMER_START in func_names or TIMER_END in func_names:
return

start_func_t = func.FunctionType.from_lists([], [builtin.Float64Type()])
end_func_t = func.FunctionType.from_lists(
[builtin.Float64Type()], [builtin.Float64Type()]
)
start_func = func.FuncOp(TIMER_START, start_func_t, Region([]))
end_func = func.FuncOp(TIMER_END, end_func_t, Region([]))

PatternRewriteWalker(
AddBenchTimersPattern(start_func_t, end_func_t), apply_recursively=False
).rewrite_module(op)

op.body.block.add_ops((start_func, end_func))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend using SymbolTable APIs to look for functions and insert them:

xdsl/backend/riscv/lowering/convert_memref_to_riscv.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, I like this

Comment on lines +54 to +59
if (
not (top_level := op.parent_op())
or not isinstance(top_level, builtin.ModuleOp)
or top_level.parent
):
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not all functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently don't have a use case for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're looking at annotating top-level functions that are the equivalent of a main function. Should prob add a check that it's not being called. Don't think the SymbolTable API supports this though by any chance?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the name of the function to annotate be worth adding as a pass parameter? If it works with your flow it might be the easiest way to make it safe by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, let me come back to that after the deadline if alright

@n-io n-io requested a review from superlopuh November 8, 2024 15:10
@n-io n-io merged commit e150009 into main Nov 8, 2024
15 checks passed
@n-io n-io deleted the nicolai/test-annotate-funcs-with-bench-timers branch November 8, 2024 15:56
EdmundGoodman pushed a commit to EdmundGoodman/xdsl that referenced this pull request Dec 6, 2024
…ject#3407)

Adds `timer_start()` and `timer_end()` calls at the beginning and end of
top-level functions, intended for testing and benchmarking purposes.

---------

Co-authored-by: n-io <n-io@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
transformations Changes or adds a transformatio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants