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

dialects: (riscv) add fastmath flag to RdRsRs Float Float Int operations #3276

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

knickish
Copy link
Contributor

riscv-only part of #3272, with a new dialect test added. Thanks for the suggestion of separate tests, I didn't realize those existed and caught an error in the LiOp implementation while adding the test cases.

@knickish knickish force-pushed the riscv_cmpf_fastmath branch from 3e230b3 to 1af6acd Compare October 10, 2024 01:45
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.01%. Comparing base (f2ba5f7) to head (729668d).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3276   +/-   ##
=======================================
  Coverage   90.01%   90.01%           
=======================================
  Files         445      445           
  Lines       55850    55926   +76     
  Branches     5372     5358   -14     
=======================================
+ Hits        50272    50341   +69     
- Misses       4169     4177    +8     
+ Partials     1409     1408    -1     

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

@@ -2491,6 +2491,7 @@ class LiOp(RISCVInstruction, ABC):

rd = result_def(IntRegisterType)
immediate = attr_def(base(Imm32Attr) | base(LabelAttr))
fastmath = opt_attr_def(FastMathFlagsAttr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a specific reason this is an attribute here where it was a property on the other PR?

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 changing to a property here

@@ -2527,12 +2530,19 @@ def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
attributes = dict[str, Attribute]()
attributes["immediate"] = parse_immediate_value(parser, i32)
fast = FastMathFlagsAttr("none")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this flag meant to be optional? It seems you can't parse it with the flag unset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As on the other PR, it's not meant to be optional, op_prop_def just doesn't actually use the default parameter at all, so parsing fails when it's set as a non-opt prop_def

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 making it non-optional, and to do the default value handling manually. What's the error when you change the declaration to prop_def?

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is more a question for the equivalent line below, if we're removing the LiOp changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

# |     raise VerifyException(f"property {prop_name} expected")
# | xdsl.utils.exceptions.VerifyException: property fastmath expected

That's the error I get, even with setting a default via `fastmath = prop_def(FastMathFlagsAttr, default=FastMathFlagsAttr("none")) (which also doesn't typecheck)

Copy link
Member

Choose a reason for hiding this comment

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

yep, the default field here doesn't work. I think @alexarice is now looking into this, but for the time being we can just set it directly in the init and in the custom parser. So all that would be necessary in this PR is to change opt_prop_def to prop_def

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just pushed a commit that does exactly that, but it's failing the filecheck test with the same error as above. Is there something else I need to do ? I am setting the fastmath property in both the parse and init methods

rd = result_def(IntRegisterType)
rs1 = operand_def(FloatRegisterType)
rs2 = operand_def(FloatRegisterType)
fastmath = opt_attr_def(FastMathFlagsAttr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar comments here about attr/prop and this being optional

xdsl/dialects/riscv.py Show resolved Hide resolved
@alexarice alexarice added the dialects Changes on the dialects label Oct 10, 2024
@alexarice alexarice requested a review from superlopuh October 10, 2024 09:15
@@ -2491,6 +2491,7 @@ class LiOp(RISCVInstruction, ABC):

rd = result_def(IntRegisterType)
immediate = attr_def(base(Imm32Attr) | base(LabelAttr))
fastmath = opt_attr_def(FastMathFlagsAttr)
Copy link
Member

Choose a reason for hiding this comment

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

What is the semantics change of li being optionally fastmath?

Copy link
Member

Choose a reason for hiding this comment

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

Probably worth documenting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I spent a while trying to find any information on this, and I'm not seeing that there is any actual effect on the li instr at all when compiled with fastmath. Chapter 15. Load Immediate of the riscv-asm-manual doesn't mention fastmath at all, and godbolt doesn't seem to show any difference when compiled with/without -ffast-math.

Is there anywhere else that I should look for information on this? If not, should I go ahead and remove the fastmath attribute from LiOp?

Copy link
Member

Choose a reason for hiding this comment

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

I also don't know how it would affect anything. I don't think arith.constant can have fastmath, can it? It seems safe to remove from this PR, and add it later if we find a way to leverage it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed it now, and rebased everything into one commit since it was getting messy

@knickish
Copy link
Contributor Author

knickish commented Oct 10, 2024

Ok thanks, will do this stuff this evening hopefully

Need to:

  • Make fastmath a property rather than attribute on both op types
  • Document semantic changes to LiOp now that it has the optional fastmath property

@knickish knickish requested a review from superlopuh October 12, 2024 18:28
@knickish knickish force-pushed the riscv_cmpf_fastmath branch from 52a5eaa to 7e647e4 Compare October 14, 2024 16:21
@knickish knickish changed the title add fastmath flag to Li and RdRsRs Float Float Int operations add fastmath flag to RdRsRs Float Float Int operations Oct 14, 2024
@knickish knickish force-pushed the riscv_cmpf_fastmath branch from 7e647e4 to 6474cd1 Compare October 14, 2024 16:29
xdsl/dialects/riscv.py Outdated Show resolved Hide resolved
xdsl/dialects/riscv.py Outdated Show resolved Hide resolved
@knickish knickish force-pushed the riscv_cmpf_fastmath branch from 11cebbd to 729668d Compare October 14, 2024 23:38
Copy link
Member

@superlopuh superlopuh left a comment

Choose a reason for hiding this comment

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

Thank you!

@superlopuh superlopuh changed the title add fastmath flag to RdRsRs Float Float Int operations dialects: (riscv) add fastmath flag to RdRsRs Float Float Int operations Oct 15, 2024
@superlopuh superlopuh merged commit a7d8ebe into xdslproject:main Oct 15, 2024
14 checks passed
superlopuh added a commit that referenced this pull request Oct 23, 2024
`backend`(lowering)-only part of
#3272. Depends on #3275 and
#3276.

This should close #2725 once merged

Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
EdmundGoodman pushed a commit to EdmundGoodman/xdsl that referenced this pull request Dec 6, 2024
…ons (xdslproject#3276)

`riscv`-only part of xdslproject#3272, with
a new dialect test added. Thanks for the suggestion of separate tests, I
didn't realize those existed and caught an error in the LiOp
implementation while adding the test cases.
EdmundGoodman pushed a commit to EdmundGoodman/xdsl that referenced this pull request Dec 6, 2024
`backend`(lowering)-only part of
xdslproject#3272. Depends on xdslproject#3275 and
xdslproject#3276.

This should close xdslproject#2725 once merged

Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants