Skip to content

mir: lower f32::atan{,2} / f64::atan{,2} via libdevice (rebased #78) - #109

Merged
nihalpasham merged 2 commits into
mainfrom
pr-78-atan-rebased
Jun 4, 2026
Merged

nihalpasham merged 2 commits into
mainfrom
pr-78-atan-rebased

Conversation

@nihalpasham

Copy link
Copy Markdown
Collaborator

Rebased + verified version of #78 by @paulzhng, brought onto current main. #78 overlapped #62's RustFloatMathIntrinsic block so it could not merge as-is; the original commit is preserved as-authored (only rebased and conflict-resolved).

What it does

f32::atan / atan2 (and the f64 forms) route through std::sys::cmath shims rather than core intrinsics, so this:

  • skips those four cmath shims in the collector instead of tripping the std-forbidden guard, and
  • maps them to libdevice __nv_atan{,2}{,f} through the existing float-math placeholder pipeline.

Verification

  • Unit tests: mir-importer 11/11, mir-lower 13/13 (both Add f32::max / f32::min support via libdevice fmax/fmin #62's max/min and this PR's atan coexist).
  • GPU (RTX 5090): cargo oxide run math_atan -> SUCCESS: 16 cases x 4 variants within 2 ULP of host libm.
  • Negative: reverting the collector skip makes f32::atan fail with FORBIDDEN CRATE IN DEVICE CODE: std::sys::cmath::atanf, confirming the change is load-bearing.

Closes #77. Supersedes #78 (@paulzhng's original).

Kernels can now write `y.atan2(x)` / `x.atan()` directly.

Signed-off-by: Paul Zhang <[email protected]>
@nihalpasham nihalpasham added intrinsics Device intrinsics and libdevice math mappings enhancement New feature or request labels Jun 4, 2026
The ys_f32 test array used 3.14 / -3.14, which clippy's approx_constant
(deny-by-default) flags as approximations of PI. Swap for 3.25 / -3.25:
same mid-range coverage, exactly f32-representable, not a constant.
@nihalpasham
nihalpasham merged commit c21cd1a into main Jun 4, 2026
20 checks passed
@nihalpasham
nihalpasham deleted the pr-78-atan-rebased branch June 5, 2026 03:09
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for {f32,f64}::atan{,2}

2 participants