-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][CUDA] Change builtin selection for SYCL #9768
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][CUDA] Change builtin selection for SYCL #9768
Conversation
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.
Please add a test
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 for driver
Test added |
clang/lib/CodeGen/CGBuiltin.cpp
Outdated
if ((FD->hasAttr<ConstAttr>() || | ||
((ConstWithoutErrnoAndExceptions || ConstWithoutExceptions) && | ||
(!ConstWithoutErrnoAndExceptions || (!getLangOpts().MathErrno)))) && | ||
!(getLangOpts().isSYCL() && getTarget().getTriple().isNVPTX())) { |
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.
All FE changes should have an accompanying FE test. It makes it easier to track down issues in the future if one arises. Can you add a FE test for this change. It can just check these builtins are not present in IR with these options and present without.
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.
Sure. Test added. Let me know if you think this is sufficient. Note that SPIR-V compilation does use llvm intrinsics (not libdevice) for cmath funcs when in -ffast-math
mode (since errno
not used). This isn't exactly a problem for SPIR-V since llvm.cos.f32
has a SPIR-V lowering for fast mode, namely approx_cos
. It happens to work but I think the idea of using libdevice is for DPC++ to provide its own definitions for cmath and other CXX stdlib funcs. Let me know if you think SPIR-V compilation should also use libdevice func definitions while in fast math mode as well, instead of relying on openCL driver implementations for say approx_cos
.
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.
Let me know if you think SPIR-V compilation should also use libdevice func definitions while in fast math mode as well, instead of relying on openCL driver implementations for say approx_cos.
I'm not familiar enough with this to have a non-naive response one way or the other. Maybe @bader or @steffenlarsen has an input?
Hi, sorry, missed the ping. There is no direct counterpart for the intrinsic in core SPIR-V. We can add translation of it to OpenCL's So the first question would be: do you expect your patch to change compilation for ESIMD? If no - there is plenty of time for us to help you, since intrinsic to OpenCL builtin translation should be trivial (please create an internal feature request for that). If yes - probably we won't be able to help you for this release, from what I see now - it's quite hard to emulate such intrinsic replacing it with a sequence of SPIR-V instructions, so in this case it better to get rid of it before the translator. |
This patch is not changing compilation for SPIR-V targets at all, but the test I have added is highlighting a problem in LLVM-SPIR-V. If I were to fix this for SPIR-V compilation it would merely avoid using LLVM intrinsics at all in SYCL, which is the default behaviour unless If we correctly map this intrinsic to an openCL builtin in LLVM-SPIR-V, then my understanding is that this would not work for say a L0 driver which as you say doesn't handle openCL SPIR-V. So we are shifting the problem elsewhere. @steffenlarsen the long term problem is that libdevice doesn't do anything for |
Thank you for the clarification, @hdelan ! As long as it is not a regression, I am okay with disabling the test for targets we know don't support it, which I think in this case would be all SPIR-V targets, so maybe we should |
Failures are unrelated. Ping @intel/llvm-gatekeepers this can be merged |
@hdelan , due to the failures that were happening (no gen12 linux tests run at all), we are not able to accept these test results as known issues. I have rekicked off your test run now that issue is fixed. If all comes back clean, gatekeepers will proceed with merge. |
|
@dm-vodopyanov that should hopefully fix it. Let's wait and see |
@dm-vodopyanov failures are unrelated. |
Failed tests on HIP:
Logs:
|
Since #9768 `ffast-math` no longer chooses llvm intrinsics. This highlighted that `std::round` was missing in libdevice. This fixes that.
Libdevice for NVPTX was previously working due to the fact that LLVM intrinsics were not selected due to the CUDA toolchain having isMathErrnoDefault evaluate to
true
. Since LLVM intrinsics were not selected then the symbols could be found when linking with libdevice, which gives special backend specific definitions of CXX stdlib funcs.Using errno to prevent intrinsic selection was a hack and it gets undone by using
-ffast-math
, meaning libdevice CXX funcs were not working with-ffast-math
.This change instead explicitly says not to use LLVM intrinsics if compiling SYCL for NVPTX backend. This means that
-ffast-math
behaviour should now be fixed for CXX stdlib funcs.@jchlanda