Skip to content

[SYCL][NVPTX][AMDGPU] Use __builtin_nearbyint in cmath wrapper - #21971

Merged
uditagarwal97 merged 2 commits into
intel:syclfrom
Maetveis:cmath-use-builtin-nearbyint
May 11, 2026
Merged

[SYCL][NVPTX][AMDGPU] Use __builtin_nearbyint in cmath wrapper#21971
uditagarwal97 merged 2 commits into
intel:syclfrom
Maetveis:cmath-use-builtin-nearbyint

Conversation

@Maetveis

@Maetveis Maetveis commented May 8, 2026

Copy link
Copy Markdown
Contributor

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 #21652.

Fixes #21652.

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.
@Maetveis
Maetveis requested a review from a team as a code owner May 8, 2026 14:35
@Maetveis
Maetveis requested review from bader and cperkinsintel May 8, 2026 14:35
Comment thread sycl/test/regression/include_cmath_no_rdc.cpp Outdated

@bader bader left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Maetveis

Copy link
Copy Markdown
Contributor Author

@intel/llvm-reviewers-runtime please review :)

@uditagarwal97
uditagarwal97 requested a review from Copilot May 11, 2026 07:41
@Maetveis

Copy link
Copy Markdown
Contributor Author

@intel/llvm-gatekeepers please merge :)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.hpp to 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.

Comment thread sycl/test/regression/include_cmath_no_rdc.cpp
@uditagarwal97
uditagarwal97 merged commit 9ad5e4b into intel:sycl May 11, 2026
40 of 41 checks passed
@Maetveis
Maetveis deleted the cmath-use-builtin-nearbyint branch May 12, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compilation with -fno-sycl-rdc is broken due to __sycl_cmath_wrapper_impl.hpp (missing definition of SYCL_EXTERNAL)

5 participants