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.
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
Add CUDF_UNREACHABLE macro. #9727
Add CUDF_UNREACHABLE macro. #9727
Changes from 6 commits
937a512
106b708
f9894d1
8f41a74
ab1cdb9
77c97ae
2c39210
2d61ea9
a0d9baa
8c7d978
52ad3a0
7de2aa0
3bcfd60
c320c1f
6d8d498
8c2b1dc
1407315
b66c4c4
3d3000c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Would it be useful to make this into a single macro (maybe this should be
CUDF_UNREACHABLE
, so it covers both host and device code)? I see the pattern in a few places in the PR.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 considered that, but I didn't want to hide the dependence on
#ifndef __CUDA_ARCH__
. Failure/raising an error and unreachable code mean very different things in my opinion, and I didn't want to conflate them by replacing this with an idiom that has potential for misuse. What do you think?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'm not sure. It's weird because we do have the uneven handling between host and device as it is. Maybe it should be the other way around, and
CUDF_FAIL
can callCUDF_UNREACHABLE
if in device code. As in - "we failed on the device, here's an assert if debug and don't expect a return".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.
Tagging @jrhemstad for thoughts on this. I would defer that change to a later PR if possible.
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 think I'm still in favor of keeping these macros separate. Letting
CUDF_FAIL
defer to an unreachable path seems dangerous. Developers that seeCUDF_FAIL
should be able to reasonably expect an error, and should not use it to signify branches that can be optimized out as impossible to reach. A macro named something likeCUDF_IMPOSSIBLE
might be a compromise, but I think a combined macro like that would obscure the intention (in harmful ways) more than it helps with cleanliness/brevity.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.
Yeah, obscuring the intention is the main issue I can see.
Here's what bugs me: we are using
CUDF_UNREACHABLE
both for truly unreachable code and failure. Ideally,CUDF_UNREACHABLE
macro would call GCC's__builtin_unreachable()
if in host code. But we callCUDF_FAIL
instead in such cases.Feels like code that should not be executed should use
CUDF_FAIL
(both host and device) and truly unreachable code should useCUDF_UNREACHABLE
(both host and device). I understand that this may do more hard than good, just bringing it up for consideration.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 believe all the cases handled in this way are actually unreachable (by enum exhaustion, in most cases). We’re just taking the opportunity to raise an error on the host because we can do that without any significant performance or compile time penalty.