-
Notifications
You must be signed in to change notification settings - Fork 744
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] Unique stable name rebase #3835
Conversation
The original version of this was reverted, and @rjmcall provided some advice to architect a new solution. This is that solution. This implements a builtin to provide a unique name that is stable across compilations of this TU for the purposes of implementing the library component of the unnamed kernel feature of SYCL. It does this by running the Itanium mangler with a few modifications. Because it is somewhat common to wrap non-kernel-related lambdas in macros that aren't present on the device (such as for logging), this uniquely generates an ID for all lambdas involved in the naming of a kernel. It uses the lambda-mangling number to do this, except replaces this with its own number (starting at 10000 for readabililty reasons) for lambdas used to name a kernel. Additionally, this implements itself as constexpr with a slight catch: if a name would be invalidated by the use of this lambda in a later kernel invocation, it is diagnosed as an error (see the Sema tests). Differential Revision: https://reviews.llvm.org/D103112
Note that I noticed a bunch of check-all failures locally that i'm going to work through as well. There shouldn't be much to review here, as the community reviewed the big patch, and this mostly just removes the old one and adds that. There are a few library changes that are just changing the name. |
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.
RT changes LGTM
I discovered when merging the __builtin_sycl_unique_stable_name into my downstream that it is actually possible for the cc1 invocation to have more than 1 Sema instance, if you pass it multiple input files, each gets its own Sema instance and thus ASTContext instance. The result was that the call to Filter the SYCL kernels was using an ItaniumMangleContext stored via a 'magic static', so it had an invalid reference to ASTContext when processing the 2nd failure. The failure is unfortunately flakey/transient, but the test that fails was added anyway. The magic-static was switched to a unique_ptr member variable in ASTContext that is initialized when needed.
@AlexeySachkov : Can you look into the level-zero issue that showed up on the build-bots? I look at it when it came up on the linux bot, but don't have a good idea on how to start debugging it. |
@erichkeane, the failure is not directly related to level-zero, but it is related to "unnamed lambda" functionality. In Jenkins/Precommit there are ~18 failures and all of them because kernel wasn't found in device images. I've used minimalistic (could be reduced more, of course) example to reproduce:
From integration header:
During instantiation (I've commented
|
Interesting.... The 'host' side is obviously wrong there, since it is a lambda without the unnamed-lambda spelling. Could this be a missed "sycl_kernel" attribute? One of the gotchas with the new mechanism is that the sycl_kernel attribute needs to be present on both sides. |
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
1 more patch :) @romanovvlad please take a look at the warnings.cpp test from here: 45d489e to figure out if you want to make other different changes to your RT commits here. Thanks! |
Will try to do tomorrow. |
In the case where the device is an itanium target, and the host is a windows target, we were getting the names wrong, since in the itanium case we filter by lambda-signature. The fix is to always filter by the signature rather than just on non-windows builds. I considered doing the reverse (that is, checking the aux-triple), but doing so would result in duplicate lambda mangling numbers (from linux reusing the same number for different signatures).
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!
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.
Other than the questions, RT changes LGTM
@@ -825,9 +825,8 @@ class __SYCL_EXPORT handler { | |||
|
|||
range<Dims> AdjustedRange = NumWorkItems; | |||
AdjustedRange.set_range_dim0(NewValX); | |||
#ifdef __SYCL_DEVICE_ONLY__ | |||
kernel_parallel_for_wrapper<NameWT, TransformedArgType>(Wrapper); |
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.
This is performed in both host and device, isn't it?
Why is that needed?
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.
@romanovvlad made these changes, but the root of it is that we're required to have the kernel instantiated on both sides now, since otherwise we cant tell whether a lambda is used to name a kernel on the host-side.
(void)NumWorkItems; | ||
kernel_parallel_for_wrapper<NameT, TransformedArgType>(KernelFunc); |
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.
Same question here and in similar places
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
@erichkeane, this patch breaks "clang-12 + shared libraries" post-commit configuration - https://github.com/intel/llvm/runs/2738419633?check_suite_focus=true. |
It appears the problem is in the library changes that @romanovvlad committed. The 'simple' fix is to just push a commit that casts the parameters in each of these functions to 'void'. I can prepare a patch to do that @bader, though I'm not sure how to submit it? |
Could you open a pull request with the patch you proposed, please? If possible, please, check locally that "self-build + shared lib" configuration passes compilation + lit tests. Unfortunately, this configuration is covered by post-commit only, so pre-commit doesn't validate that it's fixed. |
Submitted a PR here: #3874 I don't have a self-build + shared-lib config available on my test environment, but the errors/changes seem quite simple. |
Interesting... I also see that |
I have seen that failure in my local repo for a few months now, I don't think it is related to this at all. |
So my mistake, that one no longer fails for me (but did for quite a while). Even so, I don't see anything in this patch or the #3874 having the ability to change the behavior of that test at all. FWIW, my environment's failures are now: |
* sycl: (320 commits) [SYCL] Silence a "local variable is initialized but not referenced" warning; NFC (intel#3870) [SYCL] Improve SYCL_DEVICE_ALLOWLIST (intel#3826) [SPIR-V] Change return value of mapType function (intel#3871) [SYCL] Fix post-commit failure in handler.hpp from unused-parameters. (intel#3874) [Driver][SYCL] Do not imply defaultlib msvcrt for Linux based driver on Windows (intel#3827) [SYCL] Unique stable name rebase (intel#3835) [SYCL] Align behavior of empty command groups with SYCL2020 (intel#3822) [SYCL][ESIMD] Make typenames and constants consistent with SYCL API style. (intel#3850) [SYCL] Allow __failed_assertion to support libstdc++-11 (intel#3774) [SYCL] Refactor stream class handing implementation (intel#3646) [SYCL] Fix syntax error introduced in intel#3401 (intel#3861) [SYCL] SYCL 2020 sub_group algorithms (intel#3786) [Buildbot][NFC] Add option to use LLD as linker (intel#3866) Revert "Emit correct location lists with basic block sections." [SPIRITTAnnotations] Fix debug info for ITT calls. (intel#3829) [SYCL][Doc] Fix build of Sphinx docs (intel#3863) [SYCL][FPGA][NFC] Tidy up intel_fpga_reg codegen test (intel#3810) [CODEOWNERS] Fix SPIRITTAnnnotations tests ownership (intel#3859) [SYCL][ESIMD] Host-compile simd.cpp test, fix errors & warnings. (intel#3846) [SYCL] Store pointers to memory allocations instead of iterators (intel#3860) ...
Resolved by reverting: eba69b5 Reimplement __builtin_unique_stable_name- And applying: 70281ea [SYCL] Unique stable name rebase (intel#3835) CONFLICT (content): Merge conflict in clang/lib/Sema/SemaTemplateInstantiateDecl.cpp CONFLICT (content): Merge conflict in clang/lib/Sema/SemaSYCL.cpp CONFLICT (content): Merge conflict in clang/lib/Sema/SemaExpr.cpp CONFLICT (content): Merge conflict in clang/lib/Parse/ParseExpr.cpp CONFLICT (content): Merge conflict in clang/lib/Basic/IdentifierTable.cpp CONFLICT (content): Merge conflict in clang/lib/AST/ItaniumMangle.cpp CONFLICT (content): Merge conflict in clang/include/clang/Sema/Sema.h CONFLICT (content): Merge conflict in clang/include/clang/Parse/Parser.h CONFLICT (content): Merge conflict in clang/include/clang/Basic/TokenKinds.def CONFLICT (content): Merge conflict in clang/include/clang/AST/Mangle.h CONFLICT (content): Merge conflict in clang/docs/LanguageExtensions.rst
This reverts our existing implementation, updates the library uses of this, and adds the community patch back:
8347ee4