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

[TKW] Fix sympy expr lowering and add some more igemm test shapes #184

Merged
merged 17 commits into from
Oct 3, 2024

Conversation

Hardcode84
Copy link
Contributor

@Hardcode84 Hardcode84 commented Oct 2, 2024

  • Rework how we are lowering rational sympy expressions, instead of delayed materialization via lambdas introduce _Rational type and propagate numerator/denominator values independently. Division will only be materialized on explicit sympy.floor/ceiling op.
  • Rework how igemm test cases are generated and introduce few real shapes.
  • Use custom pytest markers to separate perf/non-perf tests

Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
This reverts commit 3efa309.

Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
@Hardcode84 Hardcode84 marked this pull request as ready for review October 2, 2024 14:35
@Hardcode84 Hardcode84 requested review from raikonenfnu and harsh-nod and removed request for raikonenfnu October 2, 2024 14:35
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
@Hardcode84
Copy link
Contributor Author

@harsh-nod @erman-gurses I found a way to separate perf/non-perf tests using custom markers, don't need any external files, see the updated files and --runperf option.

Signed-off-by: Ivan Butygin <[email protected]>
Copy link
Contributor

@harsh-nod harsh-nod left a comment

Choose a reason for hiding this comment

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

I really like the refactor of gen_sympy_index for Rationals. Thank you! Just some minor comments but otherwise looks g2g!

tests/conftest.py Outdated Show resolved Hide resolved
tests/conftest.py Show resolved Hide resolved
if isinstance(arg, arith_d.ConstantOp):
value = arg.attributes["value"]
if isinstance(value, IntegerAttr):
return int(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Throw error if it is not an int?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can actually encounter vector constants now, so this code is intended to fall through to the return None


stack.append(operation)
def muli_fold(lhs, rhs):
Copy link
Contributor

Choose a reason for hiding this comment

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

When does this come up? Is it when you are handling with cases like a * (1 / b) where you first do a * 1 and then divide by b? But wouldn't sympy convert that to a/b ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But wouldn't sympy convert that to a/b ?

I'm still seeing a bunch of muli %a, 1 without this, so apparently not. They are benign as they will be cleaned up later by canonicalizations, but it also means we will have to update all our codegen lit tests. With this early folding lit codegen IR is identical.

return value

def _group_rationals(stack, count):
rationals = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment explaining why we need non rationals first and then rationals? I am assuming that is the purpose of this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added comment

return arith_d.muli(lhs, rhs)

# `x + (a/b)` transformed into `(x*b + a) / b`
def _add(lhs, rhs):
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like the idea of the Rational and late materialization. It was a much better approach than our previous lambda based approach. Thanks!

Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
@Hardcode84 Hardcode84 merged commit 9ed388a into iree-org:main Oct 3, 2024
7 of 8 checks passed
@Hardcode84 Hardcode84 deleted the igemm_shapes branch October 3, 2024 15:28
stellaraccident pushed a commit that referenced this pull request Oct 13, 2024
* Rework how we are lowering `rational` sympy expressions, instead of
delayed materialization via lambdas introduce `_Rational` type and
propagate `numerator/denominator` values independently. Division will
only be materialized on explicit `sympy.floor/ceiling` op.
* Rework how igemm test cases are generated and introduce few real
shapes.
* Use custom pytest markers to separate perf/non-perf tests

---------

Signed-off-by: Ivan Butygin <[email protected]>
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.

2 participants