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: (builtin) add CompileTimeFixedBitwidthType #3599

Merged
merged 7 commits into from
Dec 10, 2024

Conversation

jorendumoulin
Copy link
Collaborator

@jorendumoulin jorendumoulin commented Dec 9, 2024

This PR adds the CompileTimeFixedBitwidthType to represent values that have a fixed bitwidth and are thus packable, but the bitwidth may not be known until compile time.

The new dependency graph now looks like the following: https://is.gd/q5N7Dx

@jorendumoulin jorendumoulin requested review from superlopuh, math-fehr and alexarice and removed request for superlopuh December 9, 2024 09:02
Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.41%. Comparing base (4bbeecb) to head (5df2d50).
Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3599      +/-   ##
==========================================
+ Coverage   90.38%   90.41%   +0.02%     
==========================================
  Files         469      471       +2     
  Lines       59075    59151      +76     
  Branches     5615     5611       -4     
==========================================
+ Hits        53397    53482      +85     
+ Misses       4232     4225       -7     
+ Partials     1446     1444       -2     

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

@jorendumoulin jorendumoulin self-assigned this Dec 9, 2024
@jorendumoulin jorendumoulin added the dialects Changes on the dialects label Dec 9, 2024
@superlopuh
Copy link
Member

IndexType is not FixedBitwidth, since its bitwidth is target-dependent

@superlopuh
Copy link
Member

We need an adjustment to the hierarchy, where we need to distinguish between packability, and bitwidth fixed at compile-time vs runtime

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.

Probably worth checking with @math-fehr on this also, but my understanding is that we're missing a type that says that the bitwidth is fixed during compilation time but it may differ from the bitwidth at runtime until lowered to target-dependent code.

@jorendumoulin
Copy link
Collaborator Author

IndexType is not FixedBitwidth, since its bitwidth is target-dependent

I had considered it to be because even if it is target-dependent, it will always have a fixed bitwidth. The fact that we don't know the actual bitwidth seems like a separate problem. I'm not too sure about this though.

Just a bit confused as how to proceed because I want to pack indextype variables, and in #3581 we decided to combine the fixedbitwidth and structpackable type.

I think @math-fehr mentioned somewhere that even though indextype is not known, it is assured to be <= int64 and thus always packable as a double

@jorendumoulin
Copy link
Collaborator Author

I propose going from left to right here: ...

Looks good to me, but what is the practical use of the _CompileTimeFixedBitwidthType class? The world seems a bit simpler by just separating Packable and FixedBitwidth, as I personally tend to steer away from boilerplate code without a clear usage. I am fine either way though.

@superlopuh
Copy link
Member

Because we need to distinguish between things that can go in DenseArrayBase and DenseIntOrFPElementsAttr, and in general for bitwidth computation of things that reside in memory on the target

@jorendumoulin jorendumoulin changed the title dialects: (builtin) IndexType is StructPackable dialects: (builtin) add CompileTimeFixedBitwidthType Dec 9, 2024
@jorendumoulin
Copy link
Collaborator Author

I updated things to your suggestions, let me know what you think!

Comment on lines 352 to 360
class CompileTimeFixedBitwidthType(TypeAttribute, ABC):
"""
A type attribute whose runtime bitwidth is fixed, but may be target-dependent.
"""

name = "abstract.compile_time_fixed_bitwidth_type"


class FixedBitwidthType(CompileTimeFixedBitwidthType, ABC):
Copy link
Member

Choose a reason for hiding this comment

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

How do you feel about putting an abstract property here?

Maybe actually not packed-dependent name, like compile_time_size?

Suggested change
class CompileTimeFixedBitwidthType(TypeAttribute, ABC):
"""
A type attribute whose runtime bitwidth is fixed, but may be target-dependent.
"""
name = "abstract.compile_time_fixed_bitwidth_type"
class FixedBitwidthType(CompileTimeFixedBitwidthType, ABC):
class CompileTimeFixedBitwidthType(TypeAttribute, ABC):
"""
A type attribute whose runtime bitwidth is fixed, but may be target-dependent.
"""
name = "abstract.compile_time_fixed_bitwidth_type"
@property
@abstractmethod
def packed_size(self) -> int:
"""
Contiguous memory footprint of packed value in bytes.
"""
raise NotImplementedError()
class FixedBitwidthType(CompileTimeFixedBitwidthType, ABC):

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, this makes sense!

@math-fehr
Copy link
Collaborator

Yeah, you should always be able to pack an index into an i64, but you don't know its size at compile-time (only when you do target-dependent lowerings)

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!

@jorendumoulin jorendumoulin merged commit ec1f978 into main Dec 10, 2024
15 checks passed
@jorendumoulin jorendumoulin deleted the joren/packable-index branch December 10, 2024 11:53
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.

4 participants