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

interpreter: add cast mechanism #1264

Merged
merged 3 commits into from Jul 15, 2023
Merged

interpreter: add cast mechanism #1264

merged 3 commits into from Jul 15, 2023

Conversation

superlopuh
Copy link
Member

No description provided.

@superlopuh superlopuh added the interpreter xDSL Interpreter label Jul 12, 2023
@superlopuh superlopuh self-assigned this Jul 12, 2023
@superlopuh superlopuh marked this pull request as ready for review July 12, 2023 17:42
@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Patch coverage: 95.29% and project coverage change: +0.08 🎉

Comparison is base (a6c78eb) 89.05% compared to head (c40e139) 89.14%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1264      +/-   ##
==========================================
+ Coverage   89.05%   89.14%   +0.08%     
==========================================
  Files         179      182       +3     
  Lines       23916    24154     +238     
  Branches     3628     3679      +51     
==========================================
+ Hits        21299    21532     +233     
- Misses       2040     2042       +2     
- Partials      577      580       +3     
Impacted Files Coverage Δ
xdsl/interpreter.py 86.63% <90.00%> (+0.60%) ⬆️
tests/test_interpreter.py 100.00% <100.00%> (ø)
xdsl/interpreters/builtin.py 100.00% <100.00%> (ø)

... and 15 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines +8 to +19
class BuiltinFunctions(InterpreterFunctions):
@impl(UnrealizedConversionCastOp)
def run_cast(
self,
interpreter: Interpreter,
op: UnrealizedConversionCastOp,
args: tuple[Any, ...],
):
return tuple(
interpreter.cast_value(o.type, r.type, arg)
for (o, r, arg) in zip(op.operands, op.results, args)
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice to have a test case for this one!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes you're right

Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

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

I have to say, I'm not sure that this is the right approach (but maybe I'm overlooking something).
Is there a reason why we have a special cast mechanism in place, when we could just have the UnrealizedConversionCast interpreter implementation? What do we gain from adding this complexity?

@superlopuh
Copy link
Member Author

I have to say, I'm not sure that this is the right approach (but maybe I'm overlooking something).

Is there a reason why we have a special cast mechanism in place, when we could just have the UnrealizedConversionCast interpreter implementation? What do we gain from adding this complexity?

In the Toy pipeline, it's the fake accelerator for pointwise addition and multiplication that uses this mechanism, not the builtin dialects.

This is kind of a composition vs inheritance thing, if I have a toy vector extension with some casts, and maybe some IO thing with some casts, how do they both override the implementation of casting in the builtin interpreter functions that lets them both work without knowing about each other?

@math-fehr
Copy link
Collaborator

Hmm, okay fair I think, works for me!

@superlopuh superlopuh merged commit e781c09 into main Jul 15, 2023
10 checks passed
@superlopuh superlopuh deleted the sasha/wm/cast-interpreter branch July 15, 2023 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter xDSL Interpreter
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants