-
Notifications
You must be signed in to change notification settings - Fork 68
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
Underspecified behavior of accessor::get_pointer and accessor::get_multi_ptr #580
Comments
I would like DPC++ to diagnose this as a compile-time error. Therefore, I don't want the spec to mandate an exception because that would prevent me from treating the code as ill-formed. |
Ah, okay. Would it make sense to consider introducing some new wording that gives implementations that level of flexibility, but not as much flexibility as undefined behavior? Something that basically means "an implementation must diagnose this as an error, either at compile-time or run-time"? I think that would still be testable in the CTS, because a conforming implementation would have to either fail to compile the test or terminate (somehow) at run-time. |
Do you mean something like the new Erroneous Behavior (well defined but a bug) category in C++26? I would support that direction. |
Something like it, yeah. I wasn't sure if we could re-use "erroneous behavior" directly, because I only really know about it in the context of uninitialized variables. But the idea would be basically the same, if I understand it correctly:
It would probably be safest to pick a new name, and only adopt "erroneous behavior" if we're fully aligned with the final C++26 wording. |
I don't fully understand the concept of "erroneous behavior". If we specified that calling |
That's my reading of the paper, at least:
But it's important to note that an implementation isn't required to diagnose erroneous behavior at compile-time. Thinking about things a bit more over the weekend, I realized that we probably can't throw an error every time we see void foo(auto accessor) {
auto ptr = accessor.get_pointer();
} I don't think that we can prove conclusively whether or not To be fully clear, I think the options open to implementations would be something like the following:
The paper mentions that it would be legal to add a flag (similar to |
It's probably impossible to detect whether you are on the host or inside device code e.g. in a library-only host implementation. Anything that relies on such a branching (including returning e.g. nullptr) might not work in such a case. So I vote in favor of UB. Other implementation types can of course add whatever diagnostic they like. |
Can you say a bit more about the sort of library-only implementation that you're concerned about? It seems to me like even a single-threaded library-only host implementation could distinguish between host code and device code (e.g., by introducing some global state). A SYCL implementation only transitions from executing host code to executing device code at certain points (which are under the implementation's control), so what is stopping an implementation from tracking that? |
That's fair - I was thinking in terms of determining statically whether we are inside host/device code. Everything else, like runtime queries with a global object, will be prohibitively costly for performance for something like |
Oh, I definitely agree that this could have significant cost. But "erroneous behavior" allows implementations to provide flags that disable the checks. So, an implementation where the checks would be prohibitively expensive could have them turned on by default (for safety/compliance reasons) but recommend that users run with some standard options to improve performance. For a library-only implementation that would probably be a macro, whereas for a compiler-based implementation it could be a real flag. |
The specification says:
...but it doesn't say what should happen if either function is called from outside of a command. An implementation is free to return any pointer (including a NULL pointer) which may result in bugs that are difficult to track down or understand. I've seen code like the below hang or segfault across different devices:
Is there a reason that we cannot define
get_multi_ptr()
to throw an error when called on the host?If this is intended to be undefined behavior, I think the specification should state that explicitly. But an error would be more useful to developers.
The text was updated successfully, but these errors were encountered: