[SYCL][NVPTX][AMDGPU] Use __builtin_nearbyint in cmath wrapper - #21971
Merged
Conversation
Instead of using `__nv_nearbyint` and `__ocml_nearbyint` from device libraries,
use `__builtin_nearbyint` in the cmath wrapper. Both targets have native
support for nearbyint so we don't need to call out to the device library.
Both CUDA and HIP compilation already does this in `__clang_{cuda,hip}_math.h`.
We can then also remove `SYCL_EXTERNAL` use from this header, to fix intel#21652.
Fixes intel#21652.
bader
reviewed
May 8, 2026
Contributor
Author
|
@intel/llvm-reviewers-runtime please review :) |
uditagarwal97
approved these changes
May 11, 2026
slawekptak
approved these changes
May 11, 2026
Contributor
Author
|
@intel/llvm-gatekeepers please merge :) |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the SYCL <cmath> device wrapper for NVPTX/AMDGPU to use __builtin_nearbyint{f} instead of calling out to CUDA/HIP device-library entry points, removing reliance on SYCL_EXTERNAL declarations that break -fno-sycl-rdc builds (Fixes #21652).
Changes:
- Replace NVPTX/AMDGPU
nearbyint{f}implementations in__sycl_cmath_wrapper_impl.hppto use__builtin_nearbyint{f}. - Remove
SYCL_EXTERNAL-based declarations of__nv_nearbyint*/__ocml_nearbyint_*from the wrapper header. - Add a regression test intended to ensure
<cmath>can be included with and without RDC.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp | Switch nearbyint implementations for NVPTX/AMDGPU to Clang builtins to avoid device-library and SYCL_EXTERNAL dependencies. |
| sycl/test/regression/include_cmath_no_rdc.cpp | Adds a compile-only regression test for including <cmath> with -fsycl-rdc and -fno-sycl-rdc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Instead of using
__nv_nearbyintand__ocml_nearbyintfrom device libraries, use__builtin_nearbyintin the cmath wrapper. Both targets have native support for nearbyint so we don't need to call out to the device library. Both CUDA and HIP compilation already does this in__clang_{cuda,hip}_math.h. We can then also removeSYCL_EXTERNALuse from this header, to fix #21652.Fixes #21652.