Merged
Conversation
It has two versions, one with an upper bound, and one with a lower and upper bound. This commit removes the first one and changes the second one to take a range, because that is more concise and flexible and clearer. Also, rename it as `in_range`, which makes sense given that the bounds are specified via a Rust `Range`. Note: some of the ranges are incorrect, and will be fixed in the next commit.
Every single one has an upper bound that is one higher than it should be. - For `thread_idx_[xyz]`: indices are 0-indexed, so the maximum index is the `block_dim_[xyz]` maximum minus one. Changing `..=` to `..` fixes it. - For `block_idx_[xyz]`: likewise, but relative to `grid_dim_[xyz]`. - For `block_dim_[xyz]`: these were all one too big. Not sure why, perhaps a `..`/`..=` mix-up? - For `grid_dim_[xyz]`: likewise. (Yes, these grid maximum dimensions are all of the form 2^N-1 even though the block maximum dimensions are all of the form 2^N. I don't know why, but it's what the CUDA docs say.)
Instead call the Rust functions that have the range constraints. That way the 3d version get the same range constraints as the 1d versions. It also avoids the need for some `unsafe` blocks.
`core` has equivalents, might as well use them instead.
450af34 to
bc1ad2c
Compare
LegNeato
approved these changes
Nov 12, 2025
Contributor
LegNeato
left a comment
There was a problem hiding this comment.
Looks good, thanks for cleaning this up.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
@FractalFir identified that rust-cuda implements some intrinsics that are present in
core. I also fixed some nearby rough edges.