-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Add DType.get_dtype()
#3810
Open
martinvuyk
wants to merge
7
commits into
modular:main
Choose a base branch
from
martinvuyk:add-dtype-helpers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
914ce14
Add DType.get_dtype()
martinvuyk fa160cb
fix docstrings
martinvuyk f59d2da
Merge remote-tracking branch 'upstream/nightly' into add-dtype-helpers
martinvuyk 79af15f
add amd float type
martinvuyk eb1e0b8
mojo format
martinvuyk 72213e5
Merge remote-tracking branch 'upstream/nightly' into add-dtype-helpers
martinvuyk c0e44f2
Merge branch 'main' into add-dtype-helpers
martinvuyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know compiler internals, but I figured adding a
@parameter
would be redundant after the first execution (?). Should I add it anyway?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add it anyways as I'm not sure.
Re the implementation itself, is there a way we can leverage the
element_type
alias from SIMD to simplify this? Conceptually, we want to just retrieveT.element_type
for SIMD types and returnDType.invalid
otherwise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To do that we'd somehow need to rebind the
AnyType
to aSIMD
, which I don't think the compiler will allow when the type is notSIMD
. I think we'd need a version of_type_is_eq
that works for unbound parameters like what @rd4com showed on Discord:_type_is_eq[SIMD[_, _]]()
and then we'd need an "unbound rebind" where we'd dodtype = rebind[SIMD[_, _]](value).element_type
, but I think this would need some very heavy involvement on the compiler side.I had another idea that we could also add another method
.get_simd() -> (DType, Int)
that finds the vector characteristics by brute forceThis seems like it would make compile times suffer, but it would actually only need
alias sizes = (1, 2, 4, 8)
which would then work for only one sizesizeof[T]() // size == 1
, and then it just unrolls the comparison for every dtype. It's still expensive if not used properly, but I think we could execute it only once and save the results as aliases inside the struct like:We can leave this for another PR if you'd like. I think the current
.get_dtype()
implementation is good for most scalar use cases or those where one knows the size of theSIMD
vectors. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoeLoser gentle ping. I think we won't be able to implement what you're suggesting without having reflection first. So could we move forward with this PR?