Skip to content

[SYCL][libdevice] improve complex trig and pi ulp - #23375

Open
cperkinsintel wants to merge 3 commits into
intel:syclfrom
cperkinsintel:cperkins-complex-ulp-fix
Open

cperkinsintel wants to merge 3 commits into
intel:syclfrom
cperkinsintel:cperkins-complex-ulp-fix

Conversation

@cperkinsintel

Copy link
Copy Markdown
Contributor

Some of the inverse trig functions (acos, asin, acosh asinh) over complex numbers in SYCL have two problems:

  • the PI constant is calculated by a rounding transcendental, and drops 1 ULP before ever being used
  • when there is a large negative real part, the intermediate sum z + sqrt(z^2 -+ 1) cancels catastrophically, its true
    value is smaler than the rounding error of its two terms.

Signed-off-by: Chris Perkins <chris.perkins@intel.com>
@cperkinsintel
cperkinsintel requested a balanced review from Copilot October 5, 2026 19:24

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.

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 6 Medium severity

Open (7)
What changed in this PR

This PR improves correctness of complex inverse trig/hyperbolic functions for large-magnitude inputs on device by avoiding catastrophic cancellation and using a more reliable value of π, and adds/extends end-to-end coverage for the affected cases.

Changes:

  • Add a new DeviceLib E2E test to compare std::acos/asin/acosh/asinh on device vs host for large arguments.
  • Update complex math implementations (acos/acosh/asinh and π constant selection) to avoid cancellation for negative real parts and fix π rounding issues.
  • Extend existing complex math test cases with additional “large argument” inputs for inverse functions.
File Description
sycl/​test-e2e/​DeviceLib/​std_complex_inverse_trig_large_args.cpp Adds a new E2E test exercising large-argument inverse complex functions on device.
sycl/​test-e2e/​Complex/​sycl_complex_math_test_cases.hpp Refactors default test values and appends large-argument cases for inverse functions.
sycl/​include/​sycl/​ext/​oneapi/​experimental/​complex/​detail/​complex_math.hpp Switches π computation to a constant and updates inverse functions to avoid cancellation on negative real inputs.
libdevice/​fallback-complex.hpp Mirrors cancellation-avoidance logic and π constant usage for float complex fallbacks.
libdevice/​fallback-complex-fp64.hpp Mirrors cancellation-avoidance logic and π constant usage for double complex fallbacks.
libdevice/​device_complex.h Introduces a shared π definition used by libdevice complex implementations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sycl/test-e2e/DeviceLib/std_complex_inverse_trig_large_args.cpp Outdated
Comment thread libdevice/device_complex.h
Comment thread sycl/include/sycl/ext/oneapi/experimental/complex/detail/complex_math.hpp Outdated
Comment thread sycl/test-e2e/Complex/sycl_complex_math_test_cases.hpp
Comment thread sycl/test-e2e/Complex/sycl_complex_math_test_cases.hpp
Comment thread sycl/test-e2e/Complex/sycl_complex_math_test_cases.hpp
Comment thread sycl/test-e2e/Complex/sycl_complex_math_test_cases.hpp
Signed-off-by: Chris Perkins <chris.perkins@intel.com>
Signed-off-by: Chris Perkins <chris.perkins@intel.com>
@cperkinsintel
cperkinsintel marked this pull request as ready for review October 6, 2026 19:24
@cperkinsintel
cperkinsintel requested a review from a team as a code owner October 6, 2026 19:24
@cperkinsintel

Copy link
Copy Markdown
Contributor Author

The failure in llvm/sycl/test-e2e/USM/memops2d/memcpy2d_device_to_host.cpp (or device_to_device.cpp) on Arc is being seen by other PR as well.
#23385

This branch has not been deployed

No deployments
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.

2 participants