-
Notifications
You must be signed in to change notification settings - Fork 745
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
[SYCL] Support or diagnose use of namespace std types as kernel type names #1963
Conversation
…names When std::nullptr_t is used as a kernel type, the generated integration header uses 'nullptr_t'. This causes lookup errors. Use 'std::nullptr_t' instead. std::max_align_t is defined (in one implementation) as a typedef of an anonymous struct. This causes errors when attempting to forward declare the type in the integration header. Diagnose such cases earlier. Signed-off-by: Premanand M Rao <premanand.m.rao@intel.com>
# Conflicts: # clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10835,6 +10835,7 @@ def err_sycl_kernel_incorrectly_named : Error< | |||
"kernel %select{name is missing" | |||
"|needs to have a globally-visible name" | |||
"|name is invalid. Unscoped enum requires fixed underlying type" | |||
"|name cannot be or use std::nullptr_t" |
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.
Just wondering, why we disallow only nullptr_t?
Your PR message says " sounds like we don't want to encourage using builtin types as kernel names. "
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.
nullptr_t is special because builtin type names are (typically) accessible without a header, but nullptr_t is a builtin type that isn't known by any name until we include a header (or forward declare). The "don't want to encourage using builtins" comes from rolandschulz's comment -- "Adding extra support for std types is not needed," and, "there is no promise that std types work as lambda name." But I may have misinterpreted his comments, and others asking him for clarification.
clang/lib/Sema/SemaSYCL.cpp
Outdated
Diag.Report(KernelLocation, diag::err_sycl_kernel_incorrectly_named) | ||
<< /* kernel name is missing */ 0; |
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 spend some time looking into these changes, and I don't get why we didn't start emitting "kernel name is missing" on each unnamed lambda, because before your changes this diagnostic was under if (!UnnamedLambdaSupport)
and it looked correct.
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.
The original "if" was if (TD && !UnnamedLambdaSupport)
, and when this evaluates false, then the else block would still use TD
anyway -- which seems weird. premanandrao's commit refactored the TD check out to if (!TD) break;
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 still a bit confused about this change. Can you give an example where if (TD)
evaluates true and KernelNameIsMissing i.e. TD does not have a name?
Also, this change is not technically required for 'std' namespace check right? Or am I missing something?
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 this happens when it is invalid.
It is not needed strictly for the specific 'std' namespace check, but it occurs in those contexts too.
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.
Normally the if (TD)
check would ensure that a kernel name type is a TagDecl -- that is, one of a struct/union/class/enum -- which would catch kernel name types such as int
. I say "normally", though, because earlier in the call stack, we also ensure that a kernel name type is a CXXRecordDecl -- that is, one of a struct/union/class. Which means, sadly, that the if (TD)
part may actually be dead code. But, it was dead code even before, and independent of, this PR. I had considered doing a clean-up of the existing code, but... I feel like this PR has already exceed its side-quest quota. :-)
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.
Yes this is part of what's being checked in, but the original had dead code too, and this part just moves the dead code a couple lines over.
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 see. In that case, I don't mind this being addressed in a separate 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.
OK then sounds like we're opting to not revert the April refactoring? And this PR would stay as is?
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.
Seems like folks still aren't comfortable with those changes, and since they come from an older time in this PR and don't seem to be needed anymore, I pushed a commit to revert that bit of refactoring. Buildbot is running. I'll ping folks when ready for re-review approvals.
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.
The changes @elizabethandrews was concerned about are reverted. All checks passed. Need review approvals again. @premanandrao @rbegam
I disagree with this approach. While Roland's comment is 'Because there is no promise that std types work as lambda name', that only applies as the top level item. a kernel named
SHOULD be illegal, if we're going to implement Roland's comment, we should cover EVERY type in std. However,
the std type is NOT the kernel name, an instance of SomeTemplate is. We should have to support this case. I believe we'd discussed before that we should just serialize std::nullptr_t as decltype(nullptr) to make this work. |
Agreed with the second part - only top-level should be disallowed. |
I read it as 'all'... @rolandschulz can you clarify? |
While we wait for clarification, just adding a couple notes:
|
Yes I meant all std types. Only types which can be forward declared have to be supported and it isn't valid to forward declare std types. |
This point here is particularly annoying... @rolandschulz : what clarification to the SYCL spec needs to me made to allow us to prevent ANY use of namespace-std in kernel names? Or do you and @mkinsner / @jbrodman /etc already feel that is the case? |
For the implementation we should just assume that it's OK that nothing in std is allowed. This is clearly the intention. If someone thinks this needs to be clarified in the spec even for 1.2.1 not just upcoming SYCL we can do that. |
One of the relevant use cases seems to be a kernel inside a function template, because the function template parameters get reused in the kernel name to keep each name type unique. We do this ourselves in the SYCL handler "fill" function template. The value type to fill is a parameter that gets reused in the kernel name. If we call fill with a |
Latest commit disallows names from std namespace. |
# Conflicts: # sycl/test/sub_group/reduce.cpp # sycl/test/sub_group/scan.cpp
@jtmott-intel, please, resolve CI failures. |
All checks have passed. Here's a quick re-summary. Originally we were going to emit an error diagnostic for kernel names with Later we decided to disallow all After implementing this change, several tests broke because they were (indirectly) using
I updated the impacted tests and made the kernel name its own distinct template parameter so we wouldn't need to re-purpose the other parameters anymore.
This does, however, put more responsibility on the user to pass unique kernel names. If they don't, then existing diagnostics will already tell them. |
I see, thanks for the update! So we COULD still enable unnamed lambdas in SYCL 2020 mode. That said, we should still have the prohibition on std types in 1.2.1 mode. I believe the enabling unnamed lambdas in 2020 mode is orthogonal to this patch, so I'd think we want to do that as a separate patch. |
# Conflicts: # clang/test/SemaSYCL/unnamed-kernel.cpp # sycl/test/group-algorithm/exclusive_scan.cpp # sycl/test/group-algorithm/inclusive_scan.cpp # sycl/test/group-algorithm/reduce.cpp # sycl/test/reduction/reduction_ctor.cpp # sycl/test/reduction/reduction_nd_conditional.cpp # sycl/test/reduction/reduction_nd_ext_type.hpp # sycl/test/reduction/reduction_nd_s0_dw.cpp # sycl/test/reduction/reduction_nd_s0_rw.cpp # sycl/test/reduction/reduction_nd_s1_dw.cpp # sycl/test/reduction/reduction_nd_s1_rw.cpp # sycl/test/reduction/reduction_placeholder.cpp # sycl/test/reduction/reduction_transparent.cpp # sycl/test/reduction/reduction_usm.cpp # sycl/test/sub_group/generic-shuffle.cpp # sycl/test/sub_group/reduce.hpp # sycl/test/sub_group/scan.hpp
Hi, @bader . Any chance this PR is having a problem with the Windows buildbots? There's no significant code changes since the last "all checks passed". The specific tests that fail can be different on each run -- sometimes it's |
The test is flaky, we disabled it on windows. Could you please merge your branch with the latest sycl branch? |
@romanovvlad After the latest merge from sycl, I'm getting a Windows-only error for |
I have not seen this fails before. @vladimirlaz @tfzhu have you seen this issue in other PRs? |
@romanovvlad This PR does touch the two failing tests, but I also got an "all checks passed" earlier, and since then I've only merged from sycl branch. I've looked over the changes to those files character by character, and everything still looks just as right as when all checks passed. None of the changes are OS-specific. And I've tried to reproduce the failure locally but can't reproduce. |
I've checked several other failing pre-commits on windows and I do not see these test failing. |
All checks passed! Sorry, folks. Yes this latest problem was my fault. I made a mistake in a merge resolution and used the same kernel name twice. I didn't feel good about using a PR to troubleshoot the issue, but I couldn't reproduce it any other way, so I finally used a separate dummy PR to narrow down where the problem was coming from, and -- I'm happy to say it's fixed now. Final approval and merge may commence. I assume folks will prefer a squash merge for this one? :-) |
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.
@jtmott-intel, I don't see any major changes since I last reviewed this. The set of changes look good to me.
@elizabethandrews, @Fznamznon, okay with you?
I see @premanandrao 's approval, but github now appears to be blocking because it's waiting on an approval from someone in the intel/llvm-reviewers-runtime team. @romanovvlad @rbegam ? |
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.
LGTM
…el type names" This reverts commit 46c54c6. # Conflicts: # clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp # clang/test/SemaSYCL/unnamed-kernel.cpp
8d0087e
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.
LGTM. Thanks!
Can you file a GitHub issue to look into the dead code so we don't forget about it?
The base branch restricts merging to authorized users -- and apparently I'm not an authorized user. :-) Maybe @premanandrao or @elizabethandrews can one of you click the merge button for me? |
We're not authorized to either :) I see @bader already merged your commit but FYI, @bader and @pvchupin have merge rights. |
This is a continuation of #1579. Sorry I couldn't commit to the branch named in that PR.
This PR has premanandrao's original commit plus one of mine to address the comments in 1579 -- specifically this conversation.
I removed the changes to the generated header and added a diagnostic to make nullptr_t in kernel names an error. It's possible to make nullptr_t work like int works, but sounds like we don't want to encourage using builtin types as kernel names. The diagnostic message is open to wordsmithing.